AI Interviews · Question

Explain recall@k, MRR and NDCG: what each one measures and when you would use it to evaluate retrieval.

Domain deep dive question reported at Applied-AI loops (no single company) (2026). Sources, confidence and an answer card.

Researched · updated

eng-041 AI Engineer Evaluation 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: “All of these score one ranked list of search results against the items a person marked as relevant. Recall@k asks what share of the relevant items made the top k. Hit@k asks whether any of them did. MRR asks how high the first relevant item sits. nDCG uses graded relevance and rewards putting the best items highest. I pick the one that matches how results are used: if a model reads all k chunks, recall at the k I send; if only the first result matters, MRR; if people see a ranked page, nDCG.”

The rest of this page explains each part of that answer, with one example worked by hand.

The interviewer wants to know whether you know these metrics precisely enough to choose between them.

In most backend work, a query has one right answer: the row exists or it doesn’t. Search is different. A query returns a ranked list, several items can be relevant, some are more relevant than others, and the order matters to whoever reads it. Each metric captures a different slice of that. Using the wrong one hides real problems or reports fake ones.

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. The passages are called chunks.
  • The search returns chunks in score order. The best k are the top k.
  • Relevant set (R): for one query, the items a person marked as relevant. Labels can be yes/no (binary) or graded (2 = answers it, 1 = partly).

The source is a prep guide that says retrieval quality is scored with recall@k and precision@k, “and ranking quality with MRR or NDCG when the order of results matters” (techinterview.orgsecondary). It names the metrics without a candidate report of the question.

Clarify first

  • Binary or graded labels? “nDCG uses grades; the others treat relevance as yes or no.”
  • Who reads the results? “Does a person see a ranked list, or does a language model read the top k?”
  • One correct item per query, or several?

Answer

One example, used for every metric

A customer asks a support bot: “Can I get a refund on the annual plan 45 days after I paid?” (invented for illustration). Two chunks are relevant: A, the current refund policy (grade 2, fully answers it), and B, a billing FAQ entry that mentions the rule (grade 1). Search returns C, A, D, B, E. C is an outdated policy; D and E are unrelated.

The definitions, applied

MetricIn plain wordsFormulaValue for the exampleWhat to say in the interview
recall@kWhat share of the relevant items made the top k?relevant in top k ÷ all relevantrecall@3 = 0.5, recall@5 = 1.0”By rank 3 we have one of two.”
precision@kWhat share of the top k is relevant?relevant in top k ÷ kprecision@5 = 0.4”Three of five chunks are noise we pay tokens for.”
hit@kDid any relevant item make the top k?1 or 0hit@5 = 1”This is what most ‘recall’ code actually computes.”
RR (reciprocal rank)How high is the first relevant item?1 ÷ its rank, 0 if none0.5 (A at rank 2)“MRR is this averaged over queries.”
nDCG@kHow good is the whole order, given grades?DCG ÷ best possible DCGnDCG@5 = 0.643”Marked down because rank 1 is wrong.”

A few notes on the less obvious ones:

  • hit@k, averaged over queries, is called the “hit rate” (or success@k). Many implementations named “recall” compute this, so check before comparing numbers.
  • MRR (mean reciprocal rank) is the mean over queries of 1 ÷ the rank of the first relevant item. It ignores everything after the first hit.
  • nDCG@k (normalized discounted cumulative gain) adds up each result’s grade, divided by a discount that grows with its position, then divides by the score of the best possible ordering. The result is between 0 and 1.

The example shows why the metrics disagree. hit@5 says perfect. recall@3 says half. MRR is pulled down because rank 1 was wrong. nDCG lands in between, crediting A more than B.

The arithmetic behind the numbers (for a Staff-level follow-up)
One query, every metric
ranking [C, A, D, B, E]; relevant A (gain 2), B (gain 1)
recall@3, recall@5
1 of 2 found by rank 3, both by rank 5
RR
first relevant at rank 2
nDCG@5
linear gain, log₂ discount
Worked example

recall@3 = 0.5, recall@5 = 1.0, precision@5 = 0.4, hit@5 = 1, RR = 0.5

nDCG@5 = (2/log₂3 + 1/log₂5) ÷ (2/1 + 1/log₂3) = 1.6925 ÷ 2.6309 = 0.643

  • In set notation: recall@k = |R ∩ top k| ÷ |R|, precision@k = |R ∩ top k| ÷ k, and DCG = Σ gainᵢ ÷ log₂(i + 1).
  • The ideal ordering puts A (grade 2) first and B (grade 1) second.
  • Some libraries use exponential gain (2^grade − 1) instead of the grade itself. Say which one you use.

When to use each

Use caseMetric
RAG where the model reads all k chunks and answers need severalrecall@k at the k you send
RAG where one passage answers the questionhit@k
One right answer, first slot is what counts (a search box, a tool returning one item)MRR
Graded relevance and order matter (results page, product search, evaluating a reranker)nDCG@k
Context tokens are costly or distracting chunks hurt the modelprecision@k

For the refund bot, which sends 3 chunks, the honest number is recall@3 = 0.5. Say: “Hit@5 would call this query a success. The model never saw B.”

Three refinements for RAG

Measure recall at two depths. Measure the candidates before reranking (say the top 50) and the final k. A reranker, a slower model that rescores the candidates, can only reorder what search found, so recall at 50 is the ceiling on what it can fix.

Order inside the prompt still matters a little. Models do best when relevant text is at the beginning or end of the context (Liu et al., 2023).

Published numbers use nDCG@10. BEIR, the common public search benchmark, reports nDCG@10 as its headline (Thakur et al., 2021), so published model numbers come in that metric, which may not be the one your pipeline needs.

Report it with an interval

Whatever you pick, average it over a labeled set of queries, give a 95% interval (the range the true value very likely sits in), and compare two configurations on the same queries. Small gains are hard to see even then. The llm-eval lab (this site’s hands-on evaluation lab) measured the smallest gap a paired test reliably detects with 500 queries: 5.0 / 7.3 pp (measured on Apple M1 Ultra, 64 GB RAM, Python 3.13.7, numpy 2.5.4 (CPU, single thread), 2026-10-11 · llm-eval lab). Say: “A 2-point change on a few hundred queries is usually noise.”

Senior vs Staff

Retrieval metrics

Senior

  • Exact definitions, a hand-worked example, and the metric matched to how results are consumed.

Staff

  • Also says which metric stands in for which product outcome, and checks that offline gains show up in an online signal.

In plain words: Senior defines and picks the metric correctly. Staff also asks whether moving that metric moves anything users notice, and checks it in production.

Small-team version

You don’t need an evaluation library. These five functions are about 25 lines, and writing them yourself means you know whether your “recall” is really a hit rate.

  • Report one primary metric chosen for your use case, plus recall at candidate depth as a diagnostic. A dashboard of every metric is noise until someone acts on it.
  • Spend money on labels, not code. 50 queries at an assumed 3 minutes each is 2.5 hours of a domain expert, about $230 at an assumed loaded rate of $93 an hour.
  • Add graded labels (for nDCG) only if your results are shown to people as a ranked list. For a language model reading k chunks, binary labels and recall@k are enough.
The arithmetic behind the numbers (for a Staff-level follow-up)
  • Labeling: 50 × 3 min = 150 min = 2.5 h; 2.5 h × $93 (assumed) ≈ $230.

Pitfalls

  • Defining recall@k as “the right answer is in the top k”. That is hit@k, and it can hide missing evidence.
  • Using MRR for RAG, where the model reads all k chunks and the first slot isn’t special.
  • Quoting nDCG without saying whether gains are linear or exponential. The same ranking gives different numbers.
  • No interval. A 2-point change 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