AI Interviews · Question

How do you measure whether retrieval is fetching the right context for the model?

Domain deep dive question reported at OpenAI (2026). Sources, confidence and an answer card.

Researched · updated

eng-009 AI Engineer RAG & retrieval quality Domain deep dive Low confidence
On this page

What they’re really asking

If you only remember one thing, say this in the first minute: “I’d turn ‘is retrieval working?’ into a number. I’d collect a few hundred real questions and have someone who knows the domain mark which documents answer each one. Then I’d measure how often the right chunks land in the top k we actually send to the model, and also in the top 50 before any reranking, so I know whether search or ranking is the weak part. I’d put an interval on every number and compare versions on the same questions. In production, where there are no labels, I’d watch citations, declines and user feedback, and feed every failure back into the labeled set.”

The rest of this page explains each part of that answer.

The interviewer wants to know whether you can measure something that has no error code.

In a normal backend service, “is it working?” has a clear answer: requests succeed, tests pass, the p99 is under target. A search step inside an AI app is different. It always returns something, with status 200. Whether those results were the right ones is a matter of judgment, and it varies from question to question. So the only honest answer is a rate measured over many questions, with a known uncertainty.

Words you need first

  • RAG (retrieval-augmented generation): before a language model answers, the system searches your own documents and pastes the best passages into the prompt. Finding the passages is retrieval.
  • Documents are split into passages of a few hundred words called chunks. Search returns chunks.
  • The search returns chunks in score order. The best k are the top k, and k is how many you send to the model.
  • A labeled query set is a list of real questions where a person has marked which chunks or documents are relevant to each one. It is the test suite for retrieval.

This question comes from a prep guide’s list for OpenAI’s forward-deployed technical deep dive, not from a candidate report. The guide’s own framing: “The reliable differentiator is a concrete answer to how you know the system works” (theforwarddeployed.iosecondary).

Clarify first

Ask these before answering. Each one changes the metric you pick.

  • How many chunks reach the model, and does an answer usually need one passage or several? “If one passage is enough, I care whether any right chunk shows up. If the answer needs three, I care how many of them show up.”
  • Is there a labeled set, or only logs? Assume logs but no labels.
  • Is there a reranker (a second, slower model that reorders the search results)? “Then I’ll measure both before and after it.”
  • Offline evaluation, production monitoring, or both? Cover both briefly.

Answer

Follow one question through the measurement

Use one example the whole way. A customer asks a software company’s support bot: “Can I get a refund on the annual plan 45 days after I paid?” (invented for illustration). A domain expert marks two chunks as relevant:

  • A, the current refund policy (“refundable within 30 days”), which fully answers it;
  • B, a billing FAQ entry that mentions the 30-day window.

Search returns C, A, D, B, E, where C is an outdated 2024 policy and D and E are unrelated. The bot sends the top 3 to the model.

StepWhat you doResult for this questionWhat to say in the interview
1. Build the setSample 50–200 real questions from logs, add every reported bad answer, add a few the documents can’t answerThis question is one row”The labeled set is the asset. Everything else is a script.”
2. Pick the metricMatch it to how the model uses the resultsThe answer could come from A alone, but B helps”I report the metric at the k we actually send.”
3. Measure at the final kShare of relevant chunks in the top 3 (recall@3)0.5: A is there, B isn’t”The model saw half of what’s relevant.”
4. Measure at candidate depthShare in the top 50 (recall@50)1.0: both were found”Search found everything. Ranking is the weak part here.”
5. Put an interval on itAverage over all questions, with a 95% intervale.g. recall@3 = 0.80 on 200 questions, about ±5.5 points”A 3-point change on 200 questions is inside the noise.”
6. Compare pairedRun both versions on the same questionsCount per-question wins and losses”Paired comparison removes most of the noise.”

Pick the metric by how results are used

There are four common retrieval metrics. Each answers a different question, so the right one depends on what happens to the results next:

  • hit@k: did any relevant chunk appear in the top k? Use it when one passage is enough to answer. Many pieces of code called “recall” actually compute this.
  • recall@k: what share of the relevant chunks appeared in the top k? Use it when the model reads all k chunks and the answer needs several of them. Measure it at the k you actually send.
  • MRR (mean reciprocal rank): 1 ÷ the rank of the first relevant result, averaged over questions. Use it when only the first result matters, such as a search box or a tool that returns one item.
  • nDCG@k (normalized discounted cumulative gain): a score that uses graded relevance (“fully answers” vs “partly”) and counts lower positions less. Use it when grades and the whole order matter, as on a results page.

For the refund question: hit@3 = 1, recall@3 = 0.5, and the reciprocal rank is 0.5 (the first relevant chunk is at rank 2). Say: “Hit@3 says this question is fine. Recall@3 says the model missed half the evidence. For a bot that reads all three chunks, recall@3 is the honest number.”

Why two depths

A reranker can only reorder what search found. So measure recall twice. Recall at candidate depth (the top 50 before reranking) tells you what a reranker could possibly recover. Recall at the final k tells you what the model actually sees. If recall@50 is high and recall@3 is low, invest in ranking. If recall@50 is low, a reranker cannot help; fix chunking or search first.

The rag lab (this site’s hands-on retrieval lab) shows this: reranking improved the top 3 but left hit@20 unchanged. It can only reorder.

Put an interval on it, and compare paired

Every rate measured on a sample is uncertain. The 95% interval is the range the true value very likely sits in. At a measured rate of 80%, 20 questions give about ±17.5 points and 200 give about ±5.5 points.

To compare two versions, run both on the same questions and look at the difference question by question. This paired comparison is much tighter, because most questions get the same result under both versions and only the disagreements add noise.

The rag lab is a worked example of reading such numbers: hit@3 on SciFact (a public set of scientific-claim questions) was 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) for vector search, hybrid search and reranking. With about 300 queries, gaps under about 4 points are noise, so only the reranker’s gain cleared its interval.

The arithmetic behind the numbers (for a Staff-level follow-up)
Interval on a retrieval rate
± 1.96 × √( p (1 − p) ÷ n )
p
e.g. recall@5
n
labeled queries
Worked example

p = 0.8: n = 20 gives ±17.5 points, n = 200 gives ±5.5

  • For the refund question: recall@3 = |{A}| ÷ |{A, B}| = 1 ÷ 2 = 0.5; recall@50 = 2 ÷ 2 = 1.0; reciprocal rank = 1 ÷ 2 = 0.5.

Online: proxies, because production has no labels

In production nobody labels each question, so you cannot compute recall. Watch signals that move with retrieval quality instead:

  • the share of answers with valid citations (each one pointing at a chunk that was actually in the prompt);
  • how often the bot declines (“I don’t know”);
  • thumbs-down and escalation rates;
  • the spread of the top retrieval scores. A shift often means new kinds of questions or a broken index.

Then run a calibrated LLM judge (a second model, checked against human labels, that grades answers) on a daily sample, asking “did the retrieved context contain what the answer needed?” Move each failure you find into the labeled set.

Senior vs Staff

Measuring retrieval

Senior

  • Labeled set, the metric matched to consumption, recall at candidate depth and final k, intervals and paired comparison.

Staff

  • Owns how the set grows from production failures and which release it gates, and pairs offline metrics with an online proxy so a drift is caught between evals.

In plain words: Senior gets a correct, honest number. Staff makes that number part of how the team ships, and makes sure someone notices if retrieval quality drifts between releases.

Small-team version

The labeled set is the expensive part, and the cost is people’s time, not compute. 200 questions at an assumed 3 minutes each is about 10 hours of a domain expert, roughly $930 at an assumed loaded rate of $93 an hour. Start with 50 plus the reported failures.

  • Build the metric script yourself. It is an afternoon of work; the family’s coding walkthrough has one.
  • Buy the judge model from the provider you already use. A daily 200-item judge run costs about $0.19 on gpt-5-mini or $1.30 on Claude Sonnet 5 (list prices fetched 2026-10-11).
  • Grow the set past 200 when the changes you care about are smaller than its ±5.5-point interval.
The arithmetic behind the numbers (for a Staff-level follow-up)
  • Labeling: 200 × 3 min = 600 min = 10 h; 10 h × $93 (assumed) = $930.
  • Judge run, assumed 2,500 input and 150 output tokens per item: gpt-5-mini at $0.25 / $2.00 per million tokens gives 200 × (0.000625 + 0.0003) ≈ $0.19; Claude Sonnet 5 at $2 / $10 per million gives 200 × (0.005 + 0.0015) = $1.30.

Pitfalls

  • “We look at some answers” as the whole method. Without a number, the guide says, the interviewer “assumes you tuned yours by feel” (techinterview.orgsecondary).
  • Reporting recall at a k the model never sees. A perfect recall@20 means nothing if the model gets 3 chunks.
  • Only synthetic questions generated from the chunks. They reuse the chunks’ own wording, so search looks better on them than on real users.
  • No interval. A 2-point change on a few hundred questions gets reported as a win when it may be noise.

Go deeper

Family

Measure retrieval and debug confident wrong answers

Find the stage that produced a confident wrong answer: trace it, sort failures by stage, give retrieval a number on a labeled query set, check answers against their sources, and prove each fix. High-risk answers add abstention and review.

Other questions in this family