RAG Quality Evaluation: Stage-Level Metrics and Failure Attribution
Retrieval-augmented generation (RAG) quality cannot be judged by sending a question to a model and checking whether the answer looks fluent. This article presents a stage-level evaluation and failure-attribution framework for RAG systems. It covers how to build a reusable evaluation set, how to measure retrieval with gold labels using precision@k, recall@k, MRR, hit rate@k, and NDCG, how to use sampling and proxy signals when labels are unavailable, what to evaluate on the generation side, and how to combine end-to-end and segment-level metrics for regression testing and governance. It also explains common misjudgments, debugging order, and practical actions for assigning quality drops to the correct stage.
Retrieval-augmented generation is not about throwing a question into a model and seeing whether the answer looks acceptable. A usable RAG pipeline includes at least these stages: the query enters the system, candidate passages are retrieved, passages are ranked by relevance and truncated to the context window, the model organizes an answer from those passages, and business rules apply format and safety constraints. If any stage distorts the signal, the final text may look fluent but remain unusable. When the whole pipeline is scored as a black box, teams often default to changing prompts when scores drop. As a result, contradictory material mixed in by retrieval, overly fragmented chunking, and ranking misalignment are all blamed on the generation side.
The first principle of evaluation is to split the pipeline into stages and then attribute failures. The retrieval side answers: “Did we find all relevant material, rank it accurately, and how much of the window is occupied by noise?” The generation side answers: “Are the statements supported by the given context, are they on topic, and does the model still fabricate when it should refuse?” The end-to-end layer answers: “Compared with a reference answer or business acceptance criteria, is the final conclusion correct?” All three segments can be observed at the same time, but optimization actions must correspond to the segment that actually lost points.
Build a reusable evaluation set
Without stable samples, metrics only drift with the questions of the day. The evaluation set should cover at least: factual queries, multi-hop synthesis, policy or version questions that require comparison, boundary questions where the knowledge base has no answer, and near-duplicate documents that are easy to confuse. Each sample should retain the original query phrasing, the expected conclusion or acceptable answer points, and optional gold passage identifiers. A gold passage does not need to be the only possible wording, but it must be possible for both humans and models to consistently judge that the passage is sufficient to support the conclusion.
The chunking strategy itself is an evaluation target. If the same policy is split into overly short sentences, individual passages often lack applicable conditions and exceptions. If it is split into overly long passages, irrelevant clauses are brought into the window. The evaluation set should fix the chunking version; otherwise retrieval metrics and generation metrics cannot be compared across runs. Query rewriting, synonym expansion, and filter conditions should also be versioned, so that “recall improved today” is not merely the result of a filter rule changing quietly.
Retrieval evaluation with gold labels
Having a set of queries with labeled relevant passages is the cleanest condition for retrieval evaluation. Ranking metrics long used in information retrieval remain applicable; they should not be abandoned just because generation models have been updated. They measure the quality of the context sent to the model, not writing style.
Precision@k looks at how many of the top k results are relevant passages, calculated as the number of relevant items divided by k. The value of k should be close to the number of passages actually sent to the model or the equivalent token budget. If k is 10 and only 3 passages are relevant, the other 7 occupy attention and context length, making it easier for the model to compromise among irrelevant clauses. This metric directly explains “why the answer is full but not grounded”: the proportion of noise in the window is too high.
Recall@k looks at how many of all relevant passages enter the top k. In knowledge question answering, missing a key exception clause is more dangerous than including an extra background note. High precision with low recall usually means ranking is too aggressive or the query is too narrow; high recall with low precision means retrieval is too broad and reranking is insufficient.
Mean reciprocal rank focuses on how early the first truly relevant result appears. Hit rate@k only checks whether at least one relevant item appears in the top k. It is suitable for simple fact questions where “finding any supporting evidence is enough to answer,” but it hides multi-evidence tasks. Normalized discounted cumulative gain considers both relevance grade and position; relevant passages score higher when they appear earlier, making it suitable for scenarios labeled with strong and weak relevance grades.
These metrics should not be interpreted as a mixed bag. Without a fixed k and a fixed relevance definition, teams will mistake “retrieving more marginal material” for a quality improvement. The operational definition of relevance must be written clearly: whether a passage can independently support the conclusion, or whether it is merely topically similar. A passage on the same topic but from a different policy version should be judged irrelevant or even harmful in a business context.
Without gold labels, do not force ranking formulas
Many enterprise knowledge bases do not have time for item-by-item labeling. At this point, still calculating precision@k treats the unknown as known, and the conclusion is unreliable. A feasible alternative is sampling and proxy signals, with their biases stated explicitly.
Manual spot checks remain the anchor. Stratified sampling by business line and query type allows people familiar with the policy to judge whether the top k passages are sufficient for answering and whether stale or conflicting versions are mixed in. The sample can be small, but it should be stable and repeated so that trends are visible.
A model can be used as an auxiliary judge, but the judge model must not also serve as the generation model under test without constraints; otherwise it tends to approve its own output. A safer approach is to let the judge only decide whether a passage contains the facts necessary to answer the question, output supported, partially supported, or unsupported, and require the original sentence location in the passage to be cited. Judge results should be calibrated regularly against a human subset for agreement rate. When agreement drops, stop using the automatic score first, and do not use it to drive launches.
During the unlabeled stage, behavioral proxies can also be monitored: empty-recall rate, duplicate passage rate, the rate at which different versions of the same document enter the top k together, average passage length, and whether the remaining tokens after filtering frequently fill the window. These are not accuracy rates, but they can explain why the generation side suddenly gets worse. For example, when clauses from two versions are retrieved at the same time, the model writes “overall” under mutually negating premises; faithfulness scores remain low, but the root cause lies in retrieval and version governance.
What to evaluate on the generation side
Generation evaluation must be conducted under the premise of “given this retrieval context.” It should not use a reference answer to scold the model for not memorizing it. If the context contains no supporting evidence, the model should receive credit, not a penalty, for refusing to answer or declaring that the information is insufficient.
Faithfulness checks whether the atomic statements in the answer are supported by the context. The approach is to split the answer into checkable short sentences: whether the subject, condition, number, time, and exception can all be found in the passages, and whether a condition from document A has been applied to a conclusion from document B. In contradictory contexts, if the model writes a third compromise statement, it should be judged unfaithful, and the case should be fed back to the retrieval side instead of spending consecutive days only changing prompts.
On-topicness checks whether the answer addresses the decision the user actually needs, rather than stacking relevant paragraphs. If the user also asks about the applicable object, merely restating a definition is not on topic. Completeness checks whether key points are covered, but completeness is capped by “the points present in the context,” to avoid encouraging the model to fill in details outside the knowledge base.
Conciseness, format compliance, and citation traceability can be listed separately. Citations should point back to a passage identifier or section, not merely say “according to the materials.” A fluent answer that cannot be traced should be treated as a failure in compliance-sensitive scenarios.
Noise sensitivity can be stress-tested separately: in addition to fixed gold passages, inject topically similar but inapplicable passages at a certain ratio and observe whether the conclusion drifts. A low drift threshold indicates that the generation strategy over-synthesizes; this does not replace the work of improving retrieval precision.
Using end-to-end and segment metrics together
End-to-end metrics answer whether the business can use the output: agreement with reference points, accuracy of key fields, refusal rate when refusal is appropriate, and human acceptability rate. They are suitable for release gates, but not for guiding which layer to change by themselves.
For each regression, record three groups of numbers together: retrieval precision@k and recall@k on the labeled subset; conflict-version mix rate and manual spot-check pass rate on the unlabeled subset; generation faithfulness and on-topicness; and end-to-end acceptability. When metrics drop, locate the cause in order: first check whether recall missed gold passages; then check top-k noise and version conflicts; after confirming that the context is sufficient and free of contradictions, check prompts, citation format, and decoding parameters. Strengthening “must answer” when context is insufficient only increases fabrication.
A simplified statistical method can be fixed in the evaluation script to avoid metric-definition drift:
def precision_at_k(retrieved_ids, golden_ids, k):top = retrieved_ids[:k]if k == 0:return 0.0hit = sum(1 for i in top if i in golden_ids)return hit / kdef recall_at_k(retrieved_ids, golden_ids, k):if not golden_ids:return 0.0top = set(retrieved_ids[:k])hit = sum(1 for i in golden_ids if i in top)return hit / len(golden_ids)
The script only solves metric consistency; it cannot replace relevance definitions. The gold set, k, chunking version, and query-rewrite version must be archived together with the scores.
Common misjudgments and governance actions
Misjudgment 1: When faithfulness remains low, add longer prompts and slogans such as “strictly prohibit fabrication.” If retrieval bundles passages from different regulations or different effective dates, the model has no single object to be faithful to, and slogans are ineffective. First apply version, effective-scope, and document-type filters, then rerank.
Misjudgment 2: Pursue only recall and set k very large. After the window is diluted, end-to-end accuracy often rises first and then falls. Use precision, conflict rate, and answer drift together to find the knee point of k.
Misjudgment 3: Replace segment-level scores with a single composite score. A composite score is convenient for reporting but leaves responsibility unclear. Externally, report end-to-end acceptability; internally, segment-level metrics must be retained.
Misjudgment 4: Evaluation queries are all written standard questions, while production traffic is colloquial, uses pronouns, and omits information across turns. Include both pre-rewrite and post-rewrite queries from real conversations in the set, and evaluate “original-query retrieval” and “rewritten-query retrieval” separately.
For governance, retrieval comes first: chunking and title hierarchy, metadata filtering, deduplication, version mutual exclusion, and whether reranking features include applicability scope. Generation comes second: atomic answers, refusal when unsupported, citation binding, and explicitly listing differences when conflicts occur instead of compromising. End-to-end evaluation is for final acceptance and does not replace the first two segments.
Evaluation is not a single exam before launch; it is a regression process that runs on the same cadence as index construction, chunking, reranking, and prompting. Change only one factor at a time and rerun the same evaluation set, so that the score change can be traced to a specific segment. By accounting separately for “whether retrieval found everything and ranked it correctly” and “whether the answer is supported and on topic,” final answer correctness gains an actionable improvement path.
