AI 202Lesson 3 of 4
GuideIntermediateEvaluation
How to evaluate RAG pipelines and AI agents, step by step
A RAG pipeline or an agent is a system of parts, so a single end-to-end score cannot tell you what to fix. Evaluate retrieval on its own, then whether the answer is faithful to what was retrieved, then whether the whole system completes the task. For agents, grade the final state rather than the exact path, repeat each task to measure reliability, and report cost next to accuracy.
AI 202 syllabus · lesson 3 of 4
On this page
- Why does a single end-to-end score fail for RAG and agents?
- How do you evaluate retrieval?
- How do you evaluate the generated answer?
- How do you evaluate an AI agent?
- How do you build the evaluation set for RAG and agents?
- Where does fine-tuning fit?
- Checklist for a RAG or agent evaluation
- Check your understanding
- Sources and further reading
To evaluate a retrieval-augmented generation (RAG) pipeline or an AI agent, test each part separately and then the whole. For RAG, check whether retrieval found the right passages, whether the answer is faithful to those passages, and whether the final answer is correct. For agents, check whether the task was completed by grading the end state, how reliably it is completed across repeated attempts, and what it cost.
Why does a single end-to-end score fail for RAG and agents?
A RAG pipeline, introduced by Lewis and colleagues in 2020, combines a retriever that finds passages with a generator that writes the answer from them. An agent adds tools, multiple steps and often a user conversation. Each part can fail independently. A wrong answer might come from a passage that was never retrieved, a passage that was retrieved but ignored, or a correct passage that the generator contradicted.
An experience report from three RAG deployments in research, education and biomedicine listed seven failure points, from missing content and missed top-ranked documents to answers that were not extracted or had the wrong format. Two of its conclusions shape this lesson: validating a RAG system is only fully feasible during operation, and robustness evolves over time rather than being designed in at the start. You need layer-by-layer measurement both before release and on live traffic.
The evaluation framework lesson covers how to build an eval set from real traffic and how big it must be. This lesson adds what is specific to retrieval and to multi-step systems.
How do you evaluate retrieval?
Retrieval is the easiest layer to measure objectively and the most common root cause, so start there.
Build a labelled retrieval set
Take real questions from your traffic and, for each one, record which documents or passages contain the answer. A subject expert can label them, or you can bootstrap labels with an LLM and have an expert correct a sample. Keep the passage identifiers stable, so that re-chunking your documents does not silently invalidate the labels.
Choose retrieval metrics
- Recall at k: the share of questions for which at least one relevant passage appears in the top k results. If the answer is not retrieved, the generator cannot use it, so this sets a ceiling on the whole system.
- Ranking quality: whether relevant passages appear near the top. Ragas defines context precision as the mean of precision at each rank where a relevant chunk appears, which rewards putting relevant chunks first. The BEIR retrieval benchmark uses nDCG at 10 for the same purpose.
Ranking matters for more than tidiness. “Lost in the Middle” found that models used information best when it appeared at the beginning or end of the input context and significantly worse when it sat in the middle, even for models built for long contexts. A relevant passage at position 9 of 10 may as well be missing.
Keep a keyword baseline
BEIR evaluated ten retrieval approaches across eighteen datasets and found BM25, a classic keyword-matching method, to be a robust baseline. Re-ranking and late-interaction models did best on average, at higher computational cost, while dense retrievers often generalised less well to new domains. Before you invest in a new embedding model, check that it beats BM25 on your own labelled set.
How do you evaluate the generated answer?
Once you know what was retrieved, grade the answer against it.
Faithfulness
An answer is faithful when every claim in it is supported by the retrieved context. Ragas computes this by splitting the answer into claims and checking each against the context; ARES trains small judge models for context relevance, answer faithfulness and answer relevance.
Both are automated, which makes them fast enough to run on every change, but both rely on model judges. Validate them as described in the LLM-as-a-judge lesson. ARES showed one efficient way to do this: a few hundred human annotations, combined with a statistical correction called prediction-powered inference, were enough to keep its automated scores accurate across eight tasks.
Correctness and citations
Faithfulness is not correctness. An answer can faithfully repeat an out-of-date passage. Score correctness against reference answers written by an expert, with deterministic checks where the answer is a number, a date or an identifier. If your product shows citations, grade them too: the ALCE benchmark measured whether cited passages actually support each statement, and found that even the best models of the time lacked complete citation support about half of the time on its ELI5 questions.
Refusals and noise
The RGB benchmark tested four abilities a RAG system needs: noise robustness (ignoring irrelevant passages), negative rejection (declining when the documents hold no answer), information integration (combining facts from several passages) and counterfactual robustness (handling passages that contain false information). The models it tested struggled most with rejection, integration and false information. Build slices for each into your eval set, in particular questions whose correct answer is that the documents do not say.
| Layer | Question it answers | Typical metric | Needs |
|---|---|---|---|
| Retrieval | Did we find the right passages? | Recall at k, context precision, nDCG | Questions with labelled relevant passages |
| Faithfulness | Is the answer supported by what we found? | Share of supported claims | Retrieved context; a validated judge |
| Correctness | Is the answer right? | Exact or judged match to reference | Expert reference answers |
| Citations | Do the cited passages support the claims? | Citation support rate | Answer with citations; a validated judge |
| Refusal | Does it decline when the docs are silent? | Correct-refusal rate | Unanswerable questions |
How do you evaluate an AI agent?
An agent decides which tools to call, in what order, over several turns. There is rarely one correct transcript, and a small mistake early on can derail everything after it.
Grade the end state, not the path
The most reliable agent benchmarks check outcomes. SWE-bench gives a model a real GitHub issue from one of 12 Python repositories and counts it as resolved only if the repository’s tests pass after the model’s edit. WebArena checks the functional correctness of tasks completed on realistic websites. τ-bench compares the database state at the end of a customer-service conversation with an annotated goal state.
Your own agent evaluation should do the same: decide what the world should look like after the task, such as a refund issued, a ticket closed or a file changed, and check that, rather than matching one expected sequence of tool calls.
Step-level checks are still useful for diagnosis. Log every tool call with its arguments and check that arguments are valid, that forbidden tools were not called and that domain rules were followed. τ-bench includes policy guidelines for exactly this reason.
Measure reliability with pass^k
Agents are not deterministic, and a task that succeeds once may fail the next time. τ-bench introduced pass^k, the probability that all k independent attempts at a task succeed. In its experiments, state-of-the-art function-calling agents succeeded on fewer than half of the tasks, and in the retail domain pass^8 was below 25%. Run each task several times, report the average success rate and pass^k, and investigate tasks that pass sometimes but not always.
from math import comb
def pass_hat_k(successes: int, trials: int, k: int) -> float:
"""Unbiased estimate of pass^k for one task: the chance that k attempts, drawn
without replacement from `trials` recorded attempts, all succeed."""
if k > trials:
raise ValueError("need at least k recorded attempts")
return comb(successes, k) / comb(trials, k)
# One task, 8 recorded attempts, 6 succeeded
print(round(pass_hat_k(6, 8, 1), 2)) # 0.75: looks fine on average
print(round(pass_hat_k(6, 8, 4), 2)) # 0.21: four in a row is unlikely
# Average pass_hat_k over all tasks to get the benchmark-level number.
Report cost next to accuracy
“AI Agents That Matter” argued that agent evaluations focused narrowly on accuracy had produced needlessly complex and costly agents, and that the field had drawn mistaken conclusions about where accuracy gains came from. The authors recommend optimising cost and accuracy jointly, comparing against simple baselines and keeping proper holdout sets, because many agent benchmarks had inadequate holdouts and agents had overfit to them. Record tokens, tool calls, wall-clock time and money per task, and plot accuracy against cost before choosing an architecture.
How do you build the evaluation set for RAG and agents?
The sampling advice from the framework lesson applies, with three additions.
- Label at the right granularity. For RAG, store the question, the relevant passage identifiers and a reference answer. For agents, store the starting state, the user goal, any policy the agent must follow and the expected end state.
- Cover the failure slices on purpose. Unanswerable questions, questions needing two documents, documents with conflicting or outdated facts, ambiguous user requests, tool errors and timeouts. Production logs are the best source of these.
- Version the corpus with the eval set. A RAG score is only comparable across runs if the documents and the index are the same. Record the corpus snapshot, the chunking settings and the embedding model with every result.
For the deeper background on retrieval-augmented models, the Stanford CS25 lecture by Douwe Kiela, one of the authors of the original RAG paper, surveys the architectures you will be evaluating.
Where does fine-tuning fit?
Layered evaluation also tells you whether fine-tuning is the right fix. If retrieval recall is low, tune the retriever, the chunking or the index, not the language model. If retrieval is good but answers are unfaithful, badly formatted or fail to refuse, a model tuned on examples of good grounded answers can help; the fine-tuning versus RAG lesson covers that choice. Measure the result with the paired statistics in the lesson on measuring improvement.
On Attempts today you can fine-tune a model with supervised LoRA on input and expected-output examples, deploy it and evaluate it on held-out test examples from its run. Retrieval and multi-step agent evaluation run in your own harness, which calls the deployed model through its API.
Checklist for a RAG or agent evaluation
- Retrieval has its own labelled set and its own recall at k and ranking scores, with a BM25 baseline.
- Faithfulness and correctness are scored separately; the judges behind them are validated against human labels.
- The eval set includes unanswerable questions, multi-document questions and noisy or conflicting passages.
- Agent tasks are graded on the end state, with tool calls and policy rules checked for diagnosis.
- Every agent task is run several times, and pass^k is reported next to the average.
- Cost, tokens and latency per task are reported next to accuracy, against a simple baseline.
- The corpus, index, chunking and model versions are recorded with every result.
Check your understanding
Answer each question in your own words, then open it to compare with the lesson’s answer.
Q1What metrics should I use to evaluate a RAG system?
Use one metric per layer. For retrieval: recall at k, the share of questions whose relevant passage appears in the top k, plus a ranking metric such as context precision or nDCG. For generation: faithfulness, the share of claims in the answer supported by the retrieved context, and answer correctness against a reference. End to end: task success on your own questions, including ones the documents cannot answer.
Q2How is evaluating an agent different from evaluating a chatbot?
An agent takes actions over several steps with tools, so there are many valid paths to the same goal and errors compound. Grade the outcome, for example the final database state, the files changed or whether unit tests pass, rather than one expected transcript. Also check tool calls and rule-following separately, repeat each task to measure consistency, and track cost per task.
Q3What is pass^k and why does it matter?
pass^k, introduced with the tau-bench benchmark, is the probability that an agent succeeds on all k independent attempts at the same task. Average success can look acceptable while pass^k falls sharply as k grows, which means users who repeat a task will soon hit a failure. It measures reliability rather than occasional capability.
Q4Do I need human labels to evaluate RAG?
Fewer than you might think, but some. Reference-free metrics such as those in Ragas use an LLM to grade context relevance and faithfulness without labelled answers. ARES showed that a few hundred human annotations can correct the errors of automated judges. Use automated metrics for scale and a small, carefully labelled set to validate them.
Q5Why should a RAG evaluation include unanswerable questions?
Because answering confidently when the documents do not contain the answer is one of the most damaging failures. The RGB benchmark tested negative rejection, declining when retrieved documents hold no answer, and found that models struggle with it. Add questions whose correct response is that the information is not available, and grade the refusal.
Sources and further reading
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks — arXiv (NeurIPS 2020), 2020
- Seven Failure Points When Engineering a Retrieval Augmented Generation System — arXiv, 2024
- BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models — arXiv (NeurIPS 2021 Datasets and Benchmarks), 2021
- Ragas: Automated Evaluation of Retrieval Augmented Generation — arXiv, 2023
- Context Precision — Ragas documentation, 2026
- ARES: An Automated Evaluation Framework for Retrieval-Augmented Generation Systems — arXiv (NAACL 2024), 2023
- Benchmarking Large Language Models in Retrieval-Augmented Generation — arXiv (AAAI 2024), 2023
- Lost in the Middle: How Language Models Use Long Contexts — arXiv (TACL 2024), 2023
- Enabling Large Language Models to Generate Text with Citations — arXiv (EMNLP 2023), 2023
- τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains — arXiv, 2024
- SWE-bench: Can Language Models Resolve Real-World GitHub Issues? — arXiv (ICLR 2024), 2023
- WebArena: A Realistic Web Environment for Building Autonomous Agents — arXiv (ICLR 2024), 2023
- AI Agents That Matter — arXiv (TMLR 2025), 2024
Progress is saved in this browser only. No account needed.