Evaluating a RAG agent: faithfulness, context precision and recall, step by step
Twelve test questions, each with its answer's claims and the chunks the retriever returned. See how faithfulness, context precision and context recall are computed, set a release bar, and watch why poor retrieval turns into hallucinated answers.
Interactive simulation. It needs JavaScript; the text below explains what it shows.
What you are looking at
Each row is one question from an evaluation set. The white columns are what an evaluator counts: the claims in the answer and how many of them the retrieved context supports, the chunks retrieved and how many were relevant, and how many relevant chunks the reference answer needs. The orange columns turn those counts into the three core metrics for each question, decide whether it passes your bar and count its unsupported claims.
The chart shows each answer's faithfulness as an orange ring, with your bar as a dashed line and the average as a solid line. The bars underneath show context recall per question, so you can line up the retrieval failures with the faithfulness failures above them.
The algorithm
A retrieval-augmented agent can fail in two places: the retriever can fetch the wrong chunks, and the generator can say things the chunks do not support. Good evaluation measures both separately, which is what RAGAS, DeepEval and the evaluators in LangSmith do.
Faithfulness checks the generator. An LLM splits the answer into short factual claims and checks each one against the retrieved context. Faithfulness is the share of claims the context supports. A claim the context does not support is a hallucination, even when it happens to be true, because the system cannot show where it came from.
Context precision checks how much of what the retriever returned was useful. The simulation uses the plain share of relevant chunks; RAGAS weights it by rank, rewarding retrievers that put relevant chunks first.
Context recall checks what the retriever missed. It compares the retrieved context with what the reference answer needs: if the answer needs four facts and only three were retrieved, recall is 75%.
With the defaults, mean faithfulness is 85.5%, mean context precision 50% and mean context recall 76.5%. Ten claims across the twelve answers are unsupported. Seven questions pass a bar of 0.8 faithfulness and 0.6 recall, a pass rate of 58.3%. The strongest lesson is the correlation of 0.97 between recall and faithfulness: every question where retrieval missed facts also has unsupported claims, because the model filled the gap from its own knowledge.
Things to try
- Lower the faithfulness bar to 0.7: questions 3 and 10 now pass, 9 of 12 in all; question 12, at 0.67, still fails.
- Raise the recall bar to 1: still 7 questions pass, because every answer that passed already had perfect recall, another sign of how tightly the two metrics are linked.
- Edit question 8 so that two relevant chunks are retrieved and all four claims are supported: mean faithfulness rises to 89.7% and 8 of 12 questions pass.
- Notice that precision is only 50% even for passing questions: half the context is noise, which costs tokens and can distract the model.
- Paste the per-question counts from your own evaluation run and download the results CSV for your release notes.
How it works in real systems
In practice the counting is done by an LLM judge, so the metrics inherit the judge's errors; teams check the judge against human labels on a sample first. Evaluation sets are built from real user questions with reference answers, versioned and rerun on every change to the prompt, the retriever or the model. LangSmith and Langfuse store the runs and show regressions; DeepEval runs the same metrics as unit tests in CI, and RAGAS can generate synthetic test questions from your documents. A failing faithfulness score points at the prompt or the model; a failing recall score points at chunking, embeddings, filters or the number of chunks retrieved.