AnyLearn
All lessons
Computer Scienceintermediate

Measuring Relevance: Judgments, NDCG, and the Click Trap

Search quality arguments end when there is a number, and begin again over whether the number is honest. This lesson builds offline evaluation from its atoms: a judgment set, precision and recall at k, MRR for known-item queries, and NDCG computed by hand for graded relevance. Then the online half: clicks, position bias, and why the top result gets clicked even when it is wrong.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 7

Tuning without measurement is superstition

Every search team eventually lives this meeting: someone important searched for something, disliked the third result, and now wants the ranking changed. The change is made, that query improves, and nobody notices the two hundred queries that got worse.

Relevance tuning without an evaluation harness is exactly whack-a-mole, because every knob in the previous lessons, analyzer choices, BM25 parameters, fusion depths, boosts, moves thousands of queries at once. The only way to know a change helped is to measure the whole system before and after, on a fixed set of queries with known right answers.

That harness has two halves, and mature teams run both:

  • Offline evaluation: a curated set of queries with human-labelled relevance judgments, scored with the metrics this lesson builds. Runs in seconds, before anything ships.
  • Online evaluation: real user behaviour, clicks, reformulations, abandonment, measured in production, ideally through controlled experiments.

Key idea: offline metrics tell you whether the ranking got better against a frozen definition of good. Online metrics tell you whether users noticed. The two disagree often enough that running only one is a strategy for surprising yourself.

Full lesson text

All 7 steps on one page, for reading, reference, and search.

Show

1. Tuning without measurement is superstition

Every search team eventually lives this meeting: someone important searched for something, disliked the third result, and now wants the ranking changed. The change is made, that query improves, and nobody notices the two hundred queries that got worse.

Relevance tuning without an evaluation harness is exactly whack-a-mole, because every knob in the previous lessons, analyzer choices, BM25 parameters, fusion depths, boosts, moves thousands of queries at once. The only way to know a change helped is to measure the whole system before and after, on a fixed set of queries with known right answers.

That harness has two halves, and mature teams run both:

  • Offline evaluation: a curated set of queries with human-labelled relevance judgments, scored with the metrics this lesson builds. Runs in seconds, before anything ships.
  • Online evaluation: real user behaviour, clicks, reformulations, abandonment, measured in production, ideally through controlled experiments.

Key idea: offline metrics tell you whether the ranking got better against a frozen definition of good. Online metrics tell you whether users noticed. The two disagree often enough that running only one is a strategy for surprising yourself.

2. The judgment set: your definition of good

Offline evaluation stands on a judgment set: a sample of queries, each with documents labelled for relevance. Everything downstream is arithmetic; the judgments are the actual encoded opinion about what good search means, which makes their construction the most consequential step.

What experience says about building one:

  • Sample queries from real traffic, stratified deliberately: head queries because they carry volume, tail queries because they carry the failures, and the known-item queries, SKUs, names, exact titles, that earlier lessons showed to be their own regime.
  • Grade, do not binarise. A four-level scale, irrelevant, marginal, relevant, perfect, captures that the ideal result and an acceptable one differ, which binary labels erase and which NDCG, below, is built to use.
  • Write a labelling rubric with examples, because two honest people disagree on raw relevance surprisingly often; the rubric is where those disagreements get settled once instead of per-label.
  • Judge the document against the query, not the system. Labels must not depend on what the current engine returns, or the evaluation inherits the very biases it exists to catch. Pool candidates from several systems and sources before judging.
  • Refresh on a schedule. Corpora drift, intent drifts, and a judgment set from two years ago quietly measures a search engine for a site that no longer exists.

3. The counting metrics: precision, recall, MRR

With judgments in hand, the simple metrics come first, and each answers a different operational question.

MetricFormula in wordsThe question it answers
Precision at kOf the top k results, what fraction is relevant?How clean is the page the user sees?
Recall at kOf all relevant documents, what fraction made the top k?Did retrieval find the good stuff at all?
MRRAverage of 1 over the rank of the first relevant resultHow fast does the user hit something right?

Each has a natural home. Precision at 10 suits browsing pages where the user scans everything shown. Recall at 100 is the retrieval stage's report card in the funnel from last lesson: the re-ranker cannot promote a document that retrieval never surfaced, so recall at the fusion depth bounds everything downstream. Mean reciprocal rank fits known-item queries, where exactly one document is the answer and the only question is how far down it sits: first place scores 1, second scores 0.5, fifth scores 0.2, and the average over queries is brutally interpretable.

What none of them see: that the top of the page matters more than the bottom within the k window, and that a perfect result differs from a merely acceptable one. Both blind spots are fixed by the metric that has become the industry default.

4. NDCG: position-weighted, grade-aware

Normalised discounted cumulative gain builds in the two missing pieces: graded labels, and the fact that rank 1 is worth more than rank 5.

Start with discounted cumulative gain. Each result contributes a gain from its relevance grade, discounted by its position:

DCG@k=i=1k2reli1log2(i+1)\mathrm{DCG@k} = \sum_{i=1}^{k} \frac{2^{\mathrm{rel}_i} - 1}{\log_2(i + 1)}

The exponential numerator makes high grades count disproportionately, a grade-3 result contributes 7, a grade-1 contributes 1, and the logarithmic denominator taxes depth gently: position 1 divides by 1, position 3 by 2, position 7 by 3.

Raw DCG depends on how many relevant documents a query happens to have, so queries cannot be compared or averaged. The fix is normalisation: divide by the ideal DCG, the score of the same judged documents arranged in the best possible order.

NDCG@k=DCG@kIDCG@k\mathrm{NDCG@k} = \frac{\mathrm{DCG@k}}{\mathrm{IDCG@k}}

The result lands in 0 to 1, where 1 means the ranking is exactly as good as the judgments allow, and 0.8 means genuine headroom remains. Averaged over the judgment set, NDCG at 10 is the single number most search teams watch, precisely because it moves when a good document climbs from rank 6 to rank 2, which is the kind of improvement users feel and coarser metrics miss.

5. NDCG by hand, once

Compute it once and the formula stops being a formula. A query returns five results with graded judgments: ranks 1 through 5 carry grades 2, 3, 0, 1, 0.

Gains: grade 2 gives 3; grade 3 gives 7; grade 0 gives 0; grade 1 gives 1; grade 0 gives 0.

Discounts by position: divide by log2 of position plus one, so 1.0, 1.585, 2.0, 2.322, 2.585.

DCG: 3 over 1, plus 7 over 1.585, plus 0, plus 1 over 2.322, plus 0. That is 3 plus 4.416 plus 0.431, totalling 7.85.

The ideal ordering sorts grades descending, 3, 2, 1, 0, 0: IDCG is 7 over 1, plus 3 over 1.585, plus 1 over 2, which is 7 plus 1.893 plus 0.5, totalling 9.39.

NDCG: 7.85 over 9.39, which is 0.84.

Predict first

The engine's mistake was ranking the perfect (grade 3) document second instead of first. Suppose instead it had buried it at rank 5. What happens to NDCG?

6. Online truth, and the position bias trap

Offline metrics grade the ranking against frozen human opinion. Online metrics ask the users, and the users answer with behaviour: click-through rates, time to first click, reformulation rate, how often a search session ends with nothing clicked, and downstream outcomes like add-to-cart from search.

The naive reading of that behaviour fails, and it fails in one specific, well-documented way.

Predict first

Across your whole query stream, result position 1 gets clicked vastly more than position 5. Does that show your ranker is putting the best results first?

The consequences run deep. Click data used naively to train or tune rankers becomes a feedback loop: whatever ranks first collects the clicks that then justify ranking it first. The escape routes are deliberate: interleaving experiments, which mix two rankers' results into one list and credit the source of each click, controlled A/B experiments on ranking changes, and click models that explicitly estimate and remove the position effect before the data is trusted.

7. The evaluation loop that keeps a search team honest

Assemble the pieces into the operating rhythm that separates search teams from search superstition.

  1. Every ranking change runs offline first. The judgment set and NDCG at 10, plus recall at fusion depth for retrieval changes, gate the merge. Seconds of compute, and regressions die in review instead of production.
  2. Slice before celebrating. An aggregate NDCG gain can hide a known-item collapse: the hybrid change that lifts paraphrase queries may bury exact SKUs. Report per-stratum, head, tail, known-item, at minimum, because the strata fail independently.
  3. Material changes ship as experiments. Offline improvement is a hypothesis; the interleaving or A/B result is the verdict. When offline and online disagree, and they will, the judgment set just learned something: mine the disagreeing queries and fix the rubric or the sample.
  4. Watch the zero-results rate and reformulations in production continuously. They are the cheapest early warnings that reality has drifted away from the judgment set.
  5. Feed failures back. Queries that users reformulate, abandon, or escalate become next quarter's judgment set additions, which is how the frozen definition of good tracks a moving product.

None of this is glamorous, and all of it compounds: the team with the loop makes twenty small verified improvements a quarter, and the team without it makes twenty confident changes, of unknown sign.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why must judgment labels not depend on what the current engine returns?
    • Because labels would need updating after every deploy
    • Because current-system bias would make the evaluation inherit exactly the blind spots it exists to catch
    • Because engines cannot return graded results
    • Because judges are not allowed to see ranked lists
  2. Which metric most directly bounds what a re-ranker can achieve?
    • Recall at the fusion depth, since the re-ranker cannot promote documents retrieval never surfaced
    • Precision at 1
    • MRR over known-item queries
    • Click-through rate on position 1
  3. In DCG, what do the exponential numerator and logarithmic denominator respectively encode?
    • Query length and corpus size
    • Term frequency and document length
    • High relevance grades count disproportionately, and depth in the ranking is taxed gradually
    • Click probability and dwell time
  4. Moving the only grade-3 document from rank 2 to rank 5 left precision and recall at 5 unchanged but dropped NDCG sharply. Why is that the desired behaviour?
    • NDCG penalises long documents
    • The ideal DCG changed between the two rankings
    • NDCG counts the grade-3 document twice at rank 2
    • NDCG is position-weighted, so burying the best result is a real quality loss that set-based metrics cannot see
  5. Why is raw click-through rate by position a poor measure of ranking quality?
    • Clicks cannot be logged reliably at scale
    • Position bias: users click the top result largely because of where it sits, so clicks measure layout as much as relevance
    • Click-through rates are only defined for paid results
    • Users click more on short titles regardless of position

Related lessons

Computer Science
intermediate

BM25: How Lexical Relevance Is Actually Computed

Matching finds candidates; scoring orders them, and the ordering is the product. This lesson builds BM25, the default ranking function of Lucene, Elasticsearch and OpenSearch, from its three ingredients: rare terms count more, repeated terms saturate, and long documents get discounted. With the formula, the two tuning knobs, and the saturation curve computed by hand.

7 steps·~11 min
Computer Science
intermediate

Lexical Meets Vector: Hybrid Search and Rank Fusion

Vector search did not replace keyword search, because the two fail in opposite places: BM25 cannot see that laptop and notebook mean the same thing, and embeddings cannot see that SKU-4471-B is not approximately anything. This lesson maps the two failure surfaces, then builds the production answer: run both retrievers and fuse the rankings, with reciprocal rank fusion done by hand.

7 steps·~11 min
Computer Science
intermediate

The Inverted Index, and Why Analysis Decides Everything

Search does not scan documents; it looks up precomputed answers. This lesson builds the inverted index from first principles, then covers the pipeline that feeds it: tokenization, normalisation, stemming and synonyms, and why an analysis mistake made at index time cannot be fixed at query time. Includes the classic failure where a product SKU becomes unfindable.

7 steps·~11 min
AI
advanced

Evaluating a Book Model Honestly

If your cost per round trip equals the move you are trying to capture, you need 100 percent directional accuracy to break even. This lesson computes that hurdle, replaces accuracy with metrics tied to a tradeable decision, and covers the capacity and latency limits that decide whether a real edge is worth anything.

10 steps·~15 min