How do you evaluate a retrieval-augmented generation (RAG) system?

Answered by Falk Gottlob · Reviewed · 2 min read

THE SHORT ANSWER

Evaluate retrieval-augmented generation (RAG), where an AI searches your documents and then writes an answer from them, in two parts. First test the search. For each test question, did the right documents come back near the top? Recall@k, the share of needed documents found in the top k results, is the usual measure. Then test the answer. Is every claim in it supported by the documents it retrieved? Hamel Husain and Shreya Shankar's advice: debug retrieval first, then grade answers with an AI judge you've checked against people.

A retrieval-augmented generation system does two jobs. It searches your documents for what looks relevant. Then a model writes an answer from what came back. When the answer is wrong, either job could be to blame. So test them apart.

Start with search. Hamel Husain and Shreya Shankar, who teach the best known evals course, call retrieval a search problem and say to grade it with standard search measures. The simplest is recall@k. For each test question, look at the top k results. Did the document with the answer show up? The share of questions where it did is your score.

You need a document attached to each test question for that. You can make those from your own content. Pick a fact from a document, write the question it answers, and you have a pair.

Anthropic's work on contextual retrieval shows the kind of gain to look for. It tracked how often the needed document was missing from the top 20 results. Its method adds a short note of context to each chunk of text before searching. Combined with a reranking step, it cut that miss rate by 67%.

Then grade the answer. The key check is faithfulness: does every claim in the answer come from the retrieved text? Ragas, an open source evaluation library, scores it as supported claims divided by all claims. An AI judge can do this check well. Calibrate that judge against a person first, as with any judge.

Debug in that order. A model can't answer from a document it never saw. Fix search before you touch the prompt.

The harness for both checks is in Evals for Engineers. Support teams running help center bots should read Evals for Support Teams. The basics are in Evals From Zero, and every guide is on the AI evals hub.

SOURCES

THE LONG VERSION

RELATED ANSWERS

If this was useful, The AI Product Transformation is where I share more of it.

One email every Monday with the week's best posts and what changed on the site.

Unsubscribe anytime. Read past issues.