Intermediate project

RAG failure clinic

Builds on 3 lessonsabout 1 h 25 min of reading first

In this project

What you need first

Skills you will practise

  • Retrieval
  • Retrieval-augmented generation
  • RAG evaluation
  • Hallucination control
Skip to the tasks

Problem

Learn to diagnose a RAG system the way you would on call. You take a small RAG system that works, break it five ways by following a written fault spec, and for each fault you record the symptom, find the metric that exposes it, name the failing stage with evidence, apply the smallest fix, and show the metric moved.

Requirements

  • A small working RAG system: your RAG eval harness result or one of your own, with 20 to 100 documents you wrote or may use (record the license; no private data). It must already have a group filter inside retrieval, a score gate, and a prompt with a grounding sentence (“answer only from the context”) and a separate refusal sentence; add any that are missing. Two user groups, each document readable by one or both, with a random canary string in each restricted document.
  • Logging of a request id, retrieved chunk ids, their scores and the final prompt for every request.
  • A golden set of at least 20 queries including every required type. The gold for each answerable query is the document plus the exact answer text span (not a chunk id, because Fault 2 changes chunks) and the expected answer. Include at least 5 unanswerable queries, 2 about a fact you will edit, 2 that the two groups should answer differently, 2 where the corpus contradicts common knowledge (for example an unusual refund period), and 2 where an on-topic chunk passes the gate but lacks the specific fact asked for.
  • A baseline measured before any fault, each of eight metrics with its own denominator (for example 3 of 5 unanswerable): span recall@k (a hit is a retrieved chunk containing the whole span; lower is bad), gate refusals on unanswerable queries (higher is better), gate refusals on answerable queries (lower is better), answer correctness and faithfulness on answered queries (lower is bad), abstain correctness (correct refusals, lower is bad; wrong refusals, higher is bad), leaks (two counts: retrieved chunk ids, and canaries in answers; higher is bad), and stale answers (higher is bad). Count leaks by running the whole golden set once as each group: retrieved chunk ids from documents that group may not read (primary) and canaries in answers (backstop), using the chunk-id and canary checks defined in RAG with per-user permissions.
  • The five faults injected one at a time, restoring the baseline between them, each with a diagnosis log.
  • k, the score threshold and the model stay fixed across all runs, except where a fault or its fix changes it.
  • Acceptance, for each fault: the log shows the exposing metric at baseline, with the fault, and after the fix. Metrics computed from retrieval logs (span recall@k, retrieved-id leaks, both gate-refusal counts) return to the baseline value exactly, or better, or differ by a rank tie you can show in the log or confirm by an exact (brute-force) search. Metrics computed from generated answers (answer correctness, faithfulness, abstain correctness, stale answers, answer canaries) return to no worse than baseline by more than your measured noise, in that metric’s bad direction, where noise is the largest difference between two baseline runs at the lowest temperature the model allows, or one query, whichever is larger, per metric. Name every query whose result changed. A fault that moves no metric needs no diagnosis-driven fix; revert it before the next fault. Its log records the queries, how you strengthened the fault (for example allow own knowledge, add 3 more contradiction queries) and the result, and it counts as located. A reported null result is not a fail.

Prerequisites

Tasks

  • To do: Set up the groups, canaries, logging and golden set, and write down the baseline. Run the baseline twice before Fault 1; the second run gives your noise.
  • To do: For each fault: inject it, run the golden set, and fill in the diagnosis log entry.
  • To do: Diagnose using the debugging tree in Better retrieval and the Symptom to stage table below: rank hypotheses by likelihood and cost to check, run the cheapest check first (for example paste the gold passage into the prompt to separate retrieval from generation), and write the evidence.
  • To do: Apply one minimal fix (one diff or commit per fault), re-run the golden set.
  • To do: Re-run the baseline after the last fault and check it matches under the acceptance rule.
  • To do: Draw the which-lane-failed diagram: the two lanes with each fault on its stage.
  • To do: Stretch: write one regression test per fault that fails on the faulty system and passes on the fixed one. Run it against the faulty version to prove it fails.

Fault spec

Starter material is this description only: you write the changes in your own system. Diagnose from the symptom, the logs and the checks you run, not from knowing the fault.

#FaultWhat to changeStage
1Stale indexEdit a fact in one source document, update the expected answers of the affected queries to the new value, and do not re-ingestIngestion
2Bad chunkingRe-ingest with a tiny fixed size, no overlap and no respect for headings, so sentences and tables are cutChunking
3No permission filterRemove the group filter from retrievalRetrieval
4Missing abstainRemove the score gate and the “say you do not know” sentence; keep “answer only from the context”Gate and generation
5Grounding removedRemove only “answer only from the context” and keep the refusal sentence, so the model may answer from what it already knows. The contradiction and lacks-the-fact queries are where it showsGeneration

Diagnosis log

One entry per fault, each field short.

FieldWhat to write
Fault and queryFault number, the query you studied, the fault’s diff or commit, and a prompt, config or log excerpt showing it in effect
Symptom and metricWhat the user sees; metric name, baseline and faulty values, query count, changed queries
Hypotheses and checkTwo or three ranked hypotheses; the check run, the request id and logged lines (ids, scores or prompt excerpt) it showed, and the check that separated the named stage from the one upstream
Failing stageThe earliest broken stage
Fix and metric afterThe single change that puts right what the fault broke (a diff, commit or one step such as re-ingest); the value after, the changed queries after the fix, and whether other metrics held. For a null result: the strengthening and its result

Evaluation

Record real measurements and never invent numbers.

Criterion0123
Baseline and golden setNo baselineBaseline on fewer than 20 queries, a query type missing, or a metric without a denominatorStarting system, corpus size, license, groups, canaries and logging as required; 20 or more queries including every required type; all eight metrics with denominators; the baseline re-run after the last fault matches under the acceptance ruleAs level 2, with the baseline run three times and a noise band per metric
Each fault located with evidenceNo fault located with log evidenceOne to four located with log evidenceAll five located (a null result with the strengthening recorded counts as located). Each entry has the fault’s diff or commit and an excerpt showing it in effect, and quotes raw log lines (request id, chunk ids and scores, or a prompt excerpt) plus the result of a check separating the named stage from the next one upstream (for example the gold passage pasted into the prompt). Earliest broken stage named, cheapest check first, which-lane diagram drawnAs level 2, with faults injected blind (a seeded script or another person), the order recorded after diagnosis, and any wrong first guess kept
Fix minimalNo fix, or a stage rewrittenA fix changes something beyond what the fault broke, or a fault is fixed across more than one diff or step, the acceptance rule fails, or any other level-2 condition not metEach fix puts right exactly what the fault broke, as one diff, commit or single step (for Fault 1, re-ingesting the edited document, keeping the edit and the updated expected answers), with k, threshold and model unchanged except where a fault or its fix changes it, and the acceptance rule holdsAs level 2, plus a regression test per fault that fails on the faulty build and passes on the fixed one
Before and after metricNo metricMetric after only, denominators missing, the acceptance rule missed on any fault, or any other level-2 condition not metThe acceptance rule met for all five faults, changed queries named, and null results reported and re-measuredAs level 2, with a per-query table of baseline, faulty and fixed values for every fault
No fix without a measurementFixes firstSome fixes preceded by a measurementEvery fix follows a logged measurement that pointed at the stage (a fault with a null result needs no fix)As level 2, with the metric change the fix should cause written before applying it

Pass mark: at least 2 on every criterion (so the lowest passing total is 10 of 15).

Architecture

Diagram: The offline lane builds the index and the online lane reads it.

Online lane: every query

Offline lane: indexing

Documents

Chunk

Embed

Index

Query and group

Retrieve with filter

Score gate

Generate with grounding

Fault 1: stale index

Fault 2: bad chunking

Fault 3: no filter

Fault 4: no abstain

Fault 5: grounding removed

Diagram summary: The offline lane builds the index and the online lane reads it. The stale index and bad chunking sit in the offline lane; the missing filter, missing abstain gate and removed grounding sit in the online lane.

Symptom to stage

SymptomLikely stageFirst checkMetric that moves
Old figure or policy, stated confidentlyIngestion (stale index)Is the retrieved chunk the old version? Compare the chunk text with the sourceStale-answer count
Right document retrieved, answer missing or wrongChunkingDoes the retrieved chunk contain the answer, or was it cut?Span recall@k
Another group’s text in an answerRetrieval (filter)Which ids were retrieved, and who may read them?Leak count
Confident answer to an unanswerable questionGate and generationWas any relevant chunk retrieved? Is there a refusal rule?Abstain correctness
Details the chunks never stateGenerationIs the right chunk in the prompt? Does each claim appear in it?Faithfulness, answer correctness
Correct chunk not in the top-kRetrievalWrong query, filter or embedding? Ranked out?Span recall@k

Interview questions

Provenance: Generated practice. Not reported from any company.

  • A wrong answer although the right document is in the corpus: what do you check, in order? Practise with question 35 in the Top 100 priority questions.
  • The chatbot confidently states a policy that does not exist. Practise with S1 in the Scenario-based bank.
  • A document was updated but search returns the old version. Practise with S5 in the Scenario-based bank.
  • Retrieval returned the right chunk and the system still hallucinates. Practise with A1 in the Advanced bank.

Portfolio checklist

  • To do: The README has the baseline metrics with query counts.
  • To do: Five complete diagnosis logs with evidence lines, and a before, faulty and after table.
  • To do: The which-lane-failed diagram.
  • To do: No private data is in the repository.