# 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.

<div data-sim="specx" data-spec="{&quot;level&quot;:&quot;intermediate&quot;,&quot;head&quot;:&quot;Evaluating a RAG agent the RAGAS way: faithfulness, context precision and recall&quot;,&quot;sub&quot;:&quot;Twelve test questions from an evaluation set. For each answer, count supported claims and relevant retrieved chunks; set the bar and see which answers pass.&quot;,&quot;params&quot;:[{&quot;id&quot;:&quot;faith_min&quot;,&quot;label&quot;:&quot;Faithfulness needed to pass&quot;,&quot;min&quot;:0.5,&quot;max&quot;:1,&quot;step&quot;:0.05,&quot;value&quot;:0.8},{&quot;id&quot;:&quot;rec_min&quot;,&quot;label&quot;:&quot;Context recall needed to pass&quot;,&quot;min&quot;:0.3,&quot;max&quot;:1,&quot;step&quot;:0.05,&quot;value&quot;:0.6}],&quot;data&quot;:{&quot;columns&quot;:[&quot;q&quot;,&quot;claims&quot;,&quot;supported&quot;,&quot;retrieved&quot;,&quot;relevant&quot;,&quot;needed&quot;],&quot;rows&quot;:[[1,6,6,5,4,3],[2,4,4,5,2,2],[3,7,5,5,3,4],[4,3,3,5,1,1],[5,8,8,5,5,4],[6,5,3,5,1,3],[7,6,6,5,3,3],[8,4,2,5,0,2],[9,5,5,5,4,4],[10,9,7,5,3,5],[11,3,3,5,2,2],[12,6,4,5,2,4]],&quot;note&quot;:&quot;An illustrative evaluation run: for each question, the claims in the answer and how many the retrieved context supports, the chunks retrieved and how many were relevant, and how many relevant chunks the reference answer needs. Paste the same counts from your own RAGAS, DeepEval or LangSmith run.&quot;},&quot;row&quot;:[{&quot;id&quot;:&quot;faith&quot;,&quot;label&quot;:&quot;faithfulness&quot;,&quot;expr&quot;:&quot;supported/claims&quot;,&quot;fmt&quot;:&quot;p&quot;,&quot;tex&quot;:&quot;F_i = \\frac{\\text{supported claims}_i}{\\text{claims}_i}&quot;},{&quot;id&quot;:&quot;prec&quot;,&quot;label&quot;:&quot;context precision&quot;,&quot;expr&quot;:&quot;relevant/retrieved&quot;,&quot;fmt&quot;:&quot;p&quot;,&quot;tex&quot;:&quot;P_i = \\frac{\\text{relevant}_i}{\\text{retrieved}_i}&quot;},{&quot;id&quot;:&quot;rec&quot;,&quot;label&quot;:&quot;context recall&quot;,&quot;expr&quot;:&quot;min(relevant, needed)/needed&quot;,&quot;fmt&quot;:&quot;p&quot;,&quot;tex&quot;:&quot;R_i = \\frac{\\min(\\text{relevant}_i, \\text{needed}_i)}{\\text{needed}_i}&quot;},{&quot;id&quot;:&quot;pass&quot;,&quot;label&quot;:&quot;passes&quot;,&quot;expr&quot;:&quot;ge(faith, faith_min)*ge(rec, rec_min)&quot;,&quot;fmt&quot;:&quot;i&quot;},{&quot;id&quot;:&quot;unsup&quot;,&quot;label&quot;:&quot;unsupported claims&quot;,&quot;expr&quot;:&quot;claims - supported&quot;,&quot;fmt&quot;:&quot;i&quot;}],&quot;derived&quot;:[{&quot;id&quot;:&quot;mf&quot;,&quot;label&quot;:&quot;Mean faithfulness&quot;,&quot;expr&quot;:&quot;mean(faith)&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;mp&quot;,&quot;label&quot;:&quot;Mean context precision&quot;,&quot;expr&quot;:&quot;mean(prec)&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;mr&quot;,&quot;label&quot;:&quot;Mean context recall&quot;,&quot;expr&quot;:&quot;mean(rec)&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;npass&quot;,&quot;label&quot;:&quot;Questions passing&quot;,&quot;expr&quot;:&quot;sum(pass)&quot;,&quot;fmt&quot;:&quot;i&quot;},{&quot;id&quot;:&quot;rate&quot;,&quot;label&quot;:&quot;Pass rate&quot;,&quot;expr&quot;:&quot;mean(pass)&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;halluc&quot;,&quot;label&quot;:&quot;Unsupported claims in all answers&quot;,&quot;expr&quot;:&quot;sum(unsup)&quot;,&quot;fmt&quot;:&quot;i&quot;},{&quot;id&quot;:&quot;corr_rf&quot;,&quot;label&quot;:&quot;Correlation of recall and faithfulness&quot;,&quot;expr&quot;:&quot;corr(rec, faith)&quot;}],&quot;chart&quot;:{&quot;title&quot;:&quot;Faithfulness of each answer against the bar&quot;,&quot;x&quot;:{&quot;var&quot;:&quot;t&quot;,&quot;label&quot;:&quot;Question&quot;,&quot;from&quot;:1,&quot;to&quot;:12},&quot;y&quot;:{&quot;from&quot;:0,&quot;to&quot;:1.05},&quot;series&quot;:[{&quot;label&quot;:&quot;Faithfulness bar&quot;,&quot;expr&quot;:&quot;faith_min&quot;,&quot;dash&quot;:true},{&quot;label&quot;:&quot;Mean faithfulness&quot;,&quot;expr&quot;:&quot;mf&quot;}],&quot;fit&quot;:{&quot;x&quot;:&quot;q&quot;,&quot;y&quot;:&quot;faith&quot;,&quot;label&quot;:&quot;Faithfulness of each answer&quot;}},&quot;bars&quot;:{&quot;title&quot;:&quot;Context recall of each question&quot;,&quot;y&quot;:&quot;rec&quot;,&quot;label&quot;:&quot;q&quot;},&quot;steps&quot;:[{&quot;title&quot;:&quot;Split answers into claims&quot;,&quot;text&quot;:&quot;An LLM breaks each answer into short factual claims, then checks each against the retrieved context: mean faithfulness is {mf:p}.&quot;,&quot;show&quot;:[&quot;mf&quot;]},{&quot;title&quot;:&quot;Judge the retrieved chunks&quot;,&quot;text&quot;:&quot;Each retrieved chunk is marked relevant or not: on average {mp:p} of what the retriever returned was useful.&quot;,&quot;show&quot;:[&quot;mp&quot;]},{&quot;title&quot;:&quot;Check what was missed&quot;,&quot;text&quot;:&quot;Recall asks whether the chunks the reference answer needs were retrieved: mean recall is {mr:p}.&quot;,&quot;show&quot;:[&quot;mr&quot;]},{&quot;title&quot;:&quot;Connect the metrics&quot;,&quot;text&quot;:&quot;Low recall usually means low faithfulness: the model fills the gaps itself. Correlation here is {corr_rf}, and {halluc} claims are unsupported.&quot;,&quot;show&quot;:[&quot;corr_rf&quot;,&quot;halluc&quot;]},{&quot;title&quot;:&quot;Set the release bar&quot;,&quot;text&quot;:&quot;With faithfulness of at least {faith_min} and recall of at least {rec_min}, {npass} of the questions pass ({rate:p}).&quot;,&quot;show&quot;:[&quot;npass&quot;,&quot;rate&quot;]}]}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## 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.

## Sources

- [RAGAS documentation: Available metrics](https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/)
- [Es et al.: RAGAS: Automated Evaluation of Retrieval Augmented Generation (arXiv)](https://arxiv.org/abs/2309.15217)
- [DeepEval documentation: RAG evaluation metrics](https://deepeval.com/docs/metrics-faithfulness)
