Overview

6 Evaluating Retrieval-Augmented Generation (RAG)

Retrieval-augmented generation is presented as a way to reduce hallucinations by grounding model outputs in external, verifiable documents. The chapter emphasizes that these systems are really two coupled parts: retrieval, which finds candidate evidence, and generation, which turns that evidence into an answer. Because either part can fail on its own, and because their failures can mask one another, evaluation has to separate retrieval quality from generation quality instead of judging only the final response.

To evaluate retrieval, the chapter draws on classic information retrieval metrics such as precision, recall, precision@k, mean average precision, mean reciprocal rank, and nDCG. It explains how exact matching, sparse retrieval, dense retrieval, and hybrid retrieval each have different strengths and failure modes, especially around lexical variation versus precise identifiers. The key lesson is that retrieval evaluation requires labeled corpora, queries, and relevance judgments, and that rank matters because relevant documents buried too low in the context window may not influence the model effectively.

The chapter then introduces a four-part diagnostic framework for RAG systems: faithfulness, answer relevance, context recall, and context precision. Faithfulness checks whether claims in the answer are supported by retrieved context, while answer relevance checks whether the answer actually addresses the user’s question. Context recall asks whether the needed information is present in the retrieved material, and context precision asks whether that material is mostly useful rather than noisy. Taken together, these metrics help diagnose whether failures come from retrieval, generation, query formulation, or agentic planning, and they are especially useful in production through offline evaluation, regression testing, and online monitoring.

The basic single-turn Retrieval-Augmented Generation architecture. A user question is routed to a retrieval system, which queries a knowledge base and returns relevant documents. The LLM synthesizes an answer to the question and retrieves context, producing responses supported by sources.
Agentic RAG. The AI model decides how to query, which retrieval tool to use, and whether to iterate until it has enough evidence to answer.
Deep Research. The AI agent is given a topic to research; it formulates a research plan, searches and refines to gather information, and produces a detailed report.
The generalized RAG framework. The system prompt provides standing instructions. The user prompt provides the query. In-context knowledge, retrieved from external sources, populates the context window. The assistant response is produced from all three inputs combined.
Relationship pairs in RAG evaluation. The diagram labels four evaluation relationships: user query to retrieved context (retrieval relevance), user query to response (answer relevance), retrieved context to response (faithfulness), and response to itself (internal consistency).
Changing the location of relevant information within the language model's input context results in a U-shaped performance curve. Models are better at using relevant information that occurs at the very beginning (primacy bias) or end of their input context (recency bias), and performance degrades significantly when models must access and use information located in the middle of the input context. Source: Liu et al, 2023[2].

Summary

  • RAG systems separate knowledge from intelligence: the retrieval system provides knowledge; the model provides reasoning. This separation solves the static knowledge problem but introduces two interacting failure modes—retrieval quality and generation quality—that previously covered evaluation methods cannot diagnose.
  • Agentic RAG systems add a third failure category: reasoning quality. The model formulates its own retrieval queries, evaluates results, and decides when to stop retrieving. Deep research agents add a planning step and a human verification stage on top of this, each introducing its own evaluation dimension.
  • The three retrieval paradigms fail in complementary ways: grep/ripgrep fails on lexical variation; BM25/TF-IDF fails on paraphrase; dense vector search fails on precise identifiers such as SKUs, error codes, and contract clause numbers. Hybrid retrieval using Reciprocal Rank Fusion combines sparse and dense signals to cover both failure modes.
  • Precision and recall measure whether the right documents were retrieved. Rank-aware metrics—Precision@k, MRR, MAP, and nDCG—additionally penalize systems that rank relevant documents below the context window cutoff, where they cannot influence generation.
  • RAGAS defines four independent metrics across two axes. Faithfulness and answer relevance measure generation quality: faithfulness checks whether claims are supported by retrieved context using claim decomposition; answer relevance checks whether the answer addresses the question using back-translation. Context recall and context precision measure retrieval quality: context recall checks whether the retrieved context covers the ground truth answer; context precision checks whether retrieved documents are relevant and ranked above noise.
  • The RAGAS diagnostic matrix maps combinations of high and low metric scores to specific root causes. Low faithfulness with high context scores points to a generation problem—either intrinsic hallucination (misreading the context) or extrinsic hallucination (ignoring it). Low context recall with high faithfulness points to a retrieval gap that should be diagnosed against the retrieval method's known failure mode before any fix is attempted.
  • RAGAS generalizes across context source types. SQL retrieval is evaluated with execution accuracy and task success rate; API retrieval requires freshness checks in addition to functional correctness; multi-hop retrieval chains require applying RAGAS at each hop independently, not just at the final output.
  • Production RAG evaluation requires three modes: offline evaluation with the full RAGAS suite against a labeled evaluation set; online monitoring of faithfulness and answer relevance for production traffic; and regression testing before every system change. Always evaluate retrieval quality before interpreting generation metrics—poor retrieval degrades generation scores even when the generation model is working correctly.

FAQ

What is Retrieval-Augmented Generation (RAG)?RAG is an AI system that combines a retrieval component, which fetches relevant documents or passages from an external knowledge source, with a generation component, which uses that retrieved information to produce an answer. It is commonly used to ground responses in verifiable evidence and reduce hallucinations.
Why are standard text similarity metrics like BLEU and BERTScore not enough for RAG evaluation?BLEU and BERTScore measure general similarity between texts, but they do not diagnose whether the retriever found the right evidence, whether the model used that evidence faithfully, or whether the final answer actually addressed the user’s question. RAG needs metrics tailored to retrieval and grounding failures.
What are the main failure modes in a single-turn RAG system?In single-turn RAG, the two main failure modes are retrieval quality problems and generation quality problems. The retriever may return irrelevant or incomplete documents, or the generator may ignore the evidence and hallucinate unsupported claims. These failures can also interact with each other.
How is agentic RAG different from single-turn RAG?Agentic RAG lets the model decide what to search for, how to phrase queries, which retrieval tool to use, and whether to search again. Single-turn RAG usually performs one fixed retrieval step before generation. Agentic RAG adds reasoning and query-formulation quality as important evaluation dimensions.
What do precision and recall measure in RAG retrieval evaluation?Recall measures coverage: how many of the relevant documents in the corpus were retrieved. Precision measures noise: how many of the retrieved documents are actually relevant. Low recall means the system is missing important evidence; low precision means the context is cluttered with irrelevant material.
Why do rank-aware metrics like Precision@k, MRR, and nDCG matter?Rank-aware metrics account for the order of retrieved documents, which matters because only the top results may fit in the context window and the model is more likely to use earlier items. Precision@k measures relevance in the top k results, MRR focuses on how quickly the first relevant result appears, and nDCG handles graded relevance and ranking quality more generally.
What is the purpose of the RAGAS framework?RAGAS provides a four-metric diagnostic framework for RAG systems: faithfulness, answer relevance, context recall, and context precision. Together, these metrics help identify whether failures come from generation, retrieval, or both.
What does faithfulness measure in RAGAS?Faithfulness measures whether the claims in the generated answer are supported by the retrieved context. A high faithfulness score means the model stayed grounded in the evidence; a low score indicates hallucination beyond the retrieved documents.
What does answer relevance measure in RAGAS?Answer relevance measures whether the final answer actually addresses the user’s question. It is typically computed using back-translation: the system generates candidate questions from the answer and compares them to the original question. This helps detect partial or off-topic answers even if they are factually correct.
How do context recall and context precision help diagnose retrieval problems?Context recall checks whether the retrieved context contains the information needed to answer the question, while context precision checks whether the retrieved context is mostly useful rather than noisy. Low recall points to missing evidence; low precision suggests irrelevant documents are crowding the context window.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Evaluation and Alignment, The Foundational Ideas ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Evaluation and Alignment, The Foundational Ideas ebook for free