Precision, Recall, MAP, MRR, and NDCG

These metrics summarize different user promises made by a ranked retrieval system. This page gives the worked definitions and examples; Ranking and Retrieval Metrics is the compact overview.

For the classifier-side intuition and confusion-matrix diagrams behind precision and recall, see Evaluation Metrics.

Metric definitions

Assume one query returns a ranked list of documents . Each document has a relevance judgment at rank . For binary metrics, means relevant and means not relevant. Let be the number of known relevant documents for the query.

Ordinary precision and recall apply to a retrieved set , not necessarily to a cutoff:

Here is the gold set of relevant documents. Precision asks how clean the retrieved set is; recall asks how much relevant material the set found. In a ranked product, users usually see only the first page or the context budget only admits a few chunks, so the same definitions are often evaluated at a cutoff :

The symbol is an indicator: it contributes 1 when the condition is true and 0 otherwise.

Average precision summarizes the whole ranking for one query by averaging precision at the ranks where a relevant result appears:

Mean average precision, MAP, is the mean of AP across queries. Reciprocal rank for one query is , where is the rank of the first relevant result. Mean reciprocal rank, MRR, averages that value across queries. NDCG handles graded relevance by giving more credit to highly relevant documents and discounting results that appear lower in the ranking.

The @k suffix means “evaluate only the first ranks.” Without @k, the metric is normally computed over the full retrieved/evaluated ranking or, for MAP and MRR, averaged over the full query set. Cutoff variants such as , , or truncate the ranking before scoring; for example, is zero for a query whose first relevant result appears at rank 11.

Binary Example

Suppose a search system returns five documents, and the binary relevance labels are:

RankDocumentRelevant?
1Ayes
2Bno
3Cyes
4Dyes
5Eno

There are four known relevant documents in the corpus, so one relevant document was missed outside the top five.

MetricCalculationValue
Precision over top 53 relevant among 5 retrieved0.60
Recall over top 53 of 4 known relevant documents0.75
2 relevant among the first 3 ranks0.67
2 of 4 known relevant documents0.50
Reciprocal rankfirst relevant result is at rank 11.00
Average precision0.60

This example shows why ordinary and cutoff metrics answer different questions. Precision over the top five says the retrieved list is moderately clean. Recall over the top five says it found most, but not all, known relevant material. and focus only on what a user or RAG context builder sees first.

Query-Set Example

MAP and MRR are query-set metrics: compute a per-query score first, then average. Suppose three queries have these relevant ranks:

QueryRelevant ranksAP calculationAPRR
Q11, 30.831.00
Q220.500.50
Q3none retrievedno relevant result retrieved0.000.00

Then , while . MAP rewards finding multiple relevant documents across the ranking. MRR cares only about how quickly the first relevant result appears.

NDCG: Normalized Discounted Cumulative Gain

NDCG is useful when relevance is not just binary. A document can be perfect, useful, marginal, or irrelevant, and the metric should reward putting the strongest evidence near the top. It is common in web search, product search, recommendations, document retrieval, and RAG source ranking.

NDCG has three steps:

  1. Convert each relevance label into a gain.
  2. Discount each gain by rank.
  3. Normalize by the best possible ordering for the same labels.

Step 1: Choose Gains

The first step is to choose a gain for each result. In the simplest version the gain is the human relevance label itself:

Some evaluations use an exponential gain,

which makes the jump from relevance grade 2 to 3 larger than the jump from 0 to 1. This is common when the top grades are qualitatively much better than the lower grades.

For example, with labels 0 = irrelevant, 1 = marginal, 2 = useful, and 3 = excellent, linear gains are , while exponential gains are . Exponential gains say that an excellent document is much more valuable than a merely useful one.

Step 2: Discount by Rank

The second step is to discount each gain by rank:

Rank 1 has discount , so the first result keeps its full gain. Rank 2 has discount , rank 3 has discount , and later ranks count less and less. The logarithm makes the penalty strong near the top but gentler farther down the list.

This creates the main intuition: the same excellent document is worth more at rank 1 than rank 5 because users are less likely to inspect it later, and a RAG pipeline may drop it before generation.

Step 3: Normalize by the Ideal Ranking

The final step is normalization. Sort the same relevance labels into the best possible order and compute the corresponding ideal DCG:

Here is a permutation of the retrieved relevance labels: it represents a possible reordering. The ideal permutation puts the largest gains first.

Then

The normalization turns the score into a value between 0 and 1 when gains are non-negative. A perfect ordering gets 1.0; a weaker ordering gets less, with larger penalties when highly relevant results are pushed down.

If no cutoff is written, NDCG is computed over the evaluated ranking length. In product evaluations it is usually reported as because only the top results are visible or useful.

NDCG Worked Example

Suppose a query asks for the current enterprise refund approval policy, and the top five retrieved chunks receive these graded labels:

RankChunkLabelMeaning
1A3exact current policy table
2B0unrelated support macro
3C2relevant explanation, but less specific
4D1marginally useful background
5E0stale or irrelevant content

Using linear gains, the displayed order has relevance labels :

RankRelevanceDiscount Contribution
131.0003.000
200.6310.000
320.5001.000
410.4310.431
500.3870.000

So

The ideal ordering would put the same grades as :

Therefore

This score is high because the exact policy table is already first and the useful explanation is still near the top. It is not perfect because the irrelevant result at rank 2 appears before the grade-2 and grade-1 chunks.

Now compare a worse ordering with the same five chunks: . Precision@5 and recall@5 are unchanged because the same three relevant chunks are retrieved. MRR is worse because the first relevant chunk moved from rank 1 to rank 2. NDCG also falls because the best chunk no longer receives the full rank-1 discount:

OrderBinary hits in top 5First relevant rankNDCG@5 intuition
31best evidence first, small ordering flaw
32same recall, but best evidence delayed

That is the core reason NDCG is valuable: it can distinguish rankings that retrieve the same documents but order the evidence differently.

Practical use

Use these metrics inside search evaluation slices, not only as one global average. A reranking change may improve NDCG while reducing recall for exact-code queries. A hybrid search change may improve recall while adding low-quality top results, which precision@k will reveal.

NDCG is a good primary metric when users inspect a ranked list and relevance labels have grades: web search, product search, recommendations, document retrieval, and RAG source ranking. It is less informative when only the first correct answer matters; then MRR may match the product better. It also assumes the chosen relevance grades and discount curve reflect user value, so NDCG should be reported at a realistic cutoff such as @5, @10, or @20 rather than only over the full corpus.

References