Inferensys

Glossary

Normalized Discounted Cumulative Gain (NDCG)

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness, or gain, of a document based on its position in the result list, normalized against an ideal ranking.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
RETRIEVAL EVALUATION METRIC

What is Normalized Discounted Cumulative Gain (NDCG)?

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness, or gain, of a document based on its position in the result list, normalized against an ideal ranking.

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness, or gain, of a document based on its position in the result list, normalized against an ideal ranking. It is the standard metric for evaluating information retrieval and recommendation systems where result relevance is graded (e.g., highly relevant, somewhat relevant, not relevant) rather than binary. NDCG accounts for the fact that users value highly relevant documents more and that documents appearing lower in a ranked list are less likely to be seen, applying a logarithmic discount to their contribution to the overall score.

The calculation involves first computing the Discounted Cumulative Gain (DCG), which sums the graded relevance scores of retrieved documents while penalizing scores based on their rank position. This DCG is then normalized by dividing by the Ideal DCG (IDCG), the maximum possible DCG achieved by a perfect ranking of all relevant documents for that query. This yields a score between 0.0 and 1.0, where 1.0 represents a perfect ranking. NDCG@k, which evaluates only the top k results, is commonly reported to assess the quality of the initial results presented to a user.

RETRIEVAL EVALUATION METRICS

Key Characteristics of NDCG

Normalized Discounted Cumulative Gain (NDCG) is the standard metric for evaluating ranked lists where relevance is graded, not binary. It accounts for both the graded relevance of items and their positions in the ranking.

01

Graded Relevance

Unlike binary metrics (relevant/not relevant), NDCG operates on graded relevance judgments. Documents are assigned relevance scores (e.g., 0=irrelevant, 1=somewhat relevant, 2=relevant, 3=highly relevant). This allows the metric to distinguish between a ranking that returns a 'highly relevant' document first versus one that returns a merely 'relevant' document first, providing a more nuanced assessment of ranking quality.

02

Positional Discounting

NDCG incorporates a logarithmic discount factor that reduces the contribution of a document's relevance score based on its rank. The gain from a document at position p is divided by log₂(1+p). This reflects the user experience principle that results lower on the list are less likely to be examined and therefore provide less utility. A highly relevant document at position 10 contributes significantly less to the total score than the same document at position 1.

03

Cumulative Gain (CG & DCG)

The calculation proceeds in steps:

  • Cumulative Gain (CG): The simple sum of relevance scores for the top-k results. It ignores rank position.
  • Discounted Cumulative Gain (DCG): The sum of relevance scores discounted by their rank: DCG@k = Σ (relevance_i / log₂(1 + i)). DCG is the core measure of a ranking's usefulness. For example, for relevance scores [3, 2, 3, 0, 1] at k=5: DCG@5 = 3/log₂(2) + 2/log₂(3) + 3/log₂(4) + 0 + 1/log₂(6) ≈ 3 + 1.26 + 1.5 + 0 + 0.39 = 6.15
04

Normalization to Ideal DCG

NDCG is DCG normalized by the Ideal DCG (IDCG)—the maximum possible DCG achievable for a given query, obtained by ranking all documents in perfect descending order of relevance. NDCG@k = DCG@k / IDCG@k. This normalization bounds the score between 0.0 and 1.0, where 1.0 represents a perfect ranking. It allows for meaningful comparison across queries with different numbers of relevant documents and varying relevance grade distributions.

05

Interpretation and Typical Values

An NDCG score is always a decimal between 0 and 1.

  • 1.0: Perfect ranking (matches the ideal order).
  • > 0.8: Excellent ranking performance.
  • ~0.6-0.7: Good, competitive performance in many benchmarks.
  • < 0.5: Indicates significant room for improvement in the retrieval or ranking model. Scores are averaged over a large query set to evaluate a system. It is the de facto standard for web search, recommendation systems, and RAG retrieval evaluation where relevance is not binary.
06

Comparison to Binary Metrics

NDCG provides a more sensitive and informative evaluation than binary metrics like Precision@k or Recall@k.

  • Advantage: It rewards systems for correctly placing higher-relevance items at top ranks. A system that swaps a 'score 3' item with a 'score 1' item will see a larger NDCG penalty than a binary metric penalty.
  • Use Case: Essential for evaluating search engines and RAG retrievers where the quality of the top result is critical, and relevance is a spectrum. Binary metrics fail to capture these nuances, making NDCG the preferred choice for modern ranking evaluation.
COMPARISON

NDCG vs. Other Ranking Metrics

A feature-by-feature comparison of Normalized Discounted Cumulative Gain (NDCG) against other common metrics for evaluating ranking and retrieval systems.

Metric / FeatureNDCGPrecision@k / Recall@kMean Average Precision (MAP)Mean Reciprocal Rank (MRR)

Core Purpose

Measures ranking quality with graded relevance and position discounting

Measures binary relevance at a fixed cutoff (k)

Measures average precision across all relevant documents

Measures the rank of the first relevant item

Handles Graded Relevance

Accounts for Result Position

Output Range

0.0 to 1.0 (normalized)

0.0 to 1.0

0.0 to 1.0

0.0 to 1.0

Interpretation

1.0 = ideal ranking

Higher is better

Higher is better

1.0 = first result is always relevant

Sensitivity to Top Rankings

High (via logarithmic discount)

Fixed at cutoff k

High (precision at each relevant doc)

Extremely High (only first rank matters)

Common Use Case

Evaluating web search, recommendation systems

Quick binary checks on top-k results

Academic IR benchmarks, TREC evaluations

Question answering, factoid retrieval

Calculation Complexity

Medium (requires ideal DCG for normalization)

Low

Medium (requires precision at each relevant doc)

Low

RETRIEVAL EVALUATION METRICS

Practical Applications of NDCG

Normalized Discounted Cumulative Gain (NDCG) is a cornerstone metric for evaluating ranking systems where relevance is graded, not binary. Its applications are critical for optimizing real-world search and recommendation engines.

01

Search Engine Ranking

NDCG is the primary metric for evaluating web search engines like Google and Bing, where user satisfaction depends on the order of results. It measures how well the engine surfaces the most useful pages (e.g., highly relevant official documentation vs. tangentially related blog posts) at the top of the list. A high NDCG score correlates with reduced user pagination and higher click-through rates on the first few results.

Top 5
Critical Results
02

E-commerce & Product Recommendations

In e-commerce platforms (e.g., Amazon, Shopify), NDCG evaluates product ranking algorithms. Relevance is graded: a perfect match has high gain, a related accessory has medium gain, and an irrelevant item has zero gain. Optimizing for NDCG directly improves conversion by ensuring the most likely-to-purchase items are presented first, maximizing the discounted cumulative gain from the user's limited attention.

03

RAG Pipeline Evaluation

In Retrieval-Augmented Generation (RAG), NDCG assesses the retriever's ability to rank source document chunks by their utility for answer generation. Chunks are graded by contextual relevance to the query. A high NDCG score indicates the LLM receives the most pertinent context first, which is critical for reducing hallucinations and improving answer faithfulness. It is often used alongside metrics like Answer Relevance and Contextual Precision.

04

Content & Media Streaming

Services like Netflix, Spotify, and YouTube use NDCG to evaluate recommendation systems. Here, relevance is a graded measure of user preference (e.g., 'love,' 'like,' 'dislike'). NDCG quantifies how well the platform's algorithms prioritize content the user is most likely to enjoy, directly impacting engagement metrics like watch time and subscription retention. The discounting factor correctly models the rapid decay in user attention as they scroll.

05

Enterprise Document Retrieval

For internal enterprise search across knowledge bases, intranets, and CRM systems, NDCG evaluates how well employees find critical information. Documents are graded by utility (e.g., exact procedure = high, related policy = medium, outdated memo = low). Optimizing NDCG reduces time-to-information and operational errors by ensuring the most authoritative and directly applicable document appears at the top of internal search results.

06

Benchmarking & A/B Testing

NDCG serves as the gold-standard metric in academic and industrial benchmarks like TREC and BEIR for comparing ranking algorithms. In production A/B tests, engineers track NDCG@5 or NDCG@10 to measure the impact of a new retrieval model, embedding, or query expansion technique. A statistically significant lift in NDCG provides a strong, user-centric signal for deploying a new ranking system to production.

NORMALIZED DISCOUNTED CUMULATIVE GAIN

Frequently Asked Questions

Normalized Discounted Cumulative Gain (NDCG) is a fundamental metric for evaluating the quality of ranked lists in information retrieval and recommendation systems. It assesses how well a system orders items by their relevance, accounting for the fact that highly relevant items are more valuable when they appear at the top of the list.

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness, or gain, of a document based on its position in the result list, normalized against an ideal ranking. Unlike binary metrics like precision and recall, NDCG handles graded relevance judgments (e.g., scores of 0 to 3) and applies a logarithmic discount factor that penalizes relevant items appearing lower in the list. The final score is normalized by the Discounted Cumulative Gain (DCG) of the perfectly ordered list (IDCG), producing a value between 0 and 1, where 1 represents a perfect ranking.

Key Components:

  • Gain: The relevance score of an item at a given rank.
  • Discount: A penalty factor, typically 1 / log2(rank + 1), that reduces the gain for items lower in the list.
  • Cumulative: The sum of discounted gains across the top-k results.
  • Normalized: Division by the ideal DCG (IDCG) to create a scale-independent, comparable metric.
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.