RAG for Everyone

← Back to all chapters

Chapter 22 of 28Evaluation120 min read

Retrieval Metrics

Retrieval metrics tell you whether the right evidence reached the prompt early enough to be useful. If retrieval fails, the model is forced to guess, refuse, or answer from weak context.

How to read this chapter

A RAG team that only evaluates final answers is debugging with half the lights off. Retrieval metrics turn the lights on before generation happens.
Core ideaRetrieval metrics compare retrieved results against known relevant evidence so teams can tune search, filters, chunking, reranking, and index releases with confidence.
Sub-topic 1 of 15

Why Retrieval Metrics Matter

Imagine a user asks: "What approval is needed for enterprise refunds after 30 days?" The answer depends on a very specific policy chunk. If retrieval misses that chunk, the model has only bad options: guess, refuse, or answer from a nearby but wrong policy.

Retrieval metrics isolate this first critical question: did the system retrieve the evidence that could support a correct answer? This is different from asking whether the final answer sounded good.

Production signals
  • Missing evidence: gold source never appears in candidates.
  • Buried evidence: gold source appears, but below the context cutoff.
  • Noisy evidence: relevant chunks are surrounded by distracting chunks.
  • Filtered evidence: metadata/access/freshness filters remove gold evidence.
  • Stale evidence: retrieval finds an old version that looks relevant but should not be used.
Retrieval metric north starMeasure whether the right evidence appears early enough, cleanly enough, and safely enough to be used.

A senior RAG engineer does not ask "is search good?" They ask: good for which user, query type, corpus, source version, risk level, and context budget?

01
Label gold evidence

Define expected chunk ids, document ids, or source spans for each benchmark question.

02
Capture the retrieval trace

Log route, filters, query rewrite, candidate ids, scores, ranks, reranker output, and index version.

03
Compute multiple metrics

Use Recall@K for candidate presence, MRR for rank, Precision@K for noise, nDCG for graded relevance, and hit rate for health trends.

04
Convert metrics into fixes

Metric movement should point to chunking, filters, hybrid search, reranking, index freshness, or release rollback.

Sub-topic 2 of 15

Real-Life Analogy: Search Party

Think of retrieval as a search party looking for a critical file in a warehouse. Recall asks, "Did they find the file at all?" MRR asks, "How quickly did they find it?" Precision asks, "How much irrelevant material did they bring back?" nDCG asks, "Did the best and most authoritative evidence appear before weaker evidence?"

This analogy matters because production RAG has the same problem. If the right file is found at position 40, the search party technically found it, but the person answering the question may only inspect the first 5 files. Rank and cutoff matter.

Mentor note: when a RAG answer fails, first ask: "Was the answerable evidence in the final context?" If no, look at retrieval metrics before blaming the model.
Sub-topic 3 of 15

Gold Evidence

Gold evidence is the expected evidence for a query. It is the answer key for retrieval evaluation. Without gold evidence, teams often argue based on vibes: "These results look okay to me." That does not scale.

Chunk-level gold

Best for tuning retrieval. Example: query must retrieve policy-v4#refunds-enterprise-exception.

Document-level gold

Easier to label, but less precise. It may pass even when retrieval finds the wrong section.

Span-level gold

Best for high-risk domains. The exact paragraph, table row, or clause must be retrievable.

Gold dataset example

query_id: q_refund_001
question: "Who approves enterprise refunds after 30 days?"
gold:
  - chunk_id: policy-v4:refunds:enterprise-exception
    relevance: 3
    reason: "contains VP approval rule"
  - chunk_id: addendum-v2:enterprise-refunds
    relevance: 2
    reason: "contains written reason requirement"
slice:
  domain: policy
  risk: high
  query_type: exact_policy_lookup

Notice the relevance grade. This lets us evaluate not only whether any source appeared, but whether the best source appeared early.

Sub-topic 4 of 15

Recall@K

Recall@K asks: "Out of all gold evidence items, how many appeared in the top K retrieved results?" It is usually the first metric to build because evidence that is never retrieved cannot be used by the model.

Recall@5 calculation

gold chunks: S2, S9
retrieved top 5: S1, S2, S4, S8, S9
hits: S2, S9
Recall@5 = 2 / 2 = 1.0

Now compare a dangerous case:

High K can hide product failure

gold chunks: S2
retrieved top 50: S1, S3, S4, ... S2 at rank 42
Recall@50 = 1.0
Recall@5 = 0.0
final context uses top 5
product outcome: answer fails
Production interpretation
  • Low Recall@50: candidate discovery is weak. Check corpus, parsing, chunking, query rewrite, embedding model, sparse/hybrid retrieval, and filters.
  • High Recall@50 but low Recall@5: ranking is weak. Check reranking, fusion, scoring, and final-k policy.
  • Recall drops after a filter: inspect metadata and access/freshness rules before blaming search.
Sub-topic 5 of 15

Precision@K

Precision@K asks: "Of the top K results, how many are relevant?" Precision matters because the prompt has limited space. Noisy context can distract the model, crowd out better evidence, and increase cost.

High recall, low precision

The right chunk appears, but the model receives too much noise. Fix reranking, dedupe, metadata filters, or context selection.

Low recall, high precision

The returned chunks are clean, but important evidence is missing. Fix candidate discovery.

Good production balance

Use broad retrieval for candidate recall, then rerank and select final context for precision.

Engineering judgment: candidate pools can tolerate lower precision. Final context cannot. The user never sees your candidate pool; the model does see your final context.
Sub-topic 6 of 15

Mean Reciprocal Rank

MRR rewards systems that put the first relevant result near the top. It is especially useful when one good source is enough to answer the question.

MRR intuition

query A first relevant rank = 1 -> 1/1 = 1.0
query B first relevant rank = 4 -> 1/4 = 0.25
query C first relevant rank = not found -> 0.0
MRR = average reciprocal rank across queries

If Recall@10 is stable but MRR drops, the system still retrieves gold evidence, but pushes it lower. This usually means a ranking, fusion, or reranking regression.

When MRR is useful
  • FAQ answer lookup where one authoritative chunk is enough.
  • Policy lookup where the first correct source should be near the top.
  • Regression testing after changing embeddings, reranking, or hybrid fusion.
Sub-topic 7 of 15

nDCG

nDCG helps when relevance is graded. Some evidence is perfect, some is partially useful, and some is weak background. nDCG rewards putting stronger evidence earlier.

Graded relevance example

3 = directly answers the question
2 = supports one condition or exception
1 = related background
0 = irrelevant

Question: "What changed in refund policy v4?"
Best ranking: policy-v4 changelog (3), refund policy v4 (3), enterprise addendum (2), old policy (1)

Use nDCG when your system must compare multiple useful sources, not just find one correct source. Legal, research, policy, and incident runbook systems often benefit from graded relevance.

Sub-topic 8 of 15

Hit Rate

Hit rate asks whether at least one relevant item was retrieved. It is simple and useful for health dashboards, but it hides rank and completeness.

Good for

Broad daily health checks and alerting.

Weakness

A hit at rank 50 may not help if the final prompt receives only top 5.

Use with

Recall@K, MRR, final context precision, and citation support.

Sub-topic 9 of 15

Failure Slices

Average metrics can lie. A system may show 86% Recall@10 overall while failing 40% of exact policy-id queries. Production teams slice metrics because users do not experience averages; they experience their specific workflow.

Domain

Policy vs support

Policy questions may need authority and freshness. Support questions may need broad coverage and speed.

Query type

Exact vs semantic

Error codes, SKUs, clause IDs, and incident IDs need sparse or hybrid search protection.

Source format

PDF vs markdown

Parsing and table extraction failures often show up as source-format retrieval gaps.

Risk

Low vs high

High-risk queries deserve stricter gates and smaller tolerance for regression.

Failure slice report

overall Recall@10: 0.86
policy Recall@10: 0.91
support Recall@10: 0.88
exact_terms Recall@10: 0.52  <-- action needed
pdf_tables Recall@10: 0.43   <-- parsing/indexing issue likely
Sub-topic 10 of 15

Architecture View

Retrieval metrics architecture showing golden query set, retriever, retrieved results, metric calculator, dashboards, failure analysis, and release gate
Retrieval metrics compare retrieved result ids with gold evidence, then feed dashboards, failure analysis, and release gates.

Metric pipeline

gold query set
  -> run retriever against candidate index
  -> capture retrieved ids, ranks, scores, filters, route
  -> compute Recall@K, Precision@K, MRR, hit rate, nDCG
  -> slice by domain/query/source/risk
  -> compare against baseline
  -> release, warn, or block
Sub-topic 11 of 15

Dashboards

A production dashboard should show trends, not just one score. Track metrics by index version, retriever route, embedding model, reranker version, prompt version, and source freshness.

Quality tiles

Recall@K, MRR, nDCG, final context precision, citation support.

Operations tiles

Retrieval latency, timeout rate, empty retrieval rate, filter drop rate.

Freshness tiles

Stale hit rate, deleted-source hit rate, index lag, source version correctness.

A strong dashboard answers: what changed, where it changed, who is affected, and what engineering action should happen next.

Sub-topic 12 of 15

Release Gates

Retrieval changes should pass gates before rollout. A new embedding model, chunking strategy, metadata filter, hybrid route, or reranker can improve one slice and break another.

Gate example
  • High-risk policy Recall@10 must not drop below baseline.
  • Exact-id hit rate must stay above threshold.
  • MRR must not regress for top customer-support questions.
  • Stale-source hit rate must not increase.
  • p95 retrieval latency must remain inside product budget.
Practical release rule: if a retrieval change improves overall Recall@10 but breaks high-risk policy lookup, do not ship it broadly. Canary it, route it selectively, or fix the failing slice first.
Sub-topic 13 of 15

Common Mistakes

M01

Only measuring final answers

Symptom: team cannot tell whether retrieval or generation failed.
Better move: measure retrieval before context injection and generation.
M02

No gold labels

Symptom: retrieval quality becomes subjective.
Better move: create chunk-level or document-level gold evidence.
M03

Tracking only Recall@K

Symptom: gold evidence exists but is buried under noisy results.
Better move: add MRR, precision, and rank analysis.
M04

Ignoring slices

Symptom: average metric looks fine while one domain fails badly.
Better move: slice by domain, query type, source format, tenant, and risk.
M05

Comparing different test sets

Symptom: metric movement is meaningless.
Better move: compare versions on the same benchmark set.
M06

Forgetting filter failures

Symptom: search seems bad, but metadata filters removed gold evidence.
Better move: log filters, candidate pools, and filtered-out gold ids.
M07

No freshness metric

Symptom: retrieval finds old but relevant-looking content.
Better move: track stale hit rate and source version correctness.
M08

Metric without action

Symptom: dashboard exists but no one knows what to fix.
Better move: connect each metric to tuning actions and release gates.
Sub-topic 14 of 15

Interview-Level Understanding

A strong answer sounds like this: "I evaluate retrieval separately from generation. I label gold evidence, run benchmark queries, compute Recall@K, Precision@K, MRR, hit rate, and sometimes nDCG, then slice by domain and query type. If recall is low, I inspect corpus, parsing, chunking, filters, query rewriting, and retrieval strategy. If recall is high but MRR is low, I inspect ranking, fusion, and reranking. I use those metrics as release gates, not just dashboards."

Sub-topic 15 of 15

Points To Remember

  • Retrieval metrics answer whether the right evidence reached the system.
  • Recall@K measures candidate presence; MRR measures rank quality.
  • Precision matters because noisy context hurts generation.
  • nDCG helps when relevance is graded, not simply yes/no.
  • Average scores must be sliced by domain, query type, source format, tenant, and risk.
  • Metrics should drive release gates and concrete tuning actions.

Next, test your retrieval-metric judgment in the quiz, then build a metric calculator and release gate in the project.

← Chapter 21 ProjectTake the Quiz →