What Is NDCG (Ranking Quality)?

NDCG (ranking quality)

NDCG, or normalized discounted cumulative gain, measures ranking quality when results can have graded relevance. A highly relevant document ranked first is worth more than the same document ranked tenth, and a partially relevant document still earns partial credit. The score runs from 0 to 1, where 1 means the ranking matched the best ordering possible for those results.

The word “normalized” is what makes NDCG comparable across queries. A query with six excellent matches and one with a single mediocre match produce very different raw scores even from a perfect retriever, and dividing by each query’s best achievable score puts them on the same footing. For search and RAG, where relevance is rarely a yes-or-no call, graded credit plus a positional discount is the closest single number to what you care about.

Try Arize AX

Build better agents with Arize

Trace, evaluate, and learn. Build agents that work with Arize AX and start tracing your runs today.

Prefer open source? Try Arize Phoenix for self-hosted, open source agent observability.

Key takeaways

  • NDCG divides your ranking’s discounted cumulative gain by that of the ideal ranking of the same results, giving a 0 to 1 score.
  • Reach for it when relevance is graded rather than binary, because it is the only common ranking metric that gives partial credit.
  • Its logarithmic discount falls more gently than the reciprocal discount MRR uses, so positions 5 through 10 still move the number.
  • Implementations disagree on the gain formula and on queries with no relevant documents, so two libraries can report different NDCG for one ranking.
  • Changing the logarithm base leaves NDCG unchanged, since DCG and IDCG rescale together. Changing the gain formula does move it.

The three pieces

Gain is the relevance grade of a document, commonly on a 0 to 3 scale: 0 for irrelevant, 3 for exactly what the user wanted. Binary labels are just the 0 to 1 case.

Discount shrinks each position’s contribution as you move down the list. DCG@k is the sum over positions 1 through k of rel_i / log(i + 1).

Normalization divides by the ideal DCG, or IDCG, the DCG you would get if those same documents were sorted best grade first. NDCG@k = DCG@k / IDCG@k.

Everything below uses log base 2, the convention in most information retrieval work and most libraries. Base 2 makes the first discount exactly 1, since log base 2 of 2 is 1. The discounts in the table below are 1 / log2(i + 1), rounded to three decimals. State the base whenever you report raw DCG, though it cancels out of NDCG itself: switching bases scales DCG and IDCG by the same constant and leaves the ratio untouched.

A worked example

Five results for one query, each with a grade from 0 to 3. The right-hand columns sort those same five grades descending to build the ideal ranking.

position discount grade contribution ideal grade ideal contribution
1 1.000 2 2.000 3 3.000
2 0.631 0 0.000 2 1.262
3 0.500 3 1.500 1 0.500
4 0.431 1 0.431 0 0.000
5 0.387 0 0.000 0 0.000

DCG@5 = 2.000 + 1.500 + 0.431 = 3.931

IDCG@5 = 3.000 + 1.262 + 0.500 = 4.762

NDCG@5 = 3.931 / 4.762 = 0.825

The ranking captured about 82.5 percent of the graded value available from these five documents. The loss came from burying the grade-3 document at position 3 while a grade-0 document sat at position 2.

Fix only that. Promote the grade-3 document to the top, giving the order 3, 0, 2, 1, 0. The new DCG is 3.000 + 1.000 + 0.431 = 4.431, and 4.431 / 4.762 = 0.930. One promotion on a still-imperfect list moves the score over ten points.

Details that change the number

The gain formula. The example above uses the grade directly, called linear gain. Many information retrieval papers instead use exponential gain, raising 2 to the power of the grade and subtracting 1, turning grades 0, 1, 2, 3 into gains 0, 1, 3, 7. That sharpens the reward for top-grade documents and yields a different NDCG for the identical ranking. Neither is wrong, but the two are not comparable, so check your library’s default before comparing scores across teams.

Queries with nothing relevant. If every grade is 0, IDCG is 0 and the division is undefined. Some implementations return 0, some return 1, and some drop the query. On a query set with many failures those choices produce visibly different averages, so pick one and document it.

The cutoff. NDCG@5 and NDCG@20 are different metrics. Always report the k.

Where the grades come from

NDCG is only as good as its labels, and graded labels cost more than binary ones because a human has to separate “answers the question” from “related and useful” from “topically adjacent but useless.” That cost pushes many teams to generate grades with a model, which works when the rubric is tight and fails quietly when it is not. Understanding when a judge model is and is not appropriate decides whether your NDCG measures your retriever or your labeler, and where one judge is unstable on borderline grades, aggregating the verdicts of several cuts label variance.

Offline NDCG also drifts from live behavior as the corpus grows. Recomputing it on real traffic requires retrieved document IDs, positions, and grades on the retrieval span, one of the things an agent observability platform captures.

What NDCG does not tell you

It says nothing about recall against the full corpus. IDCG is built from the documents you actually retrieved, so a retriever returning five mediocre documents in perfect order scores 1.0 while the excellent document it never surfaced goes uncounted. Pair NDCG with a recall measure if that matters. It also inherits every bias in the rubric, and a single aggregate hides which slices are failing.

FAQ

What is the full form of NDCG?

Normalized discounted cumulative gain, also written nDCG. Cumulative gain sums relevance, discounting shrinks it by position, normalizing divides by the ideal ordering.

What is the NDCG formula?

DCG@k is the sum over positions 1 through k of the relevance grade divided by the log of the position plus one. IDCG@k is that same sum computed on the ideal ordering of those documents. NDCG@k is the first divided by the second.

What is a good NDCG score?

No threshold transfers between systems, because the score depends on the cutoff, the grading rubric, and the difficulty of the query set. Use it to judge whether a change to chunking, embedding, or reranking improved things on a fixed query set.

How is NDCG used in RAG?

It scores retrieval before generation runs. A RAG pipeline passes only the top few chunks into the context window, so both which chunks return and what order they arrive in shape the answer. NDCG measures both at once, fitting better than binary metrics when some chunks are partially useful.

How does NDCG compare to MRR and Precision@k?

MRR looks only at the position of the first relevant result. Precision@k counts how many of the top k are relevant but ignores their order. NDCG is the only one of the three using graded relevance and accounting for the order of every result inside the cutoff, which is why it also needs the most expensive labels.

Example

Grades 2, 0, 3, 1, 0 give DCG@5 = 3.931. The ideal order 3, 2, 1, 0, 0 gives IDCG@5 = 4.762. NDCG@5 = 3.931 / 4.762 = 0.825, using log base 2.

Don’t ship vibes.

Arize gives AI teams observability and evals to understand and improve agent performance.