Modules/Gen AI/ Evaluation Lab

Retrieval Evaluation Metrics

Same five relevant documents, ten retrieved, three orders. Precision and recall see no difference at all. Two other metrics see everything.

Overview

Why classification metrics are not enough

A retriever does not return a yes or no; it returns an ordered list of candidates. Two systems can retrieve exactly the same documents and be very different in quality if one puts the relevant ones first and the other buries them at position 10.

So retrieval metrics are evaluated at a cutoff k — the number of results a user or a downstream model will actually see — and the better ones are sensitive to position within that cutoff.

Ranking

5

all three rankings retrieve exactly the same 5 relevant / 5 irrelevant documents

Ranked Results, 1 to 10

nDCG Working

Metrics @ k

Precision@k0.60
Recall@k0.60
MRR1.00
nDCG@k1.00

 

Retrieval Evaluation Metrics: A Practical Guide

Retrieval returns a ranked list, so the metric has to care about order. Precision@k, recall@k, MRR and NDCG each answer a different question about that list.

Precision@k and Recall@k

precision@k = (relevant in top k) / k

recall@k    = (relevant in top k) / (total relevant)

Precision@k asks how much of what you returned was useful. Recall@k asks how much of what exists you managed to find.

With 3 relevant documents in the collection and a top-5 list containing 2 of them: precision@5 = 2/5 = 0.4, recall@5 = 2/3 = 0.67.

Both ignore order entirely — a relevant document at position 1 and at position 5 count identically. For a RAG pipeline feeding a fixed number of chunks to a model that may be the right simplification; for a search results page it is not.

MRR and NDCG

MRR (mean reciprocal rank) uses only the position of the first relevant result, averaged over queries:

MRR = mean(1 / rank of first relevant)

First position scores 1.0, second 0.5, third 0.33. It is the right metric when the user needs one good answer and will stop reading once they have it — question answering, navigational search — and it deliberately ignores everything after the first hit.

NDCG (normalised discounted cumulative gain) is the most complete of the four. It handles graded relevance rather than a binary label, applies a logarithmic discount so later positions contribute less, and normalises by the score of the ideal ranking so the result lands in [0, 1] and is comparable across queries.

Use NDCG when relevance comes in degrees and the whole ordering matters; use MRR when only the first hit does.

Measuring the stage that usually fails

Almost all RAG failures are retrieval failures: the right chunk never reached the model. Debugging the prompt while recall is 0.4 is wasted effort, so retrieval needs its own metrics, measured separately.

What you need is a small evaluation set — 50 to 200 real questions, each with the id of the chunk (or chunks) that actually answers it. Building it is the unglamorous part and it is what makes every subsequent decision measurable rather than anecdotal.

The metrics divide into two families:

Did we find it? Recall@k, hit rate@k. Binary, per query.

Where did we find it? MRR, nDCG, precision@k. Rank-sensitive.

MetricQuestion it answers
Recall@kWhat share of the relevant documents are in the top k?
Hit rate@kIn what share of queries is at least one relevant doc in the top k?
Precision@kWhat share of the top k are relevant?
MRRHow high is the first relevant document, on average?
nDCG@kHow good is the whole ranking, with graded relevance?

Recall@k is the one that matters most for RAG

Because the model only sees the top k, recall@k is a ceiling on the whole system. If the answer is not in the retrieved set, no prompt engineering recovers it.

recall@k = (relevant documents in the top k) / (all relevant documents)

With one relevant document per question, recall@k equals hit rate@k, and that is the common case for factoid evaluation sets.

Measure it at several k and read the curve:

kRecallInterpretation
10.42Ranking is imprecise
50.71Usable
200.94The right chunk is nearly always in the top 20
500.96Diminishing

That table diagnoses precisely. Recall@20 of 0.94 with recall@5 of 0.71 means the retrieval finds the document but does not rank it highly — which is a reranking problem, not a chunking or embedding problem. If recall@50 were 0.6, the document is not being found at all, and reranking cannot help.

That distinction — find versus rank — is the single most useful thing these metrics tell you.

Rank-sensitive metrics

MRR (mean reciprocal rank) averages 1/rank of the first relevant result:

First relevant at rankReciprocal rank
11.00
20.50
30.33
100.10
Not found0

MRR is appropriate when there is essentially one right answer and its position matters — which describes most question answering. It is harsh on rank 2 versus rank 1, which is arguably correct given how much more attention a model pays to the first chunk.

nDCG@k handles graded relevance: a document can be highly relevant, somewhat relevant or irrelevant, and the metric discounts gains logarithmically by position. It is the standard in information retrieval research and requires graded judgements, which are more expensive to collect than binary ones.

Precision@k matters less for RAG than the others, because passing a few irrelevant chunks alongside the right one is usually tolerable. It matters when context budget is tight or when irrelevant context measurably degrades answers — which it does.

Interactive Exploration Guide

  1. Move the cutoff. Slide k from 1 to 10 and watch precision@k and recall@k move in opposite directions. A larger k almost always raises recall and lowers precision.
  2. Change the ranking. Switch Ranking so the relevant documents sit lower. Precision@k and recall@k at a large k barely move, while MRR and NDCG drop sharply — that difference is exactly what order-aware metrics measure.
  3. Put one relevant result first. Choose a ranking with a relevant document at position 1. MRR jumps to 1.0 regardless of what follows, which shows how much it ignores.
  4. Set k = 1. Precision@1 and recall@1 become extremely blunt. At small k the choice of metric matters far more than at large k.

Choosing one for a RAG pipeline

For retrieval feeding a language model, recall@k is usually the metric that matters most. The model can ignore an irrelevant chunk among the k it receives, but it cannot use a relevant chunk that was never retrieved — a missed document is unrecoverable, whereas a spurious one is merely noise.

Set k to the number of chunks you actually pass to the model and measure recall at that value. Then use precision or NDCG as a secondary check, since packing the context with irrelevant material does cost tokens and can distract the model.

What trips people up

  • Reporting a metric without its k. “Precision 0.4” is meaningless; precision@5 is a number.
  • Using accuracy. It has no meaning over a ranked list of a large corpus, where almost everything is irrelevant.
  • Ignoring order when order matters. Precision@k cannot distinguish a system that ranks well from one that merely retrieves the same set in a worse order.
  • Assuming complete relevance labels. Most evaluation sets label only judged documents, so an unjudged-but-relevant result counts against you and recall is systematically understated.
  • Averaging over too few queries. These metrics are noisy per query; differences need many queries to be meaningful.

Key takeaway

Retrieval returns a ranking, so metrics are computed at a cutoff k and differ mainly in whether they care about position. Precision@k and recall@k ignore order within the cutoff; MRR looks only at the first relevant result; NDCG discounts by position and handles graded relevance. For RAG, recall@k at your actual context size is the number to optimise, because the model can survive a bad chunk but not a missing one.

Building the evaluation set

This is the work that makes everything else possible, and there are three routes.

Hand-written. Domain experts write questions and identify the answering chunk. Highest quality, slowest. 50 questions is enough to start and enough to catch large regressions.

Generated from documents. For each chunk, ask a model to write a question it answers. Fast, and it produces questions phrased like the document, which flatters retrieval — the vocabulary gap that causes real failures is absent by construction.

Mined from logs. Real user queries paired with the documents that were clicked, cited or rated helpful. The most realistic, and it requires a system already in production.

The practical compromise: generate a first set to get moving, then replace it with mined real queries as they become available, and keep a hand-written set of known-hard cases as a regression suite.

Two habits that matter. Include negative cases — questions the corpus genuinely cannot answer — so you can measure whether the system declines rather than inventing. And version the set, so a change in the score means a change in the system rather than a change in the questions.

Measuring end to end as well

Retrieval metrics are necessary and not sufficient. The generation stage has its own failure modes, and the standard measures are:

MetricQuestion
Groundedness / faithfulnessIs every claim supported by the retrieved context?
Answer relevanceDoes the answer address the question asked?
CompletenessDoes it cover everything the question needed?
CorrectnessIs it right, against a known answer?

Groundedness and correctness can diverge informatively. An answer that is correct but ungrounded means the model answered from its own knowledge rather than the documents — which looks like success and will fail silently on anything the model did not memorise.

Frameworks such as RAGAS and TruLens implement these with a model as judge. Model-graded metrics are noisy and directionally useful; validate them against human judgement on a sample before trusting the absolute numbers.

What to do with the numbers

SymptomLikely causeAction
Low recall@50Not found at allChunking, embedding model, hybrid search
Good recall@20, poor recall@5Found but badly rankedAdd a cross-encoder reranker
Good recall, poor groundednessModel ignoring contextPrompt constraints, fewer chunks
Good retrieval, poor correctnessWrong document is relevant-lookingBetter evaluation set, or a real gap in the corpus
High precision, low recallToo selectiveRetrieve more candidates

Work top to bottom. Fixing retrieval before generation, and finding before ranking, is the ordering that avoids wasted effort.

Five metrics, one result list, five different answers

The sections above define each metric. Putting them side by side on the SAME ranking is what shows why they disagree -- and which disagreements are telling you something you need to act on.

example_01.pyNumPy
Output

Questions people ask

How many evaluation questions do I need? 50 catches large regressions; 200 gives reasonably stable comparisons between similar configurations.

Which metric should I optimise? Recall@k where k is the number of chunks you pass to the model. That is the system's ceiling.

Should I use generated questions? To get started, yes — while knowing they understate the vocabulary gap and therefore overstate your recall.

What is a good recall@5? Corpus-dependent. Compare against your own baseline rather than an absolute target, and track it over time.

Do I need graded relevance? Only if you are using nDCG. Binary judgements suffice for recall, hit rate and MRR.

How do I evaluate when there is no single right chunk? Mark all acceptable chunks as relevant and use recall, or move to graded judgements and nDCG.

Recap in one screen

  • Measure retrieval separately: it is where nearly all RAG failures are.
  • Recall@k is the ceiling on the whole system, because the model only sees the top k.
  • Comparing recall at several k separates "not found" from "found but badly ranked" — different fixes.
  • MRR suits single-answer questions; nDCG needs graded judgements.
  • Build 50–200 questions with known answers, include unanswerable ones, and version the set.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. Without scrolling back — what is the one-line takeaway from this module?

  2. What does this module say about “Why classification metrics are not enough”?

  3. What does this module say about “Ranking”?

Cheat sheet

Retrieval Evaluation Metrics

A retriever does not return a yes or no; it returns an ordered list of candidates. Two systems can retrieve exactly the same documents and be very different in quality if one puts the relevant ones first and the other buries them at position 10.

GEN AI · vizlearn.in/gen_ai/retrieval_evaluation_metrics.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.