intermediate retrieval-evaluation 26 min read

Set Metrics: Precision, Recall, MAP, and MRR as Estimators

The published stack measured recall@k everywhere and never defined it; here the whole set-metric family is defined over real rankings — precision and recall at a cutoff, the precision–recall curve and Average Precision as the area beneath it, MAP and MRR — and then reframed as what they actually are: sample means with standard error, so a reported gap is not a real one until it clears sampling noise

Overview & motivation

The retrieval problem ended with a ranking: a query qq, a score rel(q,d)\mathrm{rel}(q, d) on every document dd, and the top-kk returned as a set. Everything the curriculum built afterward — BM25, dense dual encoders, IVF and product quantization, late interaction served by PLAID, reciprocal-rank fusion — was judged by a single recurring number, recall@k. The capstone reported it a dozen times. Not once did we say what it means.

That is the gap this topic closes. An evaluation metric is a functional that takes a ranking and a set of relevance judgments and returns a number. Write the judgments as a qrel set RqDR_q \subseteq \mathcal{D}: the documents a competent analyst would mark relevant to query qq. Because we want every number on this page to be a measurement rather than an illustration, we do not invent rankings — we score three real retrievers over a shared finance corpus. The lexical leg is BM25, the dense leg is a pooled dual encoder, and the strongest leg is late interaction, each producing a full ranking of N=120N = 120 documents for each of Q=40Q = 40 queries. The relevance judgments are the top-kk documents under exact MaxSim, a neutral oracle: no single leg is the ground truth, so the three genuinely differ in quality, and “relevance” is a fixed target they all approximate.

510152025k = 5rank 1 → (worked query 24); ▮ TP relevant&retrieved · ▯ FP retrieved · ▯ FN missed-relevant
relevant in top-5
5 / 10
precision@k = TP/k
1.000
recall@k = TP/|R|
0.500
F1@k
0.667

Slide k right: recall never falls (each new relevant doc can only add coverage), while precision wobbles — it jumps up when slot k is relevant and decays when it is not. Recall reaches 1.0 once all 10 relevant docs are passed; precision at that point is only 10/(last relevant rank).

120 synthetic finance documents, 40 queries; relevance is the top-10 exact-MaxSim neighbor set (a neutral oracle). Numbers mirror set_metrics_precision_recall_map_mrr.py; the lab recomputes precision, recall, the PR/AP area, the mean, and the CI in closed form.

The lab above is the topic in miniature, and we will return to each of its four panels in turn. The arc is short: define the metrics on one ranking, integrate them into a curve, average them across queries — and then admit that every resulting number is a noisy estimate.

Set metrics at a cutoff: precision and recall

Fix a query and a cutoff kk. Of the top kk documents the system returned, write TPk=topk(q)Rq\mathrm{TP}_k = |\,\mathrm{top}_k(q) \cap R_q\,| for the number that are relevant (true positives). The two foundational metrics divide this count two ways.

Definition 1 (Precision and recall at a cutoff).

For a ranking with qrel set RR (with R>0|R| > 0) and a cutoff k1k \ge 1,

P@k  =  topkRk,R@k  =  topkRR.P@k \;=\; \frac{|\,\mathrm{top}_k \cap R\,|}{k}, \qquad R@k \;=\; \frac{|\,\mathrm{top}_k \cap R\,|}{|R|}.

Precision is the purity of the cutoff — what fraction of what you returned is relevant — and recall is the coverage of the relevant set — what fraction of what you should have returned you did. Their harmonic mean is the F1F_1 score, F1@k=2P@kR@k/(P@k+R@k)F_1@k = 2\,P@k\,R@k / (P@k + R@k).

The denominator of recall is R|R|, the size of the relevant set. This is the textbook convention, and it is worth a word because it differs from the one the capstone used: there, recall divided by min(k,R)\min(k, |R|), a cascade-retention reading (“of the kk slots, how many true neighbors survived”). The two agree exactly at k=Rk = |R|, the capstone’s only operating point, so this topic defines precisely the recall@10 the capstone reported; the R|R| form is what generalizes the curve, because it makes the next proposition true.

Proposition 1 (Recall climbs, precision wobbles).

As the cutoff kk increases, R@kR@k is non-decreasing, and R@N=1R@N = 1. Precision P@kP@k is not monotone.

Proof. The set topk+1\mathrm{top}_{k+1} contains topk\mathrm{top}_k, so TPk\mathrm{TP}_k is non-decreasing in kk; dividing by the constant R|R| preserves this. At k=Nk = N every document is returned, so TPN=R\mathrm{TP}_N = |R| and R@N=1R@N = 1. For precision, TPk\mathrm{TP}_k rises by one exactly when document k+1k{+}1 is relevant, while the denominator kk rises by one every step; so P@(k+1)P@(k{+}1) exceeds P@kP@k when the new document is relevant and falls when it is not. \square

Panel A makes the asymmetry tactile. Drag the cutoff across the worked query’s ranking: each slot is a true positive (relevant and retrieved), a false positive (retrieved, not relevant), or — beyond the cutoff — a false negative (relevant, missed). Recall only ever rises as the line moves right; precision jumps up on a relevant slot and decays on an irrelevant one. A single (P@k,R@k)(P@k, R@k) pair is a point on a plane; the whole topic is what happens when we let kk run.

The precision–recall curve and Average Precision

Sweeping kk from 11 to NN traces a path in the precision–recall plane. Because recall only changes when a relevant document is hit, the informative points are exactly those hits. Let the relevant documents sit at ranks pos1<pos2<<posm\mathrm{pos}_1 < \mathrm{pos}_2 < \dots < \mathrm{pos}_m (with m=Rm = |R|); at the ii-th hit, recall is Ri=i/mR_i = i/m and precision is Pi=i/posiP_i = i/\mathrm{pos}_i. Connecting these corners gives the familiar sawtooth — and the single most useful summary of a ranking is the area beneath it.

Theorem 1 (Average Precision is the area under the PR curve).

Define Average Precision as the mean of precision at the relevant ranks,

AP  =  1Ri=1mPi  =  1Ri=1miposi.\mathrm{AP} \;=\; \frac{1}{|R|}\sum_{i=1}^{m} P_i \;=\; \frac{1}{|R|}\sum_{i=1}^{m} \frac{i}{\mathrm{pos}_i}.

Then AP\mathrm{AP} equals the area under the (raw) precision–recall curve,

AP  =  i=1m(RiRi1)Pi,R0=0.\mathrm{AP} \;=\; \sum_{i=1}^{m} (R_i - R_{i-1})\,P_i, \qquad R_0 = 0.

Proof. At rank posi\mathrm{pos}_i exactly ii relevant documents have been retrieved, so recall steps from (i1)/m(i{-}1)/m to i/mi/m — an increment RiRi1=1/mR_i - R_{i-1} = 1/m — and precision there is PiP_i. Between consecutive relevant ranks recall is constant, so those stretches add nothing to a recall-integrated sum. Hence i(RiRi1)Pi=i1mPi=1miPi=AP\sum_i (R_i - R_{i-1}) P_i = \sum_i \tfrac{1}{m} P_i = \tfrac{1}{m}\sum_i P_i = \mathrm{AP}. \square

This is a Riemann sum over the recall axis: the relevant documents partition [0,1][0,1] into mm equal increments of width 1/m1/m, and AP is the sum of precision times those widths — the area-as-a-limit-of-sums construction applied to a step function. The proof also explains the denominator R|R| rather than “number of documents retrieved”: a relevant document that never surfaces contributes a missing 1/m1/m recall step, i.e. a term of zero, which correctly drags AP down. Dividing by the count actually found would give a ranking that retrieves one of ten relevant documents (at rank 1) an AP of 1.01.0 — exactly wrong.

Panel B draws this. The shaded bars are the recall steps; their total area is AP. Toggle the interpolated envelope and a second, larger area appears.

Mean Average Precision

A single query’s AP is a property of one ranking. To score a system we average over a query set.

Definition 2 (Mean Average Precision).

For a set of QQ queries, MAP=1Qq=1QAPq\displaystyle \mathrm{MAP} = \frac{1}{Q}\sum_{q=1}^{Q} \mathrm{AP}_q, the sample mean of per-query Average Precision.

Over our three legs the MAP values are a clean quality ladder: lexical 0.6190.619, dense 0.7350.735, late interaction 0.8740.874. Panel C shows why an average is the right summary — the per-query AP scatter widely (the late-interaction leg ranges from below 0.60.6 to a perfect 1.01.0), and only their mean is stable. That scatter is not noise to be ignored; it is the metric’s variance, and we return to it.

Reciprocal rank and known-item retrieval

Some queries have one right answer — the filing that announced a merger, the slide that stated a guidance number. There, what matters is not coverage of a set but how high the one answer ranks.

Definition 3 (Reciprocal rank and MRR).

The reciprocal rank of a query is RR=1/rank1\mathrm{RR} = 1/\mathrm{rank}_1, where rank1\mathrm{rank}_1 is the rank of the first relevant document (and RR=0\mathrm{RR} = 0 if none appears). The Mean Reciprocal Rank is MRR=1Qq=1QRRq\displaystyle \mathrm{MRR} = \frac{1}{Q}\sum_{q=1}^{Q}\mathrm{RR}_q.

MRR is built for the known-item regime, where each query has exactly one relevant document — and there it is not a different animal from AP at all.

Proposition 2 (MAP equals MRR in the known-item regime).

If every query has exactly one relevant document (Rq=1|R_q| = 1 for all qq), then APq=RRq\mathrm{AP}_q = \mathrm{RR}_q for every query, and hence MAP=MRR\mathrm{MAP} = \mathrm{MRR}.

Proof. With m=1m = 1, the single relevant document sits at some rank rqr_q. Average Precision has one term: APq=111rq=1/rq\mathrm{AP}_q = \tfrac{1}{1}\cdot\tfrac{1}{r_q} = 1/r_q. The first (and only) relevant document is at rank rqr_q, so RRq=1/rq\mathrm{RR}_q = 1/r_q too. The per-query metrics coincide, and so do their means. \square

This is the topic’s collapse anchor: at R=1|R| = 1 the whole apparatus of precision, recall, and the PR curve degenerates to a single reciprocal rank. Panel C makes it visible — switch to the known-item regime and the per-query AP strip lands exactly on the reciprocal-rank strip, mean line and all. Because MRR is degenerate when relevant sets are large (with ten relevant documents some leg almost always lands one near the top, so reciprocal rank says little), we score it in the regime it was built for: relevance is the single top-1 oracle document.

Holding both metrics in view exposes something the quality ladder hid. The MAP ranking is lexical << dense << late interaction; the MRR ranking is dense << lexical << late interaction.

Proposition 3 (Metric choice can reverse the verdict (demonstrated)).

On this corpus, dense beats lexical on MAP (0.7350.735 vs 0.6190.619) but lexical beats dense on MRR (0.5220.522 vs 0.4720.472). The verdict between two systems reverses depending on the metric.

The mechanism is structural: MAP rewards ranking the whole relevant set high, and the dense leg does that better on average; MRR rewards getting one relevant document to the very top, and the lexical leg’s exact-match behavior more often plants a relevant document at rank 1. This is a demonstrated proposition on one corpus, not a theorem — but it is built and run before it is stated, and it makes the lesson concrete: “system A is better” is meaningless without naming the metric.

Metrics as estimators

Here is the move the rest of the evaluation layer rests on. A MAP of 0.7350.735 is not a property of the dense retriever; it is the sample mean of forty per-query AP values, and a different forty queries would give a different number. Every metric on this page is an estimator of an unknown population quantity, and estimators have variance.

Definition 4 (MAP as an estimator with standard error).

Treat the per-query Average Precisions AP1,,APQ\mathrm{AP}_1, \dots, \mathrm{AP}_Q as a sample with mean MAP^\widehat{\mathrm{MAP}} and sample standard deviation σ^\hat\sigma. The standard error of the MAP estimate is

SE^=σ^Q,95% CI=MAP^±1.96SE^,\widehat{\mathrm{SE}} = \frac{\hat\sigma}{\sqrt{Q}}, \qquad \text{95\% CI} = \widehat{\mathrm{MAP}} \pm 1.96\,\widehat{\mathrm{SE}},

and the standard error shrinks like 1/Q1/\sqrt{Q}: quadrupling the query count halves the interval.

That 1/n1/\sqrt{n} rate is not a heuristic; it is a concentration inequality. The per-query AP are bounded in [0,1][0,1], so Chebyshev’s inequality already gives a confidence interval from the variance alone, and the sub-Gaussian (Hoeffding) bound sharpens it — the sample mean concentrates around its expectation at a rate controlled by the query count. The companion notebook verifies the rate empirically: resampling the per-query AP at growing nn, the measured standard error tracks σ^/n\hat\sigma/\sqrt{n}, and SE^n\widehat{\mathrm{SE}}\cdot\sqrt{n} holds essentially constant.

Panel D is the payoff. It plots two legs — dense and late interaction — with their 95% intervals, and a slider for the query count nn. The gap in MAP is real (0.1390.139), but at few queries the intervals overlap: you cannot tell the systems apart. They separate only at n=12n = 12. Below that, the honest report is “indistinguishable on this query set,” not “late interaction wins.”

Connections

  • that topic established retrieval as ranking by a relevance functional and returned a top-k set; this one defines how to SCORE that returned set against relevance judgments, turning the qualitative 'return the relevant documents' into the precision, recall, AP, MAP, and MRR the rest of the evaluation layer is built on the-retrieval-problem
  • the lexical leg whose ranking we score: BM25 over the quantized token vocabulary is one of the three real retrievers whose precision–recall curves, AP, and MAP this topic measures against the shared ground truth bm25-binary-independence-model
  • the dense MIPS leg whose ranking we score: its pooled-vector dual-encoder scores produce one of the three real rankings, and it is half of the dense-versus-late-interaction comparison whose confidence intervals overlap until twelve queries dense-retrieval-dual-encoders
  • the late-interaction leg whose ranking we score: its MaxSim signal (served centroid-style) is the strongest of the three legs by MAP, and the exact-MaxSim version of it is the neutral oracle that defines relevance here late-interaction-learned-sparse
  • the capstone measured recall@k a dozen times without ever defining it; this topic defines exactly that recall@k (and its whole family) over the same legs, corpus, and exact-MaxSim ground truth, so it retroactively grounds every recall number the capstone reported capstone-multimodal-financial-rag

References & Further Reading

  • book Introduction to Information Retrieval — Manning, Raghavan & Schütze (2008) Chapter 8: evaluation in information retrieval — precision, recall, the precision–recall curve, interpolated precision, MAP, and the eleven-point interpolated average precision
  • paper Evaluating Evaluation Measure Stability — Buckley & Voorhees (2000) The empirical case that retrieval metrics are noisy estimators: how many queries (and what error rate) it takes before a measured difference between two systems is reliable — the motivation for treating MAP as an estimate with variance; SIGIR 2000
  • book Test Collection Based Evaluation of Information Retrieval Systems — Sanderson (2010) A survey of the Cranfield evaluation paradigm: qrels, pooling, the metric family, and the reliability and significance of measured differences; Foundations and Trends in Information Retrieval 4(4)
  • book An Introduction to the Bootstrap — Efron & Tibshirani (1994) The resampling estimate of a statistic's standard error and confidence interval used here to cross-check the analytic SE = std/sqrt(n) of MAP, since the per-query AP are bounded and skewed
  • documentation ir_measures — a single interface to the IR evaluation measure zoo — MacAvaney et al. Documentation for the conventions behind AP, MAP, MRR, and the interpolation variants — concrete evidence that 'AP' names a family of conventions, not one number