Evaluating RAG & agents
A RAG system or an agent can fail in several places. Grade each stage separately, not only the final answer.
RAG: retriever and generator
Evaluate the two halves apart. The retriever is judged with ranking metrics such as recall@k: did the right passages come back? The generator is judged on faithfulness (is each claim supported by the passages?) and on answer correctness.
Agents: the trajectory
An agent’s answer depends on a chain of steps. Besides task success, look at the trajectory: were the tool calls valid, did each step help, how many steps were wasted? Two runs with the same answer can differ greatly in cost and risk.
In the lab, mark each step of a run as good or bad and see the scores change.
A worked example
A question has two relevant documents. The retriever returns five; the relevant ones are ranked 1st and 4th. Recall@3 is 1/2 and recall@5 is 1. If the generator reads only the top 3, it is missing half of the evidence before writing a word, so a wrong answer is the retriever’s fault, not the model’s.
In practice
Build a small labelled set of questions with known relevant passages and reference answers. Measure retrieval (recall@k), faithfulness (every claim supported by the retrieved text) and correctness separately, so you know which part to fix. For agents, log full trajectories and check tool-call validity and cost alongside the final answer.
Easy to confuse
- A correct answer with unsupported claims is still a faithfulness failure; it will fail when the model does not happen to know.
- Two agents with the same success rate can differ tenfold in cost and in risky actions taken along the way.
A RAG answer is fluent and correct, but the retrieved passages never mention the answer. What did the model rely on?
Correct is not the same as grounded. Faithfulness asks whether the answer is supported by the retrieved context; this one is not, so it may fail on questions the model does not know.
Two agents both finish the task. One used 4 tool calls and the other 19. What does final-answer accuracy say?
Success on the final answer ignores the path. Judging the trajectory (steps, wrong tool calls, cost) separates a clean run from a lucky one.
Retrieval recall@3 is 0.5. What does that mean?
Recall@k is the share of relevant passages found in the top k results. It measures the retriever alone, before the model writes anything.
Read more in the books
- AI Engineering, Chip Huyen: Ch. 6, “RAG and Agents”.
- AI Engineering, Chip Huyen: Ch. 4, “Evaluate AI Systems”: design your evaluation pipeline.
- Introduction to Information Retrieval, Manning, Raghavan, Schütze: Ch. 8, “Evaluation in information retrieval”.