Inferensys

Glossary

Normalized Discounted Cumulative Gain (NDCG)

Normalized Discounted Cumulative Gain (NDCG) is a ranking metric that evaluates the quality of a search result list by considering both the relevance of each item and its position, with higher relevance scores receiving more weight when they appear earlier in the list.
Developer reviewing semantic search engine results on laptop, relevance scores visible, technical search demo.
RETRIEVAL EVALUATION METRICS

What is Normalized Discounted Cumulative Gain (NDCG)?

A core metric for evaluating the quality of ranked lists in information retrieval and recommendation systems.

Normalized Discounted Cumulative Gain (NDCG) is a ranking metric that evaluates the quality of a search result list by considering both the graded relevance of each item and its position, with higher relevance scores receiving more weight when they appear earlier in the list. It is calculated by first computing the Discounted Cumulative Gain (DCG), which sums relevance scores with a logarithmic discount based on rank, and then normalizing it against the ideal DCG achievable for that query, resulting in a score between 0 and 1.

NDCG is the standard metric for evaluating retrieval-augmented generation (RAG) systems and search engines because it accounts for multi-level relevance (e.g., highly relevant, somewhat relevant, irrelevant) rather than simple binary relevance. A perfect NDCG@K score of 1.0 indicates the top K results are ordered identically to the ideal ranking. It is directly compared to metrics like Recall@K and Mean Reciprocal Rank (MRR) but is preferred when result relevance is graded.

RANKING METRIC

Key Characteristics of NDCG

Normalized Discounted Cumulative Gain (NDCG) is the standard metric for evaluating ranked lists where items have graded relevance (e.g., highly relevant, somewhat relevant, not relevant). It accounts for both the quality of results and their position.

01

Graded Relevance

Unlike binary metrics (relevant/not relevant), NDCG operates on graded relevance scores. Each item in the result list is assigned a relevance label, typically an integer (e.g., 0=irrelevant, 1=somewhat relevant, 2=highly relevant). This allows the metric to distinguish between a good result and a perfect result.

  • Example: In a search for "machine learning tutorials," a foundational blog post might score 1, while an official university course syllabus might score 3.
02

Positional Discounting

NDCG incorporates the principle that users value relevant items more when they appear higher in the list. It applies a logarithmic discount to the gain (relevance score) of each item based on its rank.

The gain for an item at position i is divided by log2(i + 1). This means the utility of a relevant document drops sharply if it's not on the first page of results, modeling real user attention decay.

03

Cumulative Gain (CG & DCG)

Cumulative Gain (CG) is the simple sum of relevance scores for the top K results. It ignores position.

Discounted Cumulative Gain (DCG) refines this by summing the positionally discounted gains.

Formula for DCG@K: DCG@K = Σ (relevance_i / log2(i + 1)) for i = 1 to K.

A variant uses an exponential gain for stronger emphasis on highly relevant items: DCG@K = Σ ((2^relevance_i - 1) / log2(i + 1)).

04

Normalization to Ideal DCG

NDCG is normalized by the Ideal DCG (IDCG). IDCG is the maximum possible DCG achievable for a given set of queries, obtained by ranking all items in perfect descending order of relevance.

Formula: NDCG@K = DCG@K / IDCG@K

This normalization bounds NDCG between 0.0 and 1.0, where 1.0 represents a perfect ranking. It allows for meaningful comparison across different queries and datasets with varying numbers of relevant items.

05

Evaluation of Ranking Quality

NDCG provides a single, interpretable number that summarizes overall ranking quality. It is the de facto standard for evaluating web search engines, recommendation systems, and RAG retrievers.

  • A score of 0.9+ indicates excellent ranking.
  • Scores are averaged over a large query set to evaluate system performance.
  • It directly measures the user experience of finding high-quality information quickly.
06

Relation to Other Metrics

NDCG complements other retrieval metrics:

  • Precision@K: Measures accuracy in the top K but uses binary relevance.
  • Recall@K: Measures coverage of all relevant items.
  • Mean Average Precision (MAP): Averages precision at each relevant item's rank, also for binary relevance.

NDCG is preferred when relevance is non-binary. It is more correlated with user satisfaction than precision or recall alone, as it penalizes systems that bury excellent results on page two.

METRIC COMPARISON

NDCG vs. Other Retrieval Metrics

A comparison of Normalized Discounted Cumulative Gain (NDCG) against other common metrics used to evaluate ranking quality in information retrieval and RAG systems.

Metric / FeatureNDCG (Normalized Discounted Cumulative Gain)Precision@KRecall@KMean Reciprocal Rank (MRR)

Core Definition

Measures ranking quality by summing graded relevance scores, discounted by rank position, normalized against an ideal ranking.

Measures the fraction of retrieved items in the top K that are relevant.

Measures the fraction of all relevant items that are found in the top K results.

Measures the average reciprocal rank of the first relevant item across queries.

Handles Graded Relevance

Accounts for Rank Position

Penalizes Late Relevance

Upper Bound (Perfect Score)

1

Varies by query

Varies by query

1

Typical Use Case

Evaluating web search, recommendation systems, and RAG retrieval where relevance is not binary.

Evaluating the purity of the top results when false positives are costly.

Evaluating the comprehensiveness of retrieval when missing relevant items is costly.

Evaluating systems where the rank of the first correct answer is critical (e.g., question answering).

Primary Weakness

Requires graded relevance judgments; more complex to compute.

Ignores relevance beyond position K; does not account for rank order within K.

Does not account for rank order; a relevant item at rank K+1 is a complete miss.

Only considers the first relevant item; ignores other relevant results.

Interpretation

A score of 1.0 indicates a perfect ranking order matching the ideal DCG. Scores are comparable across query sets.

A score of 0.8 at K=10 means 8 of the top 10 results were relevant.

A score of 0.5 at K=10 means half of all relevant documents for that query were in the top 10.

A score of 0.5 means the average rank of the first relevant result is 2 (1/rank = 0.5).

EVALUATION METRICS

Practical Applications of NDCG

Normalized Discounted Cumulative Gain (NDCG) is a core metric for evaluating ranked lists in information retrieval and recommendation systems. Its primary applications focus on measuring the quality of search results and personalized suggestions by accounting for both the relevance of items and their position in the list.

01

Search Engine Result Page (SERP) Evaluation

NDCG is the de facto standard for evaluating the quality of web search results. It quantifies how well a search engine orders documents by their usefulness to the user.

  • Graded Relevance: Unlike binary metrics, NDCG uses graded relevance scores (e.g., 0=irrelevant, 1=somewhat relevant, 2=relevant, 3=highly relevant).
  • Positional Discounting: It applies a logarithmic discount, heavily penalizing a highly relevant document placed on the second page of results versus the first position.
  • Industry Benchmark: Major search providers use NDCG@5, NDCG@10, or NDCG@20 to A/B test ranking algorithm changes and measure improvements in user satisfaction.
02

Recommender System Optimization

In e-commerce and media streaming, NDCG evaluates the quality of personalized recommendation lists (e.g., "Recommended for You").

  • List Quality: It measures if the most engaging or likely-to-purchase items are ranked at the top of a recommendation carousel.
  • Business Impact: A higher NDCG correlates directly with key metrics like click-through rate (CTR), conversion rate, and user retention.
  • Example: A video platform uses NDCG to test if a new algorithm ranks movies a user is likely to watch for 80% of their duration higher than those they might abandon after 5 minutes.
03

Retrieval-Augmented Generation (RAG) Pipeline Tuning

Within RAG architectures, NDCG is critical for evaluating the retriever component—the system that fetches context documents for the language model.

  • Retriever Benchmarking: Engineers compare different retrieval strategies (e.g., dense vs. sparse vs. hybrid search) by calculating NDCG over a test set of queries and ground-truth relevant document chunks.
  • Fine-Tuning Validation: After fine-tuning a dense retriever on domain-specific data, the improvement is measured by the increase in NDCG, indicating the retriever now better understands domain-specific language.
  • Precision vs. Recall Trade-off: NDCG@K (e.g., K=5) ensures the top few retrieved passages are maximally relevant, which is crucial for generator accuracy and hallucination reduction.
04

A/B Testing and Model Deployment

NDCG serves as a primary offline metric for gatekeeping model deployments. A new ranking model must demonstrate a statistically significant improvement in NDCG over the current production model before it is launched.

  • Reduction of Online Risk: It provides a reliable, quantitative proxy for expected user satisfaction before costly and risky live experiments.
  • Multi-Model Comparison: When choosing between several candidate algorithms, the one with the highest NDCG on a held-out validation set is typically selected for further testing.
  • Monitoring Drift: Tracking NDCG on a fixed evaluation set over time can alert teams to performance degradation due to data or concept drift.
05

Academic Benchmarking and Competitions

NDCG is the standard evaluation metric for public datasets and challenges in information retrieval, such as the TREC conferences or the MS MARCO leaderboard.

  • Reproducible Research: It provides a consistent, normalized score (between 0.0 and 1.0) that allows for direct comparison of algorithms published by different research groups.
  • Dataset-Specific: Major datasets publish official evaluation scripts and report NDCG@10 or similar as the key metric for ranking submissions.
  • Driving Innovation: The pursuit of higher NDCG scores on these benchmarks has driven advancements in neural ranking models, cross-encoders, and retrieval-augmented architectures.
06

Related Metrics and Practical Nuances

NDCG is used in conjunction with other metrics to provide a complete performance picture. Understanding its relationship to these metrics is essential for practitioners.

  • vs. Precision/Recall: Precision@K measures accuracy at a cutoff but treats all relevant items equally. NDCG is superior as it uses graded relevance and positional discounting.
  • vs. Mean Average Precision (MAP): MAP is designed for binary relevance and emphasizes recall. NDCG is preferred for multi-level relevance scales common in modern systems.
  • Ideal Discounted Cumulative Gain (IDCG): This is the denominator in NDCG. It represents the score of a perfect ranking, providing an intuitive upper bound of 1.0.
  • Cutoff Selection: The choice of K in NDCG@K is application-dependent: NDCG@5 for first-page web results, NDCG@100 for evaluating full retrieval sets in academic settings.
RAG EVALUATION

Frequently Asked Questions

Normalized Discounted Cumulative Gain (NDCG) is a core metric for evaluating the quality of ranked lists in information retrieval and Retrieval-Augmented Generation (RAG) systems. These FAQs address its mechanics, calculation, and practical application for engineers and CTOs.

Normalized Discounted Cumulative Gain (NDCG) is a ranking evaluation metric that measures the quality of a search result list by considering both the graded relevance of each item and its position, applying a logarithmic discount to items lower in the ranking. It is the normalized form of Discounted Cumulative Gain (DCG), which sums the relevance scores of results while reducing the contribution of scores from lower-ranked positions. The normalization is performed against an Ideal DCG (IDCG), which is the maximum possible DCG for a given set of results, producing a score between 0.0 and 1.0 where 1.0 represents a perfect ranking.

In the context of Retrieval-Augmented Generation (RAG), NDCG is used to evaluate the retriever component, assessing how well it orders relevant document chunks for a given query before they are passed to the generator. A high NDCG score indicates that the most relevant context is positioned at the top of the list, which is critical for minimizing prompt noise and reducing the likelihood of the language model generating hallucinations from less relevant information.

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.