RAG Evals
Phase 12 · Document 03 · Evaluation Prev: 02 — LLM-as-Judge · Up: Phase 12 Index
Table of Contents
- Why This Matters
- Core Concept
- Mental Model
- Hitchhiker's Guide
- Warmup Readings
- Deep Readings and External References
- Key Terms
- Important Facts
- Observations from Real Systems
- Common Misconceptions
- Engineering Decision Framework
- Hands-On Lab
- Verification Questions
- Takeaways
- Artifact Checklist
1. Why This Matters
RAG is the most common production LLM pattern (Phase 9), and it fails in a way that's invisible without the right eval: a confident, fluent answer that's ungrounded (hallucinated) or based on the wrong retrieved chunks. This doc applies the unified eval discipline (00–02) to RAG, with one move that defines RAG eval: separate retrieval from generation. When an answer is wrong you must know whether retrieval missed the chunk or generation ignored it — they're fixed in completely different places. (The mechanics live in Phase 9.09; here we frame RAG eval as an instance of the Phase 12 discipline — golden sets [01], judges [02], the harness [08] — and consolidate the metric set.)
2. Core Concept
Plain-English primer: evaluate the two halves separately
RAG = retrieval + generation, so RAG eval has two halves, and keeping them separate is the core skill (Phase 9.09):
- Retrieval eval — did we fetch the right chunks? (independent of the generator)
- Generation eval — given those chunks, was the answer faithful, relevant, complete? (independent of whether retrieval was perfect)
A wrong answer is either a retrieval miss or a generation failure (or both), and the fix differs — conflating them ("answer wrong → try a bigger model") is the #1 RAG-tuning mistake when the real problem was retrieval (Phase 9.00: retrieval dominates quality).
The RAG metric quadrant (Ragas framing)
Four metrics, two per half (Phase 9.09):
| Metric | Half | Question |
|---|---|---|
| Context recall | Retrieval | Did we retrieve all chunks needed to answer? (misses?) |
| Context precision | Retrieval | Are retrieved chunks relevant (and well-ranked)? (noise?) |
| Faithfulness | Generation | Is the answer supported by the retrieved context? (hallucination?) |
| Answer relevancy | Generation | Does the answer address the question? |
Read the quadrant to localize: low recall → chunking/embeddings/hybrid (Phase 9.02/9.03/9.05); low precision → reranking (Phase 9.06); low faithfulness → grounding/model (Phase 9.08); low answer-relevancy → prompt/packing (Phase 9.07).
Scorers: programmatic IR metrics + judge
Mapping to the Phase 12 scorer hierarchy (00):
- Retrieval = programmatic (when you have gold relevant chunks in the golden set [01]): recall@k, precision@k, MRR, nDCG — objective, cheap. recall@k is the ceiling — if the right chunk isn't retrieved, no model can fix it.
- Generation = LLM-as-judge (02): faithfulness and answer-relevancy are about meaning, so a (calibrated) judge scores them (Ragas/TruLens automate this). Calibrate against humans — judge bias applies here too.
The golden set for RAG
The golden set (01) for RAG carries extra fields: the question, gold relevant chunk IDs (for retrieval metrics), a ground-truth answer, and — crucially — unanswerable questions (to test refusal/hallucination, Phase 9.08). Build it from real queries + hard cases; grow it from production failures (the flywheel, 01).
The 3-step debugging loop
The daily RAG-eval tool (Phase 9.09): for a wrong answer —
- Was the right chunk retrieved? (recall@k / inspect context) → if no, fix retrieval.
- If yes, is the answer faithful? → if no, fix grounding/model.
- If faithful but unhelpful → fix answer-relevancy (prompt/packing). This localizes every RAG failure to a stage.
Offline + online
Same as the discipline (00): offline run the golden set in CI, gate on faithfulness + recall@k when you change chunking/embedder/reranker/prompt (08); online sample faithfulness on live traffic + use thumbs/citation-clicks/escalations, feeding failures back (Phase 7.08, Phase 9.10).
3. Mental Model
RAG = retrieval + generation → EVAL THE TWO HALVES SEPARATELY (the defining move)
wrong answer = retrieval miss OR generation failure → fixed in DIFFERENT places [9.00 retrieval dominates]
QUADRANT: retrieval → context RECALL (misses?) + PRECISION (noise?) [programmatic, needs GOLD chunks]
generation → FAITHFULNESS (hallucination?) + ANSWER-RELEVANCY [LLM-judge, calibrate [02]]
localize: recall↓→chunk/embed/hybrid · precision↓→rerank · faithfulness↓→grounding/model · relevancy↓→prompt/pack
SCORERS: retrieval = recall@k/precision@k/MRR/nDCG (recall@k = CEILING) ; generation = judge (calibrated)
GOLDEN SET [01]: question + GOLD chunks + ground-truth answer + UNANSWERABLE ; OFFLINE gate + ONLINE feedback
3-STEP DEBUG: retrieved? → faithful? → relevant?
Mnemonic: separate retrieval from generation — the metric quadrant (recall/precision · faithfulness/relevancy) localizes every failure. recall@k is the ceiling; retrieval = programmatic, generation = calibrated judge. Debug: retrieved? → faithful? → relevant?
4. Hitchhiker's Guide
What to look for first: are you measuring retrieval and generation separately, and do you have gold relevant chunks (for recall@k) + unanswerable cases? Those make RAG eval diagnostic instead of opaque.
What to ignore at first: exotic trajectory metrics. Start with recall@k + faithfulness + answer-relevancy on a small golden set; expand later. (Full mechanics: Phase 9.09.)
What misleads beginners:
- Eval'ing only the final answer. You can't tell why it failed — split retrieval vs generation (Phase 9.09).
- No gold chunks. Without labeled relevant chunks you can't compute recall@k — the retrieval ceiling stays invisible.
- Treating "hallucination" as a model bug. Most are retrieval misses — check recall first (Phase 9.00).
- Trusting the faithfulness judge. Calibrate it (02).
- No unanswerable cases. You never test refusal; hallucination hides (Phase 9.08).
How experts reason: they build a RAG golden set (01) with gold chunks + unanswerable items, measure retrieval (programmatic IR metrics) and generation (calibrated judge) separately, localize failures via the quadrant + 3-step loop, gate changes in CI (faithfulness + recall@k), and feed online failures back (Phase 9.10).
What matters in production: retrieval recall (the ceiling), faithfulness (no hallucination), per-stage localization, and the regression gate catching chunking/embedder/reranker/prompt changes (08).
How to debug/verify: run the 3-step loop — retrieved? faithful? relevant? — to localize; if recall@N is low, fix retrieval (Phase 9.05/9.06) before touching the generator.
Questions to ask: do we eval retrieval and generation separately? gold chunks for recall@k? faithfulness judge calibrated? unanswerable cases included? CI gate + online faithfulness sampling?
What silently gets expensive/unreliable: answer-only eval (can't localize), no gold chunks (invisible retrieval ceiling), uncalibrated faithfulness judge, and missing unanswerable cases (hidden hallucination).
5. Warmup Readings
| Title | Why to read it | What to extract | Difficulty | Time |
|---|---|---|---|---|
| Phase 9.09 — RAG Evaluation | The full RAG-eval mechanics | quadrant, 3-step loop | Beginner | 25 min |
| 00 — Evaluation Overview | The unified discipline | scorer hierarchy | Beginner | 15 min |
| 01 — Golden Datasets | Gold chunks + unanswerable | the RAG golden set | Beginner | 20 min |
| 02 — LLM-as-Judge | Scoring faithfulness | calibration | Beginner | 20 min |
6. Deep Readings and External References
| Title | URL | Why it matters | Read first | Lab connection |
|---|---|---|---|---|
| Ragas | https://docs.ragas.io/ | The metric quadrant | faithfulness/precision/recall | This lab |
| TruLens (RAG triad) | https://www.trulens.org/ | Groundedness/relevance | the triad | Online eval |
| BEIR | https://github.com/beir-cellar/beir | IR retrieval benchmarks | nDCG/recall | Retrieval metrics |
| Phase 9.09 — RAG Evaluation | (curriculum) | The deep source | the quadrant + loop | Whole doc |
| nDCG/MRR primer | https://en.wikipedia.org/wiki/Discounted_cumulative_gain | Rank-aware metrics | DCG→nDCG | Metric lab |
7. Key Terms
| Term | Simple meaning | Technical meaning | Why it matters | Where it appears | How to use it |
|---|---|---|---|---|---|
| Retrieval eval | Did we fetch right? | recall/precision/MRR/nDCG on chunks | Localize failures | half 1 | Needs gold chunks |
| Generation eval | Was the answer good? | faithfulness + answer-relevancy | Hallucination/quality | half 2 | Calibrated judge |
| Context recall | Found all needed? | relevant chunks in top-k | Retrieval ceiling | quadrant | recall@k |
| Context precision | Relevant + ranked | top-k relevance | Noise | quadrant | → rerank [9.06] |
| Faithfulness | Answer supported | claims entailed by context | Trust | quadrant | Judge + verify |
| Answer relevancy | Addresses question | answer-to-query relevance | Helpfulness | quadrant | → prompt/pack |
| Gold chunks | Known-relevant context | Labeled relevant chunks | recall@k | golden set [01] | Label them |
| 3-step loop | Localize a failure | retrieved?→faithful?→relevant? | The debug tool | method | Daily use |
8. Important Facts
- Evaluate retrieval and generation separately — the defining move; a wrong answer is a retrieval miss or a generation failure, fixed differently (Phase 9.09).
- The quadrant: context recall + context precision (retrieval); faithfulness + answer-relevancy (generation) — localizes failures to a stage.
- recall@k is the retrieval ceiling — if the right chunk isn't retrieved, no model can recover it (Phase 9.00).
- Retrieval = programmatic IR metrics (recall@k/precision@k/MRR/nDCG) with gold chunks; generation = calibrated LLM-judge (faithfulness/relevancy) (02).
- Most "hallucination despite RAG" is a retrieval miss — check recall first.
- The RAG golden set needs gold chunks + ground-truth answers + unanswerable cases (01, Phase 9.08).
- The 3-step loop (retrieved? → faithful? → relevant?) localizes every failure.
- Gate offline (faithfulness + recall@k) + monitor online, feeding failures back (Phase 9.10).
9. Observations from Real Systems
- Ragas (the quadrant) and TruLens (the RAG triad) are the standard RAG-eval tools — the unified discipline (00) applied to RAG.
- The decisive debugging moment is discovering a "hallucination" was a retrieval miss — only the split reveals it (Phase 9.09).
- Teams that gate CI on faithfulness + recall@k ship far fewer RAG regressions when swapping embedders/chunking/rerankers (Phase 9.02–9.06).
- Online signals (thumbs, citation clicks, escalations) are mined into new golden examples — the flywheel (Phase 9.10).
- Faithfulness judges need calibration — uncalibrated, they miss subtle ungrounded claims (02).
10. Common Misconceptions
| Misconception | Reality |
|---|---|
| "Eval the final answer" | Split retrieval vs generation to localize |
| "Hallucination = bad model" | Usually a retrieval miss — check recall@k first |
| "No need for gold chunks" | Then recall@k (the ceiling) is invisible |
| "Faithfulness judge = truth" | Calibrate it against humans [02] |
| "Skip unanswerable questions" | You never test refusal; hallucination hides |
| "One RAG score" | Use the quadrant (4 metrics, 2 halves) |
11. Engineering Decision Framework
EVALUATE A RAG SYSTEM:
1. GOLDEN SET [01]: question + GOLD relevant chunks + ground-truth answer + UNANSWERABLE cases.
2. RETRIEVAL (programmatic): recall@k / precision@k / MRR / nDCG (recall@k = ceiling) [9.05/9.06].
3. GENERATION (calibrated judge [02]): faithfulness + answer-relevancy (Ragas/TruLens).
4. LOCALIZE via quadrant + 3-step loop: recall↓→chunk/embed/hybrid · precision↓→rerank ·
faithfulness↓→grounding/model · relevancy↓→prompt/pack [9.02–9.08].
5. OFFLINE gate (faithfulness + recall@k) in CI; ONLINE sample faithfulness + thumbs/citations → feed back [9.10].
| Symptom | Metric low → fix |
|---|---|
| Misses obvious info | context recall → chunking/embeddings/hybrid |
| Noisy context | context precision → reranking |
| Hallucinates w/ good context | faithfulness → grounding/verify/model |
| Correct facts, off-question | answer relevancy → prompt/packing |
12. Hands-On Lab
Goal
Build a RAG eval that scores retrieval and generation separately and localizes a failure via the 3-step loop — the Phase 12 discipline applied to RAG.
Prerequisites
- A RAG pipeline (Phase 9);
pip install ragas; a golden set (01) with gold chunks + ground-truth answers + unanswerable cases.
Steps
- Retrieval metrics: run the retriever; compute recall@k + MRR/nDCG vs gold chunks (the ceiling) (Phase 9.05).
- Generation metrics: run the full pipeline; score faithfulness + answer-relevancy with a calibrated judge (Ragas, 02); verify unanswerable questions trigger refusal.
- Localize: pick a wrong answer; apply the 3-step loop (retrieved? → faithful? → relevant?) and bucket it as retrieval vs generation.
- Calibrate: hand-label faithfulness on ~8 examples; compare to the judge; note agreement (02).
- Gate: change chunk size (or remove reranking); re-run; show the metric that moves (the regression gate, 08).
Expected output
A retrieval + generation eval report (quadrant), a localized failure (retrieval vs generation), a judge-calibration note, and a regression-gate before/after.
Debugging tips
- Faithfulness high, users unhappy → check answer-relevancy + recall (right but unhelpful, or missing info).
- recall@k low everywhere → fix retrieval (hybrid/rerank, Phase 9.05/9.06).
Extension task
Compare two pipeline configs (dense-only vs hybrid+rerank) across the full quadrant (Phase 9.05/9.06).
Production extension
Wire the quadrant into a CI gate + online faithfulness sampling feeding the golden set (Phase 9.10, 08).
What to measure
recall@k/precision@k/MRR/nDCG; faithfulness/answer-relevancy; refusal correctness; judge-human agreement; per-change deltas.
Deliverables
- A retrieval + generation eval report (the quadrant).
- A localized failure (retrieval vs generation) + a regression-gate before/after.
13. Verification Questions
Basic
- Why evaluate RAG retrieval and generation separately?
- Name the quadrant metrics and which half each is.
- Why is recall@k the retrieval ceiling?
Applied 4. Map each quadrant metric to the pipeline stage you'd fix. 5. Which metrics are programmatic vs judge-scored, and why?
Debugging 6. An answer hallucinates despite good docs existing. First diagnostic step? 7. Right chunk retrieved but answer still wrong. Where's the bug?
System design 8. Design a RAG eval (golden set with gold chunks, quadrant scorers, CI gate, online feedback).
Startup / product 9. Why does the retrieval-vs-generation split de-risk RAG iteration and product trust?
14. Takeaways
- Separate retrieval from generation — the defining RAG-eval move; localize failures with the quadrant + 3-step loop.
- The quadrant: context recall/precision (retrieval) · faithfulness/answer-relevancy (generation).
- recall@k is the ceiling; retrieval = programmatic IR metrics (gold chunks), generation = calibrated judge (02).
- Most hallucination-despite-RAG is a retrieval miss — check recall first.
- Golden set needs gold chunks + unanswerable cases; gate offline + feed online failures back (Phase 9.10).
15. Artifact Checklist
- A RAG golden set (gold chunks + ground-truth + unanswerable).
- Retrieval metrics (recall@k/precision@k/MRR/nDCG).
- Generation metrics (faithfulness + answer-relevancy, calibrated judge).
- A localized failure (3-step loop) + a regression-gate before/after.
- A CI gate + online feedback plan.
Up: Phase 12 Index · Next: 04 — Agent Evals