A wrong RAG answer is not a diagnosis. Before changing the prompt, find out whether the right evidence existed, whether it survived retrieval and context assembly, and whether the answer used it. Those are different failures with different owners.
One trace, four questions
Consider the fictional HarborDesk help center, frozen at corpus version v7. The following is a deliberately small replay, not a vendor benchmark or a real customer dataset. A document is a source page; a chunk is an indexed passage within it. Only current, authorized chunks count as answer evidence.
| Document / chunk | Version and access | Passage |
|---|---|---|
| RET / RET-a | v7, public | Unopened items may be returned within 30 days of delivery. |
| RET / RET-b | v7, public | A return request must include the order receipt. |
| DMG / DMG-a | v7, public | Report damaged items within 60 days of delivery. |
| DMG / DMG-b | v7, public | Attach photos of the damaged item and packaging. |
| SHIP / SHIP-a | v7, public | Domestic standard shipping usually takes five days. |
| RET / RET-old | v6, archived; ineligible | Unopened items may be returned within 14 days. |
The frozen relevance labels below name chunks, not merely pages. RET-a and RET-b share a document ID but answer different questions. The displayed ranked lists are the replay's raw retrieval outputs before the required version filter; they are not claims about an embedding model. The diagnostic raw-list metric below fixes k at 2; the separate, deliberately faulty answer trace sent three raw passages for Q1 (including RET-old), but only two for Q2 and Q3. A correctly configured system would filter archived passages before assembly; the inconsistent context packing is visible rather than assumed away.
| Case / question | Relevant v7 chunks (labels) | Raw ranks 1 → 3 | Observed answer / diagnosis |
|---|---|---|---|
| Q1: How long can I return an unopened item? | RET-a | SHIP-a, RET-a, RET-old | “14 days.” RET-a was retrieved at rank 2, but the answer followed an archived passage: version-filter and answer-evidence failure. |
| Q2: When and with what evidence do I report damage? | DMG-a, DMG-b | DMG-a, SHIP-a, DMG-b | “Within 60 days.” Supported but incomplete: the photos requirement is at rank 3, outside a two-chunk context budget. |
| Q3: What must a return request include? | RET-b | SHIP-a, RET-old, RET-a | “A receipt.” Correct-looking but unsupported by the retrieved passages; RET-b exists in the index but was missed. |
| Q4: How long does international shipping take? | None in v7 | SHIP-a, RET-a, DMG-a | “Five days” would misuse domestic evidence. The defensible answer is that this corpus does not specify international transit time. |
First inspect the source inventory and access policy. If the required passage is not in the authorized current corpus, ingestion or source ownership—not ranking—is the problem; do not create a relevance label for a nonexistent answer. If it exists but never appears in the candidate pool, inspect indexing, filters, query rewriting and lexical/vector matching. If it appears below the context cutoff, inspect ranking and the chunk boundary or context budget. Q2 demonstrates why a document-level hit on DMG is not enough: one of its two required passages was excluded.
Calculate retrieval before judging prose
Use the three answerable cases Q1–Q3 for retrieval metrics; Q4 is a separate abstention test with no positive relevance label. At k = 2, Q1 has 1/1 relevant chunks, Q2 has 1/2, and Q3 has 0/1. Macro recall@2 = (1 + 1/2 + 0) / 3 questions = 0.5. Hit@2 = 2/3 questions ≈ 0.667, because either of Q2’s required chunks constitutes a hit; hit does not imply complete evidence. First relevant ranks through 3 are 2, 1, and absent. MRR@3 = (1/2 + 1/1 + 0) / 3 questions = 0.5. This conventional MRR credits the first relevant chunk only, so it cannot show the missing second requirement in Q2. Q1’s archived rank-3 chunk is never relevant despite lexical similarity. These values describe this fabricated fixture alone.
Here is the entire standard-library replay. Save the code as rag_replay.py and run python rag_replay.py. The rankings are explicit captured fixtures so the computation can be audited; this is not a production retriever or a model evaluation.
# Fictional HarborDesk v7; raw chunk rankings before version/access filtering.
chunks = {
"RET-a": ("RET", "v7", "public"),
"RET-b": ("RET", "v7", "public"),
"DMG-a": ("DMG", "v7", "public"),
"DMG-b": ("DMG", "v7", "public"),
"SHIP-a": ("SHIP", "v7", "public"),
"RET-old": ("RET", "v6", "archived"),
}
questions = {
"Q1": ({"RET-a"}, ["SHIP-a", "RET-a", "RET-old"]),
"Q2": ({"DMG-a", "DMG-b"}, ["DMG-a", "SHIP-a", "DMG-b"]),
"Q3": ({"RET-b"}, ["SHIP-a", "RET-old", "RET-a"]),
"Q4": (set(), ["SHIP-a", "RET-a", "DMG-a"]),
}
k = 2
recalls, hits, reciprocal_ranks = [], [], []
for name, (gold, ranked) in questions.items():
assert all(cid in chunks for cid in gold | set(ranked))
assert len(ranked) == len(set(ranked))
assert all(chunks[cid][1:] == ("v7", "public") for cid in gold)
print(name, "raw:", ", ".join(ranked))
if not gold: # No answer in this corpus: test abstention separately.
continue
found = gold.intersection(ranked[:k])
first = next((i for i, cid in enumerate(ranked[:3], 1)
if cid in gold), None)
recalls.append(len(found) / len(gold))
hits.append(bool(found))
reciprocal_ranks.append(1 / first if first else 0)
print(" recall@2:", f"{len(found)}/{len(gold)}",
"first relevant rank:", first)
n = len(recalls)
print("macro recall@2:", sum(recalls) / n)
print("hit@2:", sum(hits), "/", n)
print("MRR@3:", sum(reciprocal_ranks) / n)
assert n == 3
assert (sum(recalls) / n, sum(hits), sum(reciprocal_ranks) / n) == (0.5, 2, 0.5)
The raw trace itself exposes a separate policy defect: RET-old reached Q1 and Q3. Recompute an eligible-only ranking after removing archived or unauthorized chunks, and flag any such chunk reaching the model. Do not silently treat a filtered rank as the original rank or turn a permission leak into a retrieval success. For real runs, retain query, user access scope, corpus and index version, chunk-to-document map, query rewrite, raw candidates with scores, post-filter ranks, final prompt context (including truncation), answer and cited spans. A restricted chunk must not enter the context even if it would improve the numerical score.
Then inspect claims and omissions
Review an answer against the actual final context, not the full corpus. Break it into checkable claims and attach the supporting chunk and quoted span. Q1’s “14 days” is contradicted by RET-a and only appears in archived RET-old: its citation would not make it valid. Q3’s “a receipt” matches the current source of truth in RET-b, but is not grounded in its retrieved context; a lucky answer is still a retrieval miss. For Q2, “within 60 days” is entailed by DMG-a, so it is grounded as far as it goes, but it omits the required photos from DMG-b. Record both checks separately: supported claims 1/1, required answer elements 1/2. If the final context actually contains both chunks yet the answer still omits photos, assign the failure to generation or instruction/formatting, not retrieval. If DMG-b was dropped before generation, fix rank, context packing or budget first.
The no-answer Q4 should be assessed against an explicit abstention expectation, not placed in a recall denominator with zero relevant chunks. If the user’s access role cannot see the only supporting page, the correct behavior is likewise to decline or explain the access-limited evidence, not retrieve around the restriction. When sources conflict, define which version and authority wins before labeling; a newer timestamp alone need not make a draft policy authoritative.
| Observed branch | Confirm with | Next change |
|---|---|---|
| Source absent or stale | Current authorized inventory lacks expected passage, or retrieved version differs | Repair ingestion/version policy and relabel against the approved source; abstain meanwhile. |
| Indexed but no candidate | Gold chunk exists, absent from raw candidate list | Test filters, query rewriting and indexing; compare a diagnostic exact-match query. |
| Candidate below cutoff or split evidence | Gold at rank > k, or one required chunk dropped in final context | Tune ranking/chunking and context packing; inspect multi-chunk recall, not document hit alone. |
| Good context, unsupported assertion | Claim lacks an entailing span in the final context | Constrain generation and citation behavior; reject unsupported claims. |
| Good context, supported but incomplete answer | Expected elements are present in context, but omitted in answer | Revise answer instructions and test element coverage; do not blame recall. |
| Unauthorized or unanswerable request | Only restricted evidence exists, or no qualifying evidence exists | Enforce access controls and abstention; log the unsupported request for source owners. |
Use evaluators without confusing their names
Microsoft’s RAG evaluators documentation separates label-based DocumentRetrievalEvaluator (including NDCG, XDCG, fidelity and missing-label “holes”) from the LLM-judged RetrievalEvaluator for textual relevance when query-specific relevance labels are unavailable. Its GroundednessEvaluator compares a response with grounding context; ResponseCompletenessEvaluator compares it with an expected response. Neither the hand-computed recall@2 nor MRR@3 above is represented as a Microsoft evaluator score.
The Ragas evaluation guide describes context_precision and context_recall for retrieval, faithfulness for answer consistency with context, and answer_relevancy for question relevance; its example uses question, contexts and ground-truth answers and notes that some metrics use an LLM. Do not substitute its context-recall score for the chunk-ID macro recall calculated here, or call faithfulness answer completeness.
For consequential uses, calibrate any LLM judge on a small human-adjudicated set: include archived citations, partially complete answers, answerable-but-unretrieved evidence and unanswerable questions; compare disagreements by category and revisit labels after policy changes. Hold out new questions when tuning ranking or prompts. A judge score can triage cases, but it cannot establish that a document was authorized, that the source inventory was complete or that an invented-looking citation actually entails its claim. The trace and source-of-truth decision remain the audit record.
