Generative AI
RAG Evaluation and Debugging
Build a stage-aware RAG evaluation program that covers corpus, retrieval, context, grounding, abstention, latency, and production outcomes.
By the end you can
- Define component and end-to-end metrics for RAG systems
- Create evaluation sets with answerable, unanswerable, contradictory, and permissioned cases
- Use traces to localize corpus, retrieval, reranking, assembly, and generation failures
- Design release gates and regression tests for changing indexes and models
Visual
Start diagnosis at the earliest failed stage
Later fixes cannot repair evidence that never entered the pipeline. An answer passes through six stages, and each one asks its own question. Corpus coverage: does the authoritative answer-bearing source exist and remain usable? Candidate retrieval: did that source enter the high-recall candidate set? Reranking and filters: did authority, permission, or ranking keep the right evidence? Context assembly: did decisive passages survive token budget and ordering? Generation and support: did the answer use the evidence faithfully and abstain when it should? Product workflow: did latency, review, and downstream action produce the intended outcome? Diagnosis starts at the first of those stages that failed, because every later stage inherits the failure.
Context assembly is the stage teams most often treat as neutral plumbing. It is not. A 2024 paper called "Lost in the Middle" ran multi-document question answering and key-value retrieval experiments, and reported where in the window the evidence has to sit: “In particular, we observe that performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models.”
Read that as a debugging instruction. The retriever can succeed, the decisive passage can be inside the prompt, and the answer can still be wrong because of where in the window the passage landed. Buying a long-context model does not remove the effect. Position is therefore a variable your evaluation has to hold fixed and vary deliberately, exactly like the embedder or the top-k budget. A pipeline that logs which passages were assembled, but not in what order, cannot tell a retrieval failure from an ordering failure.
- 1
Corpus coverage
Does the authoritative answer-bearing source exist and remain usable?
- 2
Candidate retrieval
Did the source enter the high-recall candidate set?
- 3
Reranking and filters
Did authority, permission, or ranking keep the right evidence?
- 4
Context assembly
Did decisive passages survive token budget and ordering?
- 5
Generation and support
Did the answer use evidence faithfully and abstain when needed?
- 6
Product workflow
Did latency, review, and downstream action create the intended outcome?
Comparison
Component metrics answer different debugging questions
There is no one “RAG score” that represents the whole system. The clearest demonstration comes from products that were shipped and then measured. The first preregistered empirical evaluation of proprietary RAG-based legal research tools appeared in 2025, in the Journal of Empirical Legal Studies. It tested vendor claims of "hallucination-free" citations, and found this: “we find that the AI research tools made by LexisNexis (Lexis+ AI) and Thomson Reuters (Westlaw AI-Assisted Research and Ask Practical Law AI) each hallucinate between 17% and 33% of the time”. These are retrieval-grounded commercial systems, in a domain with the best corpus in the world. The number that exposes them is a claim-support rate, not an answer-quality rate.
Grounding needs two numbers, not one. A 2023 audit scored four commercial generative search engines — Bing Chat, NeevaAI, perplexity.ai and YouChat — by human evaluation, keeping citation recall and citation precision apart: “on average, a mere 51.5% of generated sentences are fully supported by citations and only 74.5% of citations support their associated sentence”. Half the sentences unsupported and a quarter of the citations misattached are two different defects with two different fixes. A single “grounded?” flag would have averaged them into one meaningless figure.
So instrument three families and keep them apart. Retrieval metrics measure evidence availability: recall at the candidate budget, precision or relevance density, ranking metrics and no-answer behavior, sliced by source, language, and query type. Grounding metrics measure claim support: claim-level entailment, citation correctness and completeness as separate rates in the manner of the 51.5% and 74.5% split, unsupported-claim rate, and conflict and abstention behavior. Workflow metrics measure operational value and cost: latency and token usage, human-review burden, resolution and escalation outcomes, and incidents, appeals, and user corrections.
Retrieval metrics
Measure evidence availability in candidate and selected sets.
- Recall at candidate budget
- Precision or relevance density
- Ranking metrics and no-answer behavior
- Slices by source, language, and query type
Grounding metrics
Measure claim support and citation alignment.
- Claim-level entailment
- Citation correctness and completeness
- Unsupported-claim rate
- Conflict and abstention behavior
Workflow metrics
Measure operational value and cost.
- Latency and token usage
- Human-review burden
- Resolution and escalation outcomes
- Incidents, appeals, and user corrections
Example
A RAG test set needs more than questions and answers
The case metadata determines whether a failure can be interpreted at all. Two of these categories are not optional extras. Abstention and distractor resistance have each been shown to collapse under measurement while ordinary accuracy stayed high, which is why they belong in the frozen set rather than in the postmortem.
- Answer-bearing sources: Identify all known passages that can support a correct answer, so that a wrong answer can be classified as missing evidence rather than guessed at.
- Authority labels: Mark controlling, secondary, stale, contradicted, and inaccessible documents; without them a ranking failure and a policy failure look identical in the trace.
- No-answer cases: The benchmark for this arrived in 2018: over 50,000 unanswerable questions, written adversarially by crowdworkers to resemble answerable ones. A strong neural system that scored 86% F1 on the original SQuAD fell to 66% F1 on them. The authors put the requirement plainly: “To do well on SQuADRUn, systems must not only answer questions when possible, but also determine when no answer is supported by the paragraph and abstain from answering.” Twenty F1 points is what "assume the system abstains" costs you.
- Adversarial distractors: In 2017 Jia and Liang inserted one distractor sentence into a SQuAD paragraph — a sentence that does not change the correct answer and does not mislead humans. “In this adversarial setting, the accuracy of sixteen published models drops from an average of 75% F1 score to 36%; when the adversary is allowed to add ungrammatical sequences of words, average accuracy on four models decreases further to 7%.” A reranker that admits one topic-similar passage is running that experiment on your users. Include negations, injected instructions, and false citations alongside the topic-similar text.
- Temporal cases: Evaluate policy versions and facts that changed after earlier documents, so that a confidently stale answer is scored as the failure it is.
- Workflow expectations: Specify the required clarification, abstention, escalation, and tool behavior per case; an abstention that should have been an escalation is a distinct defect from an answer that should have been an abstention.
A trace should reproduce every evidence decision
Store the normalized query, filters, candidate IDs, scores, reranking features, selected spans, context order, prompt version, model version, citations, and validation results. Sensitive content can be protected or sampled under policy. Context order earns its place on that list on the evidence above: if the position of a passage inside the window can move an answer, a trace that records the selected spans but not their sequence has thrown away the variable that explains the failure.
Without a stage trace, teams tune prompts to compensate for corpus and retrieval failures. That can improve a demo while leaving the underlying evidence gap untouched. It can also produce the pattern the legal-tools audit found, where the answers look like research and the citations do not hold. A trace is what lets you say which of the two happened.
Key idea
Automated graders need calibration against human judgment
Grading with a model scales checks for relevance, support, and style. That same model can share the generator's biases, prefer verbosity, or be fooled by citation form. Use clear rubrics, blind comparisons, human-reviewed calibration sets, and disagreement analysis.
Ragas shows what calibration reveals when it is actually run. Presented in 2024, it scores three reference-free dimensions: faithfulness, answer relevance and context relevance. Its authors validated them on WikiEval, a dataset they built from 50 Wikipedia pages covering post-2022 events. Agreement with human annotators in pairwise comparisons was 0.95 for faithfulness, 0.78 for answer relevance and only 0.70 for context relevance, against baselines of 0.72/0.52/0.63 for GPT Score and 0.54/0.40/0.52 for GPT Ranking. The authors say so themselves: “We found context relevance to be the hardest quality dimension to evaluate.” One grader, three dimensions, and a 0.95 next to a 0.70. A single averaged "Ragas score" would hide exactly the dimension your failure tree needs most: retrieval relevance. Reference-free is not judgment-free, because the components doing the scoring are themselves models.
KILT took the older route to comparability. Petroni and twelve co-authors published it in 2021. It grounds eleven datasets across five tasks in one fixed knowledge source — the 2019/08/01 Wikipedia snapshot, containing 5.9M articles — and scores systems on their ability to return provenance pages as well as on downstream answers: “The KILT benchmark consists of eleven datasets spanning five distinct tasks, and includes the test set for all datasets considered.” A dated snapshot and a counted corpus are what shared provenance costs. Two RAG results measured over two different corpora are not comparable at all, however carefully each was scored.
A scalable evaluator is useful only after its judgments are compared with the standard the product actually trusts.
Steps
Create a RAG release gate
Require evidence from both frozen tests and fresh production-shaped cases. Freeze a protected set first, so that prompt and retriever tuning cannot reach the final gate. Score each stage separately — corpus, candidate recall, selection, grounding, workflow outcomes — rather than reporting one average. Inspect the critical slices: authority, time, language, tenant, risk, and no-answer behavior. Then calibrate the graders, run change attribution to identify which corpus, index, model, prompt, or policy version moved, and define rollback and reindexing so that compatible components can be restored while incident evidence is preserved.
Step 4 is the one with public evidence behind it. The TREC 2024 RAG Track deployed four relevance-assessment approaches in situ, across 77 runs from 19 teams: NIST's decades-old fully manual process, and three LLM-based variants using the open-source UMBRELA tool. UMBRELA's automatic judgments correlated highly with fully manual assessments at run level, on nDCG@20, nDCG@100 and Recall@100. Human assessors applied relevance criteria more strictly than UMBRELA did. The hybrid middle did not pay: “Surprisingly, we find that LLM assistance does not appear to increase correlation with fully manual assessments, suggesting that costs associated with human-in-the-loop processes do not bring obvious tangible benefits.” Two of the eight authors, Soboroff and Dang, are NIST staff, and NIST lists the paper in its own publication record.
That result tells you what an automated judge may decide, and what it may not. Ranking candidate configurations against each other at run level is a decision the evidence supports. Judging whether one particular passage is relevant is not. Neither is setting an absolute pass threshold on a strictness the grader applies more loosely than your reviewers do. A high-stakes release gate should not rest on an unvalidated grader alone.
1. Freeze a protected set
Prevent prompt and retriever tuning on the final gate.
2. Score each stage
Corpus, candidate recall, selection, grounding, and workflow outcomes.
3. Inspect critical slices
Authority, time, language, tenant, risk, and no-answer behavior.
4. Calibrate graders
Compare automated scores with qualified human review.
5. Run change attribution
Identify which corpus, index, model, prompt, or policy version moved.
6. Define rollback and reindexing
Restore compatible components and preserve incident evidence.
A RAG system is ready when its failures are locatable
A high average answer score is not enough if the team cannot tell missing evidence from poor ranking or unsupported synthesis. Every number in this lesson exists because someone measured a stage instead of an average. 51.5% against 74.5% separated support from attachment. 86% F1 falling to 66% separated answering from abstaining. 75% F1 falling to 36% separated comprehension from distractor resistance. 0.95 against 0.70 separated a grader's strong dimension from its weak one. In each case the coarser metric would have reported a system that worked.
Stage-aware evaluation turns the system into something that can be improved deliberately. The next lesson compares prompting, retrieval, tools, and fine-tuning. Diagnosis should determine which mechanism changes, not fashion or vendor defaults.
Key takeaways
- RAG debugging begins at corpus coverage and follows the evidence through retrieval, selection, assembly, generation, and workflow outcomes. Position inside the context window is one of those variables: accuracy is highest at the beginning or end and degrades in the middle, even for explicitly long-context models.
- Grounding needs at least two rates, not one. The audit of four generative search engines found only 51.5% of sentences fully supported by their citations, and only 74.5% of citations supporting the sentence they were attached to.
- Abstention and distractor resistance are separately measurable capabilities. Over 50,000 adversarially written unanswerable questions took a strong system from 86% F1 to 66% F1, and one inserted distractor sentence took sixteen published models from 75% F1 to 36%.
- Stage traces must record context order and every component version. Otherwise prompt tuning will keep masking upstream evidence failures.
- Automated graders need per-dimension calibration. Ragas agreed with human annotators 0.95 of the time on faithfulness but only 0.70 on context relevance, which its authors called the hardest dimension to evaluate.
- Release gates should freeze a protected set, score each stage, and bound what the grader may decide. TREC 2024 RAG Track evidence supports run-level ranking by automated judgments, not the stricter per-passage calls human assessors make.