The problem: this system does not answer yes or no
The page on evaluation metrics covers the case where a system decides: this email is spam, or it is not. Errors then come as false positives and false negatives, and precision, recall and F1 are enough.
A search engine does not do that. It never says "this document is relevant." It orders: here are a thousand documents, most promising first. And that order changes everything, because no reader gets to number one thousand. An excellent document in tenth place is worth far less than the same document in first place; in hundredth place, it does not exist.
Classification metrics cannot see that difference: to them, "retrieved" is "retrieved" regardless of position. So we need metrics that account for position. There are four of them, they appear throughout the retrieval, agent and evaluation pages, and this page builds each one from scratch.
The shared setup
All of these metrics assume the same thing: a test set in which, for every query, someone has recorded in advance which documents in the corpus are relevant. That annotation is called the relevance judgement. Without it none of these metrics can be computed, it is the expensive, unavoidable groundwork of any retrieval evaluation.
The K in the names is simply how many results you look at: recall@10 means "recall over the first ten results." You pick K from the real usage: ten if a human scans a page of results, five if a language model is going to read five passages, one if an agent consumes only the top hit.
Recall@K and precision@K
These two carry over the classification definitions unchanged, but applied only to the top of the list, the first K results.
Recall@K answers: of all the relevant documents that exist, what share sits in my top K?
Precision@K answers the mirror question: of the K results I returned, what share is relevant?
Same numerator, different denominators: recall divides by what exists, precision by what you showed.
An example to recompute
A query for which the corpus contains 8 relevant documents. The system returns ten results, four of them relevant, at positions 1, 2, 6 and 9.
| Metric | Calculation | Result |
|---|---|---|
| recall@10 | 4 relevant found ÷ 8 existing | 0.50 |
| precision@10 | 4 relevant ÷ 10 results shown | 0.40 |
| recall@3 | 2 relevant in the top three ÷ 8 | 0.25 |
| precision@3 | 2 relevant ÷ 3 results shown | 0.67 |
The trade-off reads straight off the table. Going from K = 10 to K = 3, precision rises (0.40 → 0.67: the list is cleaner) and recall falls (0.50 → 0.25: two good answers were cut off). Widening K can never lower recall nor raise precision. So the right K is not a measurement question, it is a usage question: how many results will the rest of the pipeline actually read?
Neither recall@K nor precision@K looks at the order within the top K. Four relevant documents at positions 1, 2, 6, 9 give exactly the same @10 scores as the same four at positions 7, 8, 9, 10. That is precisely the hole the next two metrics fill.
MRR: how high does the first good answer land?
MRR stands for mean reciprocal rank. It is built in two steps.
First, for one query, find the rank of the first relevant result and take its reciprocal. First relevant result in position 1: score of 1. In position 2: 1/2 = 0.5. In position 10: 1/10 = 0.1. Everything after that first hit is ignored.
Then take the mean of those reciprocals across every query in the test set:
where is the number of queries and the position of the first relevant result for query . In one sentence: score each query by the reciprocal of its first hit's rank, then average those scores.
This is the most common error on this metric, and it sat for a long time in this very course's retrieval-evaluation page. Three queries, whose first relevant result arrives in position 1, 2 and 10.
The correct calculation, average the reciprocals:
The wrong calculation, average the ranks, then invert: mean rank , whose reciprocal is .
0.53 against 0.23: more than double. This is not a rounding subtlety. Averaging reciprocals gives enormous weight to well-served queries and flattens the failures, the difference between rank 10 and rank 50 is almost nil (0.10 against 0.02), whereas the difference between rank 1 and rank 2 is a full 0.5. That is exactly the behaviour you want when a user looks at the first result and stops there.
MRR is therefore the search-box metric, and more generally the metric for anything that consumes a single answer. Its blind spot is the exact mirror of its strength: it says nothing about what comes after the first hit.
NDCG: what if relevance came in degrees?
The three previous metrics assume binary relevance, a document is useful or it is not. In practice that is false: a document that answers the question exactly is not worth the same as one that merely brushes past it.
NDCG stands for normalized discounted cumulative gain. The name is opaque but perfectly descriptive, read it right to left, in three pieces.
1. The gain. Each document gets a relevance grade, say from 0 (off topic) to 3 (perfect answer). The usual gain is , where is the grade. Why that shape? The exponential makes a highly relevant document disproportionately more valuable than a vaguely relevant one: grades 0, 1, 2, 3 yield gains 0, 1, 3, 7. The "" exists only so that a grade of 0 produces a gain of 0.
2. The discount. A gain earned low in the list counts for less. The usual factor is . The "" sets the scale: at rank 1, , so no discount at all. At rank 2 you keep ; at rank 3, . The logarithm makes the weight decay gently rather than abruptly: dropping from rank 1 to rank 2 costs far more than dropping from rank 20 to rank 21.
3. The cumulation, then the normalisation. Add up the discounted gains of the first K results: that is the DCG (discounted cumulative gain). Then divide by the DCG of the ideal ranking, the same documents reordered perfectly, most relevant first. That denominator is called the IDCG (ideal DCG). The division brings everything into the 0-to-1 range, where 1 means "perfect order," which makes queries comparable with each other: a query with one relevant document and a query with fifty can both reach 1.
The full calculation on three results
Three returned results, with relevance grades 3, 0 and 2 in that order. Gains: 7, 0, 3.
The ideal order would be 3, 2, 0, so gains 7, 3, 0:
The ranking is close to optimal: the only fault is placing the off-topic document ahead of the moderately relevant one, and that fault happens in positions 2 and 3, where the discount already bites. A score of 0.96 says exactly that, a real mistake, but a mild one.
Which one to look at, given the question you are asking
| The question you are asking | The metric | Why that one |
|---|---|---|
| Is the right answer anywhere in the list? | recall@K | If it is not there, nothing downstream can recover it: that is the worst failure mode |
| Is the list I am passing on a clean one? | precision@K | Matters when whatever consumes the list drowns in noise |
| A human reads ten results | recall@10 | They will sift the ten themselves; what matters is that the answer is among them |
| A machine consumes only one | MRR | Only the position of the first hit has any effect; the rest is never read |
| Degrees of relevance matter | NDCG@K | The only metric that distinguishes "answers perfectly" from "brushes the topic" |
| I want to judge a reranker | NDCG@K | A reranker changes not what was found but only the order, so only an order-sensitive metric will do |
The useful habit is not to pick one. It is to look at all four: pushing any single one of these up at the expense of the others is easy, and a table showing only one has probably shown the convenient one.
Where these metrics are used in this course
For precision and recall in classification, with false positives and false negatives: evaluation metrics. For their use in evaluating a retrieval-augmented system: evaluating a RAG system. For a concrete implementation inside a retrieval toolkit: Search Toolkit.
Why this matters
Faced with a claim like "our search is 30% better," the first question is: better on which metric? A system can gain 30% MRR by lifting the right document from position 3 to position 1 without finding anything new, or gain 30% recall by widening the list at the cost of collapsed precision. Those two gains describe completely different inventions. Knowing which one is in play is knowing what is actually contributed, and therefore what is actually being claimed.
1. The corpus contains 8 relevant documents for a query; the system returns ten results, four of them relevant. What are recall@10 and precision@10?
2. Three queries find their first good answer at positions 1, 2 and 10. What is the MRR?
3. Four relevant documents at positions 1, 2, 6 and 9 give exactly the same recall@10 and precision@10 as the same four at positions 7, 8, 9 and 10. What does that reveal?
4. Why is NDCG the right metric for judging a reranker?
5. A vendor announces: « our search is 30% better ». What is the first question to ask?