Lesson 5.2 · 8 min read · about 55 min to master at a very slow pace
Retrieval Metrics: Recall@k, MRR and nDCG
How to measure the search half of RAG on its own: recall@k, precision@k, mean reciprocal rank and nDCG, each computed by hand on a small example, and which one to use when.
Why measure retrieval separately
If the right chunk is never retrieved, the answer cannot be right (lesson 3.3). Retrieval metrics need only a list of queries and, for each, the relevant chunk(s). No LLM is involved, so they are fast and cheap to run after every change to chunking, embeddings or ranking.
Recall@k and precision@k
For RAG, recall@k is usually the key number, with equal to the number of chunks you send: did the evidence reach the model?
Mean reciprocal rank
For each query, take of the first relevant result (0 if none in the list), then average over queries:
MRR rewards putting the right chunk at the very top, which matters when only the first few are used.
Worked example: four queries, one relevant chunk each
| Query | Rank of relevant chunk | In top 3? | 1/rank |
|---|---|---|---|
| Q1 | 1 | yes | 1 |
| Q2 | 3 | yes | 0.333 |
| Q3 | 2 | yes | 0.5 |
| Q4 | not found | no | 0 |
Recall@3 . MRR .
nDCG
When relevance is graded (2 = perfect, 1 = partly useful, 0 = irrelevant) and several chunks matter, use normalised discounted cumulative gain. Each result's relevance is discounted by its position:
IDCG is the DCG of the ideal ordering, so nDCG lies between 0 and 1.
Example: relevances in ranked order . DCG . Ideal order : IDCG . nDCG@3 .
| Metric | Use it when |
|---|---|
| Recall@k | You send chunks to the LLM and need the evidence among them (the RAG default) |
| MRR | One right answer per query, and its position matters |
| nDCG@k | Graded relevance, several useful results (search results pages) |
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passHow do I label which chunks are relevant?
For each eval question, a person marks the chunk (or document section) containing the answer. If chunking changes, map labels at the document-section level, or check whether the retrieved text contains the answer span, so labels survive re-chunking. An LLM can propose labels for review to speed this up.
Going deeperRecall@5 went up but answer quality did not. Why?
Retrieval is necessary but not sufficient. If the evidence now arrives but at position 5 among distracting chunks, or the generator fails to use it, answers won't improve. Look at MRR or the rank of the evidence, and at generation metrics such as faithfulness (lesson 5.4).
Cheatsheet
Recall@k and precision@k
MRR
nDCG
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.