RAG system evaluation: diagnosing retrieval and generation failures
A RAG failure has two distinct causes: the retrieval stage returned the wrong context, or the generation stage ignored or misread good context. You need to evaluate both sides separately to know which one to fix.
By Arun PrasadPublished
On this page
Why RAG failures are hard to diagnose
A RAG system returns a natural-language reply no matter what went wrong upstream. Whether the retriever pulled the wrong chunk or the model invented an answer over a good one, the user sees the same thing: a wrong answer, delivered confidently.
This is the core problem with standard monitoring for RAG agents. A span can return 200 and the task can still fail. Latency and error rate tell you the request went through, not whether the answer was right or whether the retrieved context had anything to do with it.
The two failure surfaces are genuinely different:
- Retrieval failures: the right information was never in the context window. The model had nothing to work with. No amount of prompt tuning fixes this.
- Generation failures: the right information was retrieved, but the model ignored it, misread it, or added claims the context doesn't support. Fixing the retriever changes nothing here.
Because both failures look identical to the user, teams often apply the wrong fix. They rewrite the prompt when the Knowledge Base has a gap, or they rebuild the index when the model is the one hallucinating. Treating them as the same problem wastes time and leads to changes that don't hold.
The only way to tell them apart is to record both sides of the pipeline and score them separately.
Step 1: Separate the pipeline into two checkpoints
Before you can evaluate retrieval and generation separately, you need to record them separately. The goal is a trace where the retrieval step and the generation step appear as distinct spans with their own inputs and outputs.
For each request, capture:
- Retrieval span: the query sent to the retriever, the chunks returned, and their relevance scores.
- Generation span: the prompt sent to the model (including the retrieved context), the model's reply, and latency.
With those two spans in your trace, you can evaluate each stage against its own criteria without having to guess at what went wrong after the fact.
If you're using the PRISM by Block Convey Python SDK, attaching a framework handler sends full trajectories, model calls, tool calls, retrieval steps, handoffs and errors, so the retrieval span appears automatically alongside the generation span in Agent Runs. If you're sending traces over HTTP, include retrieval context in the metadata field so evaluators can read it. See the PRISM integrations page for setup options.
Step 2: Evaluate retrieval quality
Retrieval evaluation answers whether the right information was retrieved and ranked high enough to be used. Use context precision and context recall to measure retrieval quality separately from generation.
Retrieval evaluation answers three questions: did the right chunk appear in the results, did it rank high enough to actually be used, and was anything relevant returned at all?
Two metrics cover this:
- Context precision: of the chunks the retriever returned, how many were actually relevant to the question? A low score means the retriever is noisy, it found some things, but mostly the wrong things.
- Context recall: of the relevant content that exists in the Knowledge Base, how much did the retriever find? A low score means the retriever missed information that was there.
Both metrics can be computed as deterministic rules (same verdict for the same input, no model involved) or as LLM-as-judge rules that read the exchange. Deterministic checks run on 100% of your sessions with no sampling, so they catch retrieval gaps consistently rather than only on the fraction of traces you happen to inspect.
When you write an evaluator for retrieval quality, the {context} placeholder in the rubric holds what the trace's retrieval steps returned, up to about 6,000 characters, so the judge can compare it against the user's question directly. See AI Agent Evaluation and Quality Checks for how to set up retrieval evaluators.
Step 3: Evaluate generation faithfulness
Generation evaluation answers whether the model used retrieved context correctly or added unsupported claims. Use faithfulness and answer relevance to measure how well the model grounds its reply in the retrieved context.
Generation evaluation answers a different question: given that the model received relevant context, did it use it correctly?
Two metrics cover this:
- Faithfulness: does each claim in the model's reply trace back to something in the retrieved chunks? A low score means the model is adding information the retrieval step never provided, hallucinating over the context.
- Answer relevance: does the reply actually address the user's question? A model can be fully faithful to its context and still produce an answer that sidesteps what was asked.
Both are well-suited to an LLM-as-judge evaluator, because they require reading the reply and the context together and making a judgement call that is difficult to express as a fixed rule.
In an evaluator rubric, {input} is the user's last message, {output} is the agent's final answer, and {context} is what the trace's retrieval steps returned. That gives the judge everything it needs to check whether the model's claims are grounded.
Step 4: Classify each failure as retrieval or generation
Once you have retrieval and generation scores on the same trace, the classification is straightforward: low retrieval scores mean fix the index; low generation scores with good retrieval mean fix the prompt.
With retrieval scores and generation scores on the same trace, the classification is straightforward:
| Retrieval scores | Generation scores | What it means |
|---|---|---|
| Low | Any | Retrieval problem. Fix the index, chunking, embedding, re-ranking, or Knowledge Base coverage. |
| Fine | Low | Generation problem. Fix the prompt, context window handling, or model behavior. |
| Fine | Fine | The answer was wrong for another reason, evaluate the user's goal, not just the retrieved content. |
This distinction matters because the fixes are completely different. A retrieval problem might mean your chunks are too large, your embedding model doesn't match your query style, or your Knowledge Base simply doesn't cover the topic. A generation problem might mean your system prompt isn't clear about how to use context, the context window is too crowded, or the model is ignoring instructions.
Root cause analysis can help here. When failing traces cluster into recurring patterns, you can see whether the common factor is a missing source, a retrieval gap, or a prompt instruction, and that points directly at the right fix. PRISM's AI Remediation clusters failing traces into recurring problems and traces each one back toward the prompt or code responsible, naming the likely cause: missing source, retrieval, stale state, tool choice, prompt, parameter, or workflow step.
Step 5: Turn failures into regression tests
Once a failure pattern has a root cause and a fix, convert it into a reusable check that runs against future builds. On Growth and above, turn an Issue into an evaluator check so the same failure can't ship again.
Fixing a retrieval or generation failure is only half the work. The other half is making sure it doesn't come back silently after the next deploy.
Once a failure pattern has a root cause and a fix, convert it into a reusable check that runs against future builds. On Growth and above, an Issue in PRISM can become an evaluator check with one action, and from that point on, your CI pipeline can run every check before you ship.
The request looks like this:
Example
POST /api/intelligence/checks/run?project_id=<your-project-id>
X-PRISMtrace-Key: <key-with-read-and-operate-scopes>
{
"build": "<your-commit-sha>",
"replies": [
{"input": "What is the refund window?", "output": "Refunds are accepted within 30 days."}
]
}PRISM judges each reply against each check and returns passed, failed, unchecked, and credits_charged. If any reply fails any check, passed is false and the build can be blocked. At most 50 replies per call; nothing is stored. A project with no checks returns 409.
After a fix is merged, PRISM also compares pass rates for the 7 days before and the 7 days after the merge, so you have a before-and-after view of whether the fix held in production traffic.
How this looks in production
Here is the diagnostic loop in concrete terms, using a customer-support RAG agent as an example.
What PRISM records
When a user asks "What's the return policy for items bought with a promo code?", the agent runs a retrieval step and a generation step. In PRISM's Agent Runs view, those appear as distinct spans: the retrieval span shows the query, the chunks returned and their scores; the generation span shows the prompt, the model's reply, latency and token counts.
The evaluator fires
An LLM-as-judge evaluator with a faithfulness rubric runs on arrival, up to the plan's daily ceiling. The rubric reads:
Does every claim in {output} appear in {context}? Flag any claim that the retrieved chunks do not support.
The context variable holds what the retrieval step returned, up to about 6,000 characters of chunks from the Knowledge Base. The judge finds that the reply mentions a 14-day window for promo purchases, but no chunk in the context says that. It returns a low faithfulness score and a reason: "Claim '14-day window for promo purchases' has no support in the retrieved context."
Root cause points at the source
Over the next few days, the same pattern appears across dozens of sessions. PRISM's root cause view clusters them and names the likely cause: missing source, the Knowledge Base doesn't have a document covering promo-code return terms. The diagnosis is retrieval failure, not generation failure. Rewriting the prompt would not have fixed it.
The fix and the regression test
The team adds the missing policy document to the Knowledge Base. The Issue is turned into a check. From the next deploy, the CI pipeline sends a sample of replies to POST /api/intelligence/checks/run with the check's ID. After the fix merges, PRISM compares pass rates for the 7 days before and the 7 days after. The faithfulness score for promo-code questions goes from low to passing across the board.
The SDK setup that enables this:
Example
import prismtrace
# pip install "prismtrace-sdk>=0.5.1"
# Attach to your framework handler to capture retrieval and generation spans
# Full trajectory: model calls, tool calls, retrieval steps, handoffs and errorsThe retrieval context your framework passes through the handler appears automatically in {context} for every evaluator rubric on that trace.
Connect your RAG agent to PRISM and see retrieval and generation spans in your own traces.
Common mistakes
1. Assuming a wrong answer is a generation problem
The most common mistake is going straight to the prompt when an answer is wrong. Before touching the prompt, check whether the right chunk was even retrieved. If context precision or context recall is low, no prompt change will fix it.
2. Using aggregate metrics that hide per-query failures
Averaging faithfulness or context precision across all queries can mask a cluster of consistent failures on a specific topic. A mean score of 0.85 looks fine until you see that every question about a particular policy area scores 0.3. Evaluate at the trace level, not just in aggregate.
3. Evaluating only the final answer and skipping the retrieval spans
If your evaluators only read {input} and {output}, they can't distinguish a faithfulness failure from a retrieval gap. The {context} variable is what makes the distinction possible. An evaluator that skips it is measuring the wrong thing.
4. Not running deterministic checks on every trace
Deterministic rules, checks that give the same verdict for the same input, with no model involved, run on 100% of sessions without sampling. Skipping them in favor of LLM-as-judge-only evaluation means some failure patterns only surface on the fraction of traces that happen to be scored on a given day.
5. Fixing the prompt without checking Knowledge Base coverage
If the Knowledge Base doesn't cover a topic, the retriever will return low-relevance chunks and the model will either hallucinate or decline to answer. When a source is added to the Knowledge Base in PRISM, its content arrives as "Not reviewed" and is not checked against incoming traces until it's approved, so approving new content is part of the fix, not an afterthought.
How do you know if a RAG failure came from retrieval or generation?
Score both stages on the same trace and compare them. If context precision or context recall is low, the retriever didn't bring back the right information, fix the index, chunking, embedding, or Knowledge Base coverage. If retrieval scores are fine but faithfulness is low, the model received good context and didn't use it correctly, fix the prompt or context window handling.
The key is to track the outcome against the user's goal, not just span status. A span that returns 200 tells you the request went through; it doesn't tell you whether the retrieved chunks supported the answer the user got. With both retrieval and generation spans recorded in the trace, the {context} variable in an evaluator rubric holds what the retrieval step returned, so the judge can compare it directly against the reply.
What metrics should I use to evaluate retrieval quality in a RAG system?
The two core retrieval metrics are context precision and context recall.
- Context precision measures how much of what the retriever returned was actually relevant. A low score means the retriever is returning noisy results.
- Context recall measures how much of the relevant content in the Knowledge Base the retriever found. A low score means the retriever is missing information that exists.
Both can be implemented as deterministic rules (same verdict for the same input, no model, run on 100% of sessions) or as LLM-as-judge rules.
For more on the evaluator types available, see AI Agent Evaluation and Quality Checks.
How do you test whether your RAG agent is using retrieved context correctly?
Write a faithfulness evaluator that checks whether each claim in the reply appears in the retrieved chunks, and run it on incoming traces.
In the evaluator rubric, {input} is the user's last message, {output} is the agent's final answer, and {context} is what the trace's retrieval steps returned, up to about 6,000 characters. A faithfulness rule asks the judge: does every claim in {output} have support in {context}? If not, which claim doesn't?
Every trace is scored on arrival at no credit cost, until the plan's daily ceiling is reached. Failing traces are grouped into Issues, one Issue per kind of mistake, with a diagnosis and suspect files, so a pattern of faithfulness failures surfaces as a named problem rather than individual low scores scattered across your trace view.
From there, the Issue can become a regression test that runs in CI, so the same failure can't ship again without being caught.
Related
- Retrieval augmented generationBuild guide, how to structure a RAG pipeline from the ground up
- AI Agent Evaluation and Quality Checks, deterministic and LLM-as-judge evaluators in PRISMAI Agent Evaluation and Quality Checks, deterministic and LLM-as-judge evaluators in PRISM
- Fix AI Agent Failures and Prove the Fix, root cause, remediation and before/after comparisonFix AI Agent Failures and Prove the Fix, root cause, remediation and before/after comparison
- Evaluation Metrics for AI Agents, a broader look at the metrics that matter across agent typesEvaluation Metrics for AI Agents, a broader look at the metrics that matter across agent types
- RAG Evaluation and Testing, how PRISM supports RAG-specific testingRAG Evaluation and Testing, how PRISM supports RAG-specific testing
See which RAG failures are retrieval and which are generation
Connect your agent in minutes and get retrieval spans, generation scores, and root cause groupings in a single view.
Free to start, 100 credits each month.