chapter six

6 Evaluating Retrieval-Augmented Generation (RAG)

 

This chapter covers

  • Evaluating agentic RAG systems across retrieval and generation
  • Search relevancy metrics for measuring retrieval quality
  • The four RAGAS metrics and production evaluation pipelines

In chapter 5, we built hallucination detection pipelines based on the principle that an AI system’s claims should be supported by evidence. To combat hallucinations, the most common technique is to ground AI system responses in retrieved documents from verifiable sources. These systems are closed-domain systems, or AI systems designed to operate within a narrow, specific field of knowledge or task, rather than handling general, unrestricted queries. Combined with an LLM, it is called Retrieval-Augmented Generation (RAG).

RAG-based AI systems combine two distinct components—a retrieval system that fetches relevant documents, and a generation system that synthesizes a response from them into a single system. Both components can fail independently, and their failures interact in ways that make diagnosis difficult. A response that seems incoherent might be caused by poor retrieval, poor generation, or the two components working against each other.

Consider a production scenario. A financial research assistant queries a knowledge base of earnings reports and filings to answer an analyst’s question:

“What drove Q3 revenue growth, and what risks could affect Q4?”

The system retrieves three documents:

6.1 The RAG architecture

6.1.1 A generalized RAG framework

6.1.2 Relationship pairs and the evaluation landscape

6.1.3 RAG as an agentic reasoning loop

6.1.4 Deep research agents

6.2 Evaluating retrieval quality

6.2.1 The information retrieval landscape

6.2.2 Precision and recall

6.2.3 Rank-aware metrics

6.2.4 Building a retrieval evaluation set

6.2.5 The limit of retrieval-only evaluation

6.3 RAGAS: Four dimensions of RAG quality

6.3.1 Faithfulness

6.3.2 Answer relevance

6.3.3 Context recall

6.3.4 Context precision

6.4 From evaluation to production RAG

6.4.1 Diagnosing RAG systems

6.4.2 Evaluating diverse context sources

6.5 Summary