What they’re really asking
If you only remember one thing, say this in the first minute: “I’ll get a plain pipeline running first: split the documents into chunks, embed them, find the closest chunks to the question, and have the model answer with citations. Then I’ll turn ‘it seems to work’ into a number. I’d write 20 to 30 questions where I know the right documents, and report two different numbers: the hit rate (did any right chunk make the top k?) and recall (what share of the right chunks did?). Both at the k I actually send to the model, with an error bar, and next to keyword-only and vector-only baselines.”
The rest of this page explains each part of that answer.
The interviewer wants to see two things: that you can build a small retrieval pipeline quickly, and that you know how to prove it works.
The second part is the new one for a backend engineer. A normal search feature has a clear contract: a database query returns the rows that match, and a unit test can check it. Here the search works by meaning. It always returns a ranked list of “closest” chunks, and the closest chunk can still be the wrong one. Then a language model writes a fluent answer from whatever was retrieved. So there is no unit test for “the search is good”. You need a small set of questions with known answers and a measurement on it, much like an A/B test.
The build is the warm-up. The evaluation question is where you show you know what to measure, at what k, and how sure you are.
(This was reported by a Harvey candidate who was later rejected. The last question was how to improve the evaluation, “such as recall or hit rate” PracHub.)
Words you need first
- RAG (retrieval-augmented generation): find a few relevant pieces of your documents, paste them into the prompt of a large language model (LLM), and ask it to answer from them. LLMs read text in tokens, pieces of words of roughly ¾ of a word each, and API prices are per token.
- Chunk: one of those pieces, usually a paragraph or short section, with an ID.
- Embedding: a list of numbers (a vector, for example 384 long) that a small model computes from text, so that texts with similar meaning get vectors pointing in similar directions.
- Top-k: the k chunks with the best scores. k is how many you hand to the model, often 5.
Clarify first
Spend a minute on the setup and say your assumptions out loud:
- What corpus, and how big? “I’ll assume a few dozen documents that fit in memory.”
- Hosted embeddings or a local model? “I’ll use a local embedding model from the sentence-transformers library in Colab.”
- Is there a labeled question set? “I’ll assume not, so I’ll write 20–30 questions with their relevant document IDs.”
- Do answers need one passage or several? This decides whether hit rate or recall is the honest number.
- How many chunks go to the model? “I’ll assume k = 5.”
Answer
The build, in order
- Chunk on headings and paragraphs, with stable IDs like
doc.md#3and the heading path attached. Stable means the same chunk gets the same ID on every run, because your labels and citations point at it. - Embed with
normalize_embeddings=True. That makes every vector length 1, so the similarity score between the question and every chunk (cosine similarity, the angle between two vectors) is one matrix multiply:matrix @ query. Thenargpartitionpicks the top k without sorting the whole corpus. - Generate with a prompt that lists numbered sources, requires
[n]citations and allows “I don’t know”. Check the citations in code: every sentence cites, and every citation points at a chunk the model was given.
The family walkthrough has the code for each stage.
Hit rate and recall are different numbers
The interviewer named two metrics. Separate them first, because many people (and codebases) blur them:
- Hit rate (hit@k): the share of questions with at least one relevant chunk in the top k.
- Recall@k: the share of all relevant chunks that made the top k. It is lower whenever an answer needs two chunks and you found one.
Follow one question to see the difference. Say a user asks “Can I get a refund on an annual plan after 30 days?” (an illustrative example). Two chunks answer it: A, the refund policy, and B, the annual-plan terms. Your search returns five chunks in this order:
| Position | Chunk | Relevant? |
|---|---|---|
| 1 | C (an FAQ entry) | no |
| 2 | A (refund policy) | yes |
| 3 | D (account settings) | no |
| 4 | B (annual-plan terms) | yes |
| 5 | E (another billing page) | no |
| Metric | Value | What to say in the interview |
|---|---|---|
| hit@3 | 1 | ”Something useful is in the top 3.” |
| recall@3 | 0.5 | ”But the model only sees half of what it needs if I send 3.” |
| recall@5 | 1.0 | ”At k = 5 it gets both, so k = 5 is the setting I’d report.” |
Say: “I report both, at the k I actually send. Hit rate says whether the model got anything useful; recall says whether it got everything it needs.”
How to improve the evaluation, in order
- A real labeled set. Grow it to 50+ questions, written before tuning anything. Include paraphrases that share no words with the source, identifiers such as error codes, questions that need two chunks like the refund one, and a few the corpus can’t answer. Score those last ones on whether the system says “I don’t know”. Label at the document level if chunk IDs move when you re-chunk.
- An error bar. Twenty questions is a small sample. With 20 questions and a hit rate of 0.8, the 95% interval is about ±17.5 points, so 0.8 could really be anything from about 0.62 to 0.98. When you compare two configurations on the same questions, use a paired bootstrap: resample the questions many times, recompute the difference between the two systems each time, and see whether the middle 95% of differences excludes zero.
- Metrics that care about order. Add MRR (mean reciprocal rank: 1 ÷ the position of the first right chunk, averaged over questions) or nDCG@10 (a score that rewards relevant chunks near the top, 1.0 for the perfect order) when order matters. Also measure recall at a deeper cut, such as the top 50. If the right chunk isn’t in the top 50 either, a reranker (a slower model that re-scores a short list) can’t help.
- The answer itself. First run the free, code-only citation checks. Then measure faithfulness: whether every claim in the answer is supported by the cited chunk. That needs a judge, usually another LLM call. Check the judge against about 30 answers you labeled yourself before you trust its number.
- Baselines. Report keyword search alone (BM25, the standard keyword-ranking formula) and vector search alone (dense) next to the combined version (hybrid). If the hybrid isn’t better than both, look for a bug.
The rag lab shows why the baselines matter. On SciFact, a public benchmark of science claims, its hybrid scored
about the same as dense until the keyword side’s word-splitting was fixed: hit@3 of
69.3 / 68.3 / 72.7 % (measured on Apple M1 Ultra, 64 GB RAM, torch 2.14.1, sentence-transformers 6.1.0 (MPS), 2026-10-11 · rag lab) (dense, hybrid, rerank) versus
73.7 % (measured on Apple M1 Ultra, 64 GB RAM, torch 2.14.1, sentence-transformers 6.1.0 (MPS), 2026-10-11 · rag lab) for hybrid with a \w+ tokenizer. Without the
baselines side by side, nobody would have noticed that one half was barely contributing.
The arithmetic behind the numbers (for a Staff-level follow-up)
hit@k = mean over queries of [any relevant in top k]; recall@k = mean of |relevant ∩ top k| ÷ |relevant| relevant- labeled relevant chunks or documents for one query
k- number of results sent to the model
A query with relevant A and B, ranking [C, A, D, B, E]: hit@3 = 1, recall@3 = 0.5, recall@5 = 1.0
- The ±17.5 points: 1.96 × √(0.8 × 0.2 ÷ 20) = 1.96 × 0.0894 ≈ 0.175.
Senior vs Staff
Notebook RAG and its eval
Senior
- Builds it fast, separates hit rate from recall at the k actually sent, and adds intervals and baselines.
Staff
- Turns the labeled set into a gate that blocks regressions, and says which product decision the metric informs.
Small-team version
At a small company this notebook is often the first version of the feature. The advice in money and actions:
- Call a hosted embedding API. text-embedding-3-small was listed at $0.02 per million tokens when fetched on 2026-10-11, so embedding cost doesn’t matter.
- Keep vectors in NumPy. Revisit storage only past a million or so vectors.
- Spend the saved time on the labeled set. 50 questions written with someone who knows the domain, run on every change, is worth more than any framework.
- Budget for generation, not embedding. With the family walkthrough’s assumptions (2,200 input and 300 output tokens per query), gpt-5-mini at $0.25 / $2.00 per million costs about $0.00115 per query, so 5,000 queries a day is about $173 per 30 days. Change the model only when the eval says the cheap one fails.
The arithmetic behind the numbers (for a Staff-level follow-up)
- Per query: 2,200 × $0.25 ÷ 10⁶ + 300 × $2.00 ÷ 10⁶ = $0.00055 + $0.0006 = $0.00115.
- Per 30 days at an assumed 5,000 queries a day: 150,000 × $0.00115 ≈ $173.
Pitfalls
- Calling a hit rate “recall”. They differ whenever an answer needs more than one chunk.
- Reporting at a k you don’t send. recall@20 says nothing about what the model saw at k = 5.
- Twenty questions and no interval. A ±17.5-point error bar is too wide to declare one configuration the winner.
- Eval questions generated from the chunks they are scored against. They share the chunk’s words, so every score looks better than it is.
- Optimizing retrieval while generation is the one failing. Check the citations and faithfulness too, or you tune the wrong half.
Go deeper
- Family walkthrough: Build a small RAG in code, then measure it, especially Verification.
- Metrics and when each fits: Measure retrieval and debug confident wrong answers.
- Labs: Build Your Own RAG System, Build Your Own LLM Evaluation Harness, Build Your Own Embedding Pipeline.