Sub topic 13
Finding out whether the retriever or the generator is at fault
This chapter assumes you can compute recall@k and faithfulness as covered earlier. It shows how to combine them to decide which component to fix when an answer is bad.
Why one score is not enough
A bad answer has two common causes. The retriever may have missed the passage that holds the answer. Or the retriever found it and the generator ignored it, misread it, or added claims of its own. These need different fixes: chunking, embeddings, or reranking for the first, and prompts, model choice, or decoding settings for the second. If you tune the wrong component, you spend effort and see no improvement.
The basic test
For each failing question, check retrieval first, then generation.
- Did any labelled relevant document appear in the top k? If not, call it a retrieval failure. The generator never had the facts.
- If one did, is the answer faithful to the context? If faithfulness is low, call it a generation failure. The facts were available.
- If both pass but the answer is still wrong, suspect the labels, the question, or a missing document.
A small diagnosis function
from collections import Counter
def diagnose(retrieved_ids, relevant_ids, faithfulness, k=5, threshold=0.8):
hit = any(d in relevant_ids for d in retrieved_ids[:k])
if not hit:
return "retrieval"
if faithfulness is not None and faithfulness < threshold:
return "generation"
return "ok"
cases = [
(["d7", "d2"], {"d2"}, 1.0),
(["d7", "d8"], {"d2"}, 0.9),
(["d2", "d7"], {"d2"}, 0.4),
(["d2", "d1"], {"d2"}, None),
]
print(Counter(diagnose(r, rel, f, k=2) for r, rel, f in cases))
# Counter({'ok': 2, 'retrieval': 1, 'generation': 1})Run this over the whole evaluation set, not only the failures. The counts show where most problems sit. If most failures are retrieval, improving the prompt will not help much.
Two traps
Low faithfulness can hide a retrieval failure. When the context lacks the answer, a model often fills the gap from its own memory. Those claims are unsupported, so faithfulness drops. The function above avoids this because it checks retrieval first. Always apply the checks in that order.
The opposite trap is high faithfulness on a useless answer. A generator can faithfully summarize irrelevant passages. Faithfulness only says the answer matches the context. Pair it with answer relevance and a retrieval check.
Confirming with an oracle run
To confirm a diagnosis, change one component and hold the other fixed.
- Oracle context: give the generator the labelled relevant passages instead of retrieved ones. If answers are still poor, the generator is the problem. If they improve a lot, retrieval was the bottleneck.
- Fixed generator, new retriever: swap the retriever and keep the prompt and model the same. Compare the same questions in both runs.
| Retrieval hit | Faithfulness | Likely cause |
|---|---|---|
| No | Low | Retriever, with the model guessing |
| No | High | Retriever, with an answer that is faithful but off-topic |
| Yes | Low | Generator |
| Yes | High | Labels, data, or question ambiguity |
When labels are missing
Without relevance labels, use judge-based context relevance instead of the hit check. Ask a judge whether the retrieved passages contain what the question needs. This is noisier, so spot-check some verdicts by hand before trusting the split.
Exercise
A question has a labelled relevant document at rank 9. You use k=5 and the answer has faithfulness 0.3. Which component do you blame first, and why?
Show answer
The retriever. The relevant document is outside the top 5, so the generator never saw it. The low faithfulness probably comes from the model filling the gap with its own knowledge. Fix retrieval (for example with reranking or a larger k) and re-measure before changing the prompt.