NDCG: Graded Relevance and Discount Geometry
Set metrics treat relevance as a yes-or-no flag; NDCG keeps the degree of a match and the position it lands. We build the discounted cumulative gain over the same three retrieval legs, prove the ideal ranking is optimal by the rearrangement inequality, read the geometry of the logarithmic discount against the rank-biased alternative, and carry the estimator framing straight over — a reported NDCG gap is not a real one until it clears sampling noise, and the gain and discount you chose are conventions that can flip the verdict
From sets to grades
Set metrics scored a ranking against a set of relevant documents: a document is in or it is not. That binary judgment throws away something real. Asked for a company’s interest-rate exposure, a retriever might surface the exact hedging paragraph from a 10-K, a sentence that merely mentions rates in passing, and an off-topic disclosure. The first is perfectly on point, the second marginally so, the third irrelevant — yet precision and recall see only “relevant, relevant, not.” Graded relevance keeps the distinction: each document carries a grade , from irrelevant to perfect.
To keep every number a measurement rather than an illustration, we reuse the prerequisite’s apparatus wholesale — the same shared corpus of documents and queries, the same three real legs (BM25, a pooled dense dual encoder, and late interaction), and the same exact-MaxSim oracle as the neutral ground truth. The one new ingredient is the grade itself.
Definition 1 (Graded relevance from the oracle).
For each query, the oracle’s top- documents (with , the same set the prerequisite called ) are assigned a grade by global tertiles of their exact-MaxSim score: the top third of those scores grade , the middle third grade , the bottom third grade ; every other document grades . Writing for the grade of document on query , the relevant set is recovered exactly as .
That last equality is deliberate: the graded judgments nest the binary ones, so this topic measures the same retrievers against the same documents the set-metric topic did — only now with a degree attached. Across the forty queries the grades come out in balanced thirds (134 at grade 3, 133 at grade 2, 133 at grade 1), so no single grade dominates the signal.
Each bar is a rank's contribution gain(grade)·discount(rank); their sum is DCG, the dashed outline is the ideal ordering (sum IDCG), and the shaded fraction is NDCG = 0.791. Switch to exponential gain: grade-3 jumps from 3 to 7, so a leg that plants the perfect document near the top is rewarded far more than one that spreads marginal hits.
120 synthetic finance documents, 40 queries; relevance is graded by global tertiles of the exact-MaxSim oracle score over the top-10 (so grade ≥ 1 is the binary relevant set). Numbers mirror ndcg_discount_geometry.py; the lab recomputes DCG/IDCG/NDCG, the discount curves, the mean, and the CI in closed form.
The lab above is the topic in miniature; we return to each of its four panels in turn. The arc: attach a gain to each grade and a discount to each rank, sum them into DCG, normalize by the best attainable ordering — then read the geometry of the discount, watch the conventions flip a verdict, and admit that the resulting number is still a noisy estimate.
Gain and discount: the two design choices
A hit is worth something for being relevant and something for being near the top. NDCG multiplies the two: a document of grade at rank contributes . Both factors are design choices, and naming them honestly is half the topic.
Definition 2 (Gain and discount functions).
A gain function maps a grade to a reward. The two standard choices are
Linear gain treats grade as worth twice grade ; exponential gain (the common modern default) makes grade worth and grade worth , sharply rewarding the surfacing of a single perfect document. A discount function down-weights later ranks. The celebrated choice is the logarithmic discount, alongside two comparisons,
each evaluated at the -indexed rank , so rank is undiscounted under .
Neither gain nor discount is forced by any axiom — they are conventions, and the last section shows each one reversing a verdict. The logarithmic discount is the most heuristic of the lot: it is chosen for its slow, heavy-tailed decay, not derived from a model of how anyone reads a result list. The geometric discount, by contrast, comes with a story, which we take up in the discount-geometry panel.
DCG, IDCG, NDCG
With a gain and a discount fixed, the rest is bookkeeping. Let be the ranking, so is the document at rank , with grade .
Definition 3 (Discounted, ideal, and normalized cumulative gain).
The discounted cumulative gain at cutoff is
The ideal DCG is the largest DCG attainable by any ordering of the documents, , obtained by sorting the grades in descending order and discounting in place. The normalized DCG is their ratio,
equal to exactly when the top is an ideal ordering.
Normalization is what makes NDCG comparable across queries: a query with six perfect documents and a query with one have very different DCG ceilings, and dividing by each query’s own IDCG puts both on . Panel A shows the worked query (which has an ideal grade profile ): the bars are each leg’s gains in the order it ranked them, the dashed outline is the ideal, and the shaded fraction is NDCG. That a maximum over orderings is achieved by sorting is the claim the next section proves — it is not a definition we may assert by fiat.
The ideal ranking is optimal: the rearrangement inequality
Why is the normalizer the sorted ranking? Read DCG as an inner product. Fix the multiset of gains a query’s documents carry and stack them in ranked order as a vector ; stack the discounts as , a strictly decreasing sequence. Then , and the question “which ranking maximizes DCG” becomes “which pairing of gains with a fixed decreasing weight vector maximizes the inner product.”
Theorem 1 (The ideal ranking maximizes DCG (rearrangement inequality)).
Let be a strictly decreasing discount vector and let the documents carry gains . Over all orderings, is maximized by placing the gains in descending order (largest gain at rank ) and minimized by ascending order. Hence is exactly the descending-gain ranking, and with equality iff the ranking is ideal on the top .
Proof. Suppose an ordering places gains out of order: some rank has while . Swapping the two documents changes the inner product by
a product of two positive factors, so the swap strictly increases DCG. Any non-descending arrangement therefore admits an improving swap; only the descending arrangement admits none, so it is the unique maximizer (up to ties among equal gains). The same argument with the inequality reversed shows the ascending arrangement is the minimizer.
This is the rigorous spine of the metric: the normalizer is not a convention but a theorem, and it is the elementary rearrangement inequality — pair large with large. The notebook checks it directly, confirming that across the corpus no random permutation of a query’s gains beats the descending order and the ascending order is strictly worst whenever the grades are not all equal.
The construction also pins the implementation. Under linear gain and the logarithmic discount,
here is identical — to better than on every leg, query, and cutoff — to
the ndcg_at_k the BM25 notebook computed long before this
topic existed. The dependent’s metric reduces exactly to the prerequisite’s, which is the byte-for-byte
twin that anchors the code.
Discount geometry
The discount is a fixed measure on rank positions, and its shape — the topic’s namesake — decides what the metric cares about. Two readings make the geometry concrete: how much total weight sits in the head, and how steeply the value of a position falls.
Definition 4 (Head mass and marginal value).
For a discount over positions, the head mass at cutoff is the fraction of total discount weight in the top ,
and the marginal value of rank is , the worth lost in a one-rank demotion.
Over the full positions, the three discounts concentrate their weight very differently in the top ten: the geometric discount () puts of its mass there, the reciprocal discount , and the logarithmic discount only . The log discount has a heavy tail — it keeps caring about documents deep in the list — where the geometric discount is light-tailed, spending almost everything at the top. The marginal value tells the same story locally: every discount loses the most between ranks and and flattens with depth, so a demotion off the top is the most expensive move and a demotion deep down barely registers. That single factor, , is one half of the swap sensitivity that pairwise learning-to-rank methods such as LambdaRank weight their gradients by — the gain side of which we will meet in a later topic.
The geometric discount earns its shape from a model the logarithmic one cannot claim.
Proposition 1 (The rank-biased user model).
Under the geometric discount, model a reader who examines rank and then continues to rank with probability , stopping with probability . The probability of reaching rank is — exactly — and the expected number of documents examined is
At that is documents.
This is the honest contrast the rigor flag insists on: rank-biased precision’s discount is a user model, with a tunable patience and a closed expectation; the logarithmic discount is picked for its heavy tail and its convenient algebra, with no such interpretation. Panel B lets you slide and watch the geometric curve sweep from steep (impatient reader, weight pinned to rank 1) to nearly flat (patient reader), against the fixed logarithmic and reciprocal curves.
NDCG as an estimator
Here the prerequisite’s central lesson carries over without a change of substance. A leg’s mean NDCG is not a property of the retriever; it is the sample mean of forty per-query NDCG values, and a different forty queries would give a different number. Under exponential gain and the log discount the three legs again form a quality ladder — lexical , dense , late interaction — but those are estimates, and estimates have standard errors.
Definition 5 (Mean NDCG as an estimator with standard error).
Treat the per-query scores as a sample with mean and sample standard deviation . The standard error is
and it shrinks like : quadrupling the query count halves the interval.
We reuse the prerequisite’s machinery verbatim — the per-query scores are fed to the same
metric_summary, and the rate is the same
concentration inequality, verified
empirically by resampling. Panel D is the payoff, and it tells two stories. The clearest pair —
lexical versus late interaction, a gap — separates by queries: you can confidently
report a winner. The closest pair — lexical versus dense, a mere gap — has intervals that
overlap across all forty queries and would need roughly to separate. Below that, the honest
report is “indistinguishable on this query set,” not a leaderboard delta.
Convention sensitivity and consistency
Because the gain and the discount are choices, the verdict can move with them — and we build and run the flip before stating it. On this corpus the three legs are a quality ladder under every convention, so there is no aggregate reversal; but the convention reverses the per-query verdict on five leg-pair-and-query instances, and two minimal constructed examples flip it starkly.
Proposition 2 (The convention can reverse the verdict (demonstrated)).
Gain flip. One query with one perfect document () and three marginal ones (). A “headline” ranking puts the perfect document at rank 1 and buries the rest; a “broad” ranking puts the three marginal documents in the top three and the perfect one at rank 4. Under exponential gain the headline ranking wins, versus ; under linear gain the broad ranking wins, versus .
Discount flip. One query with three equally relevant documents. A “top-heavy” ranking lands one at rank 1 and misses the rest within the cutoff; a “deep” ranking lands all three at ranks 2–4. Under a steep geometric discount () the top-heavy ranking wins, versus ; under the heavy-tailed logarithmic discount the deep ranking wins, versus .
In each case neither ranking is “better” in any absolute sense — the metric’s convention decides, and a reported NDCG that does not state its gain and discount is underspecified.
The mechanism is exactly the geometry above. Exponential gain steepens the grade axis, so planting the one perfect document at the top outweighs several marginal ones; a steep discount steepens the rank axis, so a single hit at rank 1 outweighs three hits just below. Choose the convention to match the task — a known-item search wants steep everything, a recall-oriented sweep wants the heavy tail — and report which you chose.
Connections
- the direct prerequisite and the source of every reused part: this topic imports that topic's shared corpus, its three retrieval legs (BM25, dense dual encoder, late interaction), its exact-MaxSim ground truth, and its estimator machinery (standard error, the bootstrap, the projected confidence interval), generalizing binary relevance to graded and precision-at-a-rank to gain-at-a-rank set-metrics-precision-recall-map-mrr
- the lexical leg whose ranking we score, and the source of the twin check: the BM25 notebook already implemented an NDCG with linear gain and the log2 discount, and this topic's NDCG reduces to it exactly when the gain is linear — the byte-for-byte cross-check that anchors the implementation bm25-binary-independence-model
- that topic compared fused rankings by NDCG@10 to argue a hybrid beats either leg; this topic defines that NDCG from first principles — graded gain, the rank discount, normalization by the ideal — so the comparison it relied on is now built rather than borrowed rank-fusion-rrf
References & Further Reading
- paper Cumulated Gain-Based Evaluation of IR Techniques — Järvelin & Kekäläinen (2002) The original (N)DCG: cumulated gain, the logarithmic discount, and normalization by the ideal gain vector — with linear gain as the first convention; ACM TOIS 20(4)
- paper Rank-Biased Precision for Measurement of Retrieval Effectiveness — Moffat & Zobel (2008) The geometric discount p^(i-1) derived from an explicit user model (persistence p, expected documents examined 1/(1-p)) — the clean alternative whose interpretation the log discount lacks; ACM TOIS 27(1)
- paper A Theoretical Analysis of NDCG Type Ranking Measures — Wang, Wang, Li, He & Liu (2013) The consistency result and its limits: NDCG with a smooth gain is consistent for the full list, but truncated NDCG@k can be inconsistent — the honest caveat on the cutoff; COLT 2013 (PMLR v30)
- book Introduction to Information Retrieval — Manning, Raghavan & Schütze (2008) Chapter 8: graded relevance, discounted cumulative gain, and normalized DCG, with the exponential gain 2^g - 1 and the log discount as the standard learning-to-rank convention