Inferensys

Glossary

Normalized Discounted Cumulative Gain (NDCG)

A listwise ranking evaluation metric that measures ranking quality by discounting relevance gains logarithmically by position and normalizing against an ideal ranking.
AI evaluator reviewing output quality on laptop, comparison metrics visible, casual evaluation session.
RANKING EVALUATION METRIC

What is Normalized Discounted Cumulative Gain (NDCG)?

Normalized Discounted Cumulative Gain (NDCG) is a listwise ranking evaluation metric that measures the quality of a ranked list by discounting relevance gains logarithmically by position and normalizing the score against an ideal ranking.

Normalized Discounted Cumulative Gain (NDCG) is a listwise ranking evaluation metric that quantifies ranking quality by comparing a system's ranked output to an ideal ordering. It operates on graded relevance judgments, where documents are assigned multi-level relevance scores rather than binary labels. The metric computes Cumulative Gain (CG) by summing relevance scores across positions, then applies a logarithmic discount to penalize relevant documents appearing lower in the ranking. This discounted cumulative gain is normalized by dividing by the Ideal DCG (IDCG)—the maximum possible DCG achievable by perfectly ordering documents—producing a score between 0 and 1.

NDCG is the standard evaluation metric for learning-to-rank (LTR) systems, including algorithms like LambdaMART which directly optimize for NDCG using gradient-based methods. The metric's logarithmic discount function reflects user behavior models where searchers are exponentially less likely to examine lower-ranked results. Variants include NDCG@k, which truncates evaluation at rank position k to emphasize top-ranked precision, making it particularly relevant for modern retrieval-augmented generation pipelines where only the highest-scoring documents are passed to the generation phase.

RANKING EVALUATION

Key Characteristics of NDCG

Normalized Discounted Cumulative Gain (NDCG) is a listwise metric that evaluates ranking quality by accounting for both the relevance of documents and their positions in the ranked list. It applies a logarithmic discount to penalize relevant documents appearing lower in the ranking and normalizes the score against an ideal ordering.

01

Position-Aware Discounting

NDCG applies a logarithmic discount to relevance gains based on rank position. The gain for a document at position p is divided by log₂(p+1). This models user behavior where searchers are exponentially less likely to examine documents deeper in the list. A highly relevant document at rank 1 contributes full value, while the same document at rank 10 contributes roughly 30% of its original gain. This discounting mechanism makes NDCG more realistic than precision-based metrics that treat all positions equally.

02

Graded Relevance Judgments

Unlike binary relevance metrics, NDCG supports multi-level graded relevance scores. Relevance judgments can be assigned on an ordinal scale—such as 0 (irrelevant), 1 (tangentially relevant), 2 (relevant), 3 (highly relevant), and 4 (perfectly relevant). This granularity allows evaluators to distinguish between marginally useful documents and authoritative sources. The cumulative gain at each rank position sums these graded scores, enabling nuanced evaluation that rewards search systems for surfacing the most authoritative content at the top.

03

Ideal DCG Normalization

The 'N' in NDCG comes from dividing the achieved Discounted Cumulative Gain (DCG) by the Ideal DCG (IDCG)—the DCG of a perfect ranking where documents are sorted in descending order of relevance. This normalization produces a score between 0 and 1, making NDCG comparable across queries with different numbers of relevant documents. A score of 1.0 indicates the system returned the optimal ordering. Without normalization, DCG scores would be query-length dependent and impossible to average across a test set.

04

Cutoff-Based Variants

NDCG is commonly reported at specific rank cutoffs, denoted as NDCG@k where k represents the truncation depth. Common variants include:

  • NDCG@5: Evaluates the top 5 results, emphasizing above-the-fold performance
  • NDCG@10: Standard cutoff for web search evaluation, representing the first page of results
  • NDCG@20: Used when recall-oriented evaluation is needed Choosing the appropriate k depends on the use case—question-answering systems may prioritize NDCG@1, while exploratory search interfaces benefit from higher cutoffs.
05

Exponential Gain Formulation

To emphasize highly relevant documents, NDCG often uses an exponential gain function: gain = 2^rel - 1, where rel is the graded relevance score. This formulation creates a non-linear reward structure where a document with relevance 4 contributes gain of 15, while relevance 2 contributes only 3. The exponential scaling ensures that search systems are strongly incentivized to place the most authoritative documents at the top, rather than being satisfied with moderately relevant results in prominent positions.

06

Comparison with MRR and MAP

NDCG differs from other ranking metrics in key ways:

  • MRR (Mean Reciprocal Rank): Only considers the position of the first relevant document, ignoring subsequent results and graded relevance
  • MAP (Mean Average Precision): Uses binary relevance and weights precision equally across positions without logarithmic discounting
  • NDCG: Combines graded relevance, position discounting, and ideal normalization, making it the preferred metric when relevance judgments exist on a multi-level scale and ranking order matters throughout the entire list
METRIC COMPARISON

NDCG vs. Other Ranking Metrics

A comparative analysis of NDCG against other common evaluation metrics used to measure ranking quality in information retrieval and recommendation systems.

FeatureNDCGMRRPrecision@KMAP

Metric Type

Listwise (graded)

Pointwise (binary)

Pointwise (binary)

Listwise (binary)

Handles Graded Relevance

Position-Aware

Normalized Across Queries

Sensitive to Total Relevant Docs

Penalizes Low-Ranked Relevant Docs

Ideal for Multi-Level Judgments

Computational Complexity

O(n log n)

O(n)

O(n)

O(n log n)

NDCG EXPLAINED

Frequently Asked Questions

Clear, technically precise answers to the most common questions about Normalized Discounted Cumulative Gain, the gold-standard metric for evaluating ranking quality in search and recommendation systems.

Normalized Discounted Cumulative Gain (NDCG) is a listwise ranking evaluation metric that measures the quality of a ranked list by comparing it against an ideal ordering. It works by first computing the Discounted Cumulative Gain (DCG), which sums the graded relevance scores of documents in a result list, applying a logarithmic discount factor that penalizes relevant documents appearing lower in the ranking. This DCG value is then normalized by dividing it by the Ideal DCG (IDCG)—the DCG of the perfectly ordered list for that query. The resulting NDCG score ranges from 0.0 to 1.0, where 1.0 represents a perfect ranking. Unlike precision-based metrics, NDCG captures the nuanced reality that some documents are more relevant than others and that users strongly prefer highly relevant results at the top of the list.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.