Course contentsShow
← AI Engineering
Lesson 406 of 1,88610. RAG - Improving RetrievalFree lesson

Normalized Discounted Cumulative Gain (NDCG)

Using NDCG to measure retrieval quality accounting for both relevance and ranking position.

Normalized Discounted Cumulative Gain (NDCG)

You'll learn how NDCG measures retrieval quality by rewarding both relevance and top-ranked positions.

What Is NDCG?

NDCG is a retrieval metric that understands a simple truth: where a result appears matters as much as whether it appears at all. Unlike precision or recall, NDCG penalizes relevant documents that appear lower in your results list.

Think of it like a restaurant review app. If the best restaurant is ranked 10th instead of 1st, most users won't see it. NDCG captures this frustration—it rewards systems that put the most relevant items at the top.

How It Works

NDCG has three components:

  1. Relevance scores: Each retrieved document gets a graded score (e.g., 0-3), not just binary relevant/irrelevant
  2. Position discount: Results lower in the ranking are logarithmically discounted (position 2 is worth less than position 1, position 10 even less)
  3. Normalization: The score is divided by the "ideal" ranking, giving you a 0-1 scale where 1.0 means perfect ordering

The "discounted" part means a highly relevant document at position 5 contributes less than the same document at position 1. The "cumulative" part means you sum across all positions. The "normalized" part means you compare against the best possible ordering.

Why It Matters for RAG

When your retrieval system returns 10 chunks, NDCG tells you whether the best chunks are at the top where the LLM will see them first (remember: lost-in-the-middle!). A high NDCG@5 means your top 5 results are well-ordered by relevance.

Key Takeaway: NDCG measures not just what you retrieve, but how well you rank it—critical when LLMs process your top-K results in order.