The useful part, up front

What you’ll take away

  • NDCG needs a declared relevance-to-gain mapping, rank discount, cutoff and ideal population.
  • Our fixed top-three comparison favors X with direct grades and Y with exponential gains.
  • Normalizing to an ideal does not remove differences in the relative credit given to relevance grades.
  • A score of one within a candidate-only population is a different claim from a full-universe retrieval result.
  • Tie expectations, realized orders, zero-ideal conventions and missing judgments need explicit treatment.
  • A ranking score assesses the supplied judgments and order; it does not certify source truth or a generated answer.
01

The same result lists can receive different NDCG comparisons

Two retrieval reports compare exactly the same ranked documents. One says list X is better; the other says list Y is better. Before looking for a changed model, check what the reports mean by a good result. A graded ranking metric needs a rule that turns relevance labels into numerical credit, as well as a rule for discounting lower positions.

Normalized discounted cumulative gain, usually shortened to NDCG, combines those choices with a comparison against an ideal ranking. The scikit-learn documentation describes summing relevance scores in predicted order and dividing by the best possible discounted score. TensorFlow Ranking exposes separate gain and rank-discount functions [1][2]. The name alone does not supply every setting.

Our original example uses four imaginary documents and two fixed orders. With one gain rule, X wins. With another, Y wins. No search system, model or human assessment was run: all labels and rankings are stipulated. The calculation explains what must accompany a retrieval score before it can support a comparison.

Fix one four-document universe before comparing the lists. Original full rankings X = B,C,A,D and Y = A,D,B,C. The main calculation scores the first three positions; all four documents have stipulated grades.
Original full rankings X = B,C,A,D and Y = A,D,B,C. The main calculation scores the first three positions; all four documents have stipulated grades. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
02

Fix the documents, grades and two result orders first

Give document A relevance grade three, B grade two, C grade two and D grade zero. Think of zero as irrelevant to the stated need, two as useful and three as very useful. These descriptions explain our invented scale; they are not observations about real documents. Grade one is allowed by the scale but does not occur in this four-document collection.

List X orders the documents B, C, A, D. List Y orders them A, D, B, C. Both complete lists contain the same four identities exactly once. At a cutoff of three, X shows B, C and A, while Y shows A, D and B. The cutoff matters because C falls outside Y's scored portion.

Elastic's ranking-evaluation guide associates document ratings with each particular query and the user's information need [3]. A grade therefore belongs to a defined judgment task. Our fixed labels let us compare the arithmetic while avoiding any claim that an assessor actually preferred these documents or that this scale measures a user's satisfaction.

03

Turn grades into credit, then discount each position

A gain rule says how much credit a relevance grade earns before position is considered. Our first rule uses the grade directly: zero earns zero, one earns one, two earns two and three earns three. A rank discount then gives less weight to the same gain when it appears farther down the list.

Use the discount “one divided by log base two of rank plus one.” At rank one its value is one; at rank two it is about 0.63093; at rank three it is one-half. Multiply each document's gain by its position's discount, then add the contributions. That total is our discounted cumulative gain, or DCG.

Finally, divide by the highest DCG possible for the same judged collection, gain rule and cutoff. This produces our NDCG when the ideal value is positive. The documented metric separates these roles [1][2]. Our displayed numbers follow the stated formula, rather than an assumption that any software setting with the same name must reproduce them.

04

Using the grades directly gives X the higher score

For list X, the first three grades are two, two and three. Their discounted contributions are 2, about 1.26186 and 1.5. Add them to get a DCG of approximately 4.76186. List Y begins with grades three, zero and two, giving contributions 3, 0 and 1. Its DCG is exactly 4.

The ideal top three place A first, then B and C. Their grades are three, two and two, so ideal DCG is 3 plus about 1.26186 plus 1, or 5.26186. Dividing both list totals by this same ideal gives X approximately 0.90498 and Y approximately 0.76019. Under this declared rule, X ranks higher.

The result gives credit to X's two useful early documents as well as its very useful document in third place. Y places the highest-grade document first but spends second place on a zero-grade item. This explanation follows from our chosen gain and discount values. It is not a measured preference or a universal reason to favor one result pattern.

Two gain rules give different relative credit to the same grades. Original comparison of explicitly chosen functions. Both use the same rank discounts and cutoff; no library default or runtime result is assumed.
Original comparison of explicitly chosen functions. Both use the same rank discounts and cutoff; no library default or runtime result is assumed. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
05

A different gain rule reverses the comparison

Now keep every grade, document and position unchanged, but give each grade the gain “two raised to that grade, minus one.” Grades zero, one, two and three become gains zero, one, three and seven. TensorFlow documents this function as an option for defining NDCG gain [4]. We are choosing it explicitly, not claiming that every NDCG implementation uses it.

X's first three gains are now 3, 3 and 7. Its DCG becomes 3 plus about 1.89279 plus 3.5, or 8.39279. Y's gains are 7, 0 and 3, giving 7 plus 0 plus 1.5, or 8.5. The ideal gains are 7, 3 and 3, producing ideal DCG of about 10.39279.

After normalization, X scores approximately 0.80756 and Y approximately 0.81787. Y now leads. Nothing was retrieved again and no label was corrected. The change comes entirely from a rule that gives the highest grade substantially more credit relative to the next grade.

06

Dividing by an ideal does not remove the gain choice

It is tempting to expect normalization to make the two gain rules interchangeable. It does make each ideal ranking score one. But each rule defines its own ideal and its own tradeoff between grades. It does not make the credit for a grade-three item mean the same thing under both rules.

With direct grades, grade three earns one-and-a-half times the gain of grade two: three divided by two. With the second rule, it earns seven-thirds as much, about 2.333 times. Those relative values change how much a first-place A can compensate for other positions. Multiplying the old gains by one fixed number could not create this change in their ratio.

For each rule, X and Y share one positive ideal denominator. Dividing by that common value preserves whichever list already has the higher DCG. The normalization does not undo the changed preference built into the gains. If labels are only zero and one, however, both gain rules give the same values. A binary example would miss the difference exposed by our grades two and three. Include genuinely graded cases when checking a graded metric.

07

Changing ordering-score units need not change the metric

The numbers used to order results are different from the relevance grades used to evaluate them. Imagine assigning ordering scores 40, 30, 20 and 10 to the documents in X's order. Replace each ordering score with ten times its old value plus seven. The numbers change, but their descending order remains B, C, A, D.

Our NDCG uses that order and the fixed relevance grades. It therefore stays the same. A larger uncalibrated ordering score is not automatically a larger gain in this evaluation. Scikit-learn's interface distinguishes the true relevance values from the predicted scores that induce the ordering [1]. Confusing those two inputs would change the question being measured.

There is another cancellation in our exact formula: changing the logarithm base consistently in both DCG and ideal DCG multiplies all discounts by one common factor. The normalized ratio is unchanged. Neither cancellation applies to changing which documents are returned, their positions, their grades or the relative gain assigned to different grades.

The winner changes at the same cutoff of three. Original calculations with discount 1/log2(rank+1) and the same fully judged universe. Decimal results are rounded; full values are retained.
Original calculations with discount 1/log2(rank+1) and the same fully judged universe. Decimal results are rounded; full values are retained. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
08

A perfect ranking within one candidate is a different claim

Suppose a retrieval stage returns only B. At cutoff one, B earns gain two under the direct-grade rule. Relative to our full judged collection, the ideal first document is A with gain three, so the score is two-thirds. Under the second gain rule, B earns three and A earns seven, giving three-sevenths.

Now redefine the evaluation population to contain only the returned B. B is necessarily the best item in that one-item set. Dividing by that smaller set's ideal produces one under either rule. The returned document has not improved. The denominator now answers a narrower question.

A candidate-only measure can be useful for examining ordering within an already chosen pool. It should not be presented as the same full-collection retrieval result. Our example has complete ratings for all four documents, making the missing A visible in the first denominator. Keep the evaluated population beside the score so a perfect conditional ranking is not mistaken for complete retrieval success.

09

The cutoff belongs in both the total and the ideal

The symbol “at three” means that only the first three returned positions contribute. It does not mean that the ideal can use four positions or that every result shown elsewhere on a page was evaluated. The scikit-learn documentation explicitly describes a cutoff and an ideal normalization that takes that cutoff into account [1].

Extend our direct-grade calculation to cutoff four. X adds D, whose gain is zero, so its score remains about 0.90498. Y adds C at rank four. Its extra contribution is two divided by log base two of five, about 0.86135. Y's DCG becomes about 4.86135 and its NDCG about 0.92389. The ideal is unchanged because its fourth item is zero-grade D.

Y therefore overtakes X under the direct-grade rule at this larger cutoff. This is a separate change from the earlier gain-rule comparison, which held the cutoff fixed at three. Record one change at a time so a gain choice and a result-depth choice do not become indistinguishable explanations for a new score.

A perfect candidate-only score answers a narrower question. Original separate case: only B is returned at cutoff one. Its gain is 2 under the direct rule and 3 under the exponential rule; only the ideal population changes.
Original separate case: only B is returned at cutoff one. Its gain is 2 under the direct rule and 3 under the exponential rule; only the ideal population changes. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
10

A tie at the cutoff needs a stated treatment

Create a separate ordering-score example in which A and B tie for first place, with C and D below them. Keep cutoff one. If A is selected first, the direct-grade normalized score is one. If B is selected first, it is two-thirds. The labels and tied scores alone do not choose between those displayed outcomes.

Under our explicitly chosen fair two-way tie experiment, average the two possible results. The expected direct-grade value is five-sixths, about 0.83333. With the exponential gain, the alternatives are one and three-sevenths, giving an expectation of five-sevenths, about 0.71429. These are calculated expectations, not observed randomized library runs.

Tie policy is a real interface distinction: scikit-learn documents averaging ties by default and warns about ignoring ties when they exist, while TensorFlow's metric description says score ties are broken randomly [1][2]. Preserve the actual policy used in a report. One realized order and an average across possible orders are different reported quantities.

11

Zero relevance and missing judgments are different states

Imagine a new judgment task in which every document has grade zero. Both our gain rules then give DCG zero and ideal DCG zero. The raw ratio is zero divided by zero, which is undefined. A reporting system needs an explicit convention for this case, such as a documented value or an eligibility rule; this article does not assign one convention to every implementation.

That differs from returning no documents for our original positive-grade collection. Under our defined empty-sum rule, the numerator is zero but the ideal remains positive, so the normalized value is zero. An empty result and an all-zero judgment universe therefore reach different mathematical situations.

An unrated document is different again. It has no established grade in the record. Our four-document calculation avoids that issue by stipulating every label. In a real evaluation, record how missing judgments are handled rather than silently relabeling “unknown” as “irrelevant.” Also preserve the allowed grade range; negative values can break the usual normalized range described by the API [1].

12

Keep the definition close enough to reconstruct the score

A useful report names the information need, document identities, relevance grades, result order, gain rule, rank discount, cutoff, ideal population and tie treatment. If it combines several queries, it should also identify their weights and any excluded cases. Elastic's documentation keeps query-specific ratings and per-query results visible [3]; a single average cannot replace those underlying records.

Our main result is now reproducible. At cutoff three, direct grades give X about 0.90498 and Y about 0.76019. The exponential gain gives X about 0.80756 and Y about 0.81787. Both comparisons follow their declared definitions. The disagreement identifies a changed preference in the metric, not a changed retrieval run.

NDCG still evaluates ordering relative to the supplied judgments. It does not prove that a source is accurate, that a passage contains every necessary qualification, or that a generated answer uses the evidence correctly. Those questions need their own checks. Preserve the metric's useful, specific conclusion without stretching it into a complete assessment of a RAG application.

A tied first position has outcomes as well as an average. Original fair two-way tie experiment for A and B at cutoff one, with C and D below them. These are analytic values, not randomized library observations.
Original fair two-way tie experiment for A and B at cutoff one, with C and D below them. These are analytic values, not randomized library observations. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
Follow the evidence

Sources & further reading

Explore the references behind this guide. External pages may change after our review.

  1. ndcg_score — scikit-learn 1.9.1 documentation
    scikit-learn · Accessed 7 Nov 2026
  2. tfr.keras.metrics.NDCGMetric | TensorFlow Ranking
    TensorFlow · Accessed 7 Nov 2026
  3. Ranking evaluation
    Elastic · Accessed 7 Nov 2026
  4. tfr.keras.utils.pow_minus_1 | TensorFlow Ranking
    TensorFlow · Accessed 7 Nov 2026

Article updated 7 Nov 2026.

Found something we should revisit?

Good explanations get better with thoughtful feedback.

Suggest a correction