Retrieval-Augmented Generation
Intermediate 15 min Module 5 of 6
Module 5 of 6

RAG Evaluation

Your RAG pipeline answers questions fluently. Users seem satisfied. But three weeks later, you discover it has been giving confident wrong answers for a specific category of questions, and nobody caught it because the answers sounded plausible. Evaluation is not a post-launch checklist. It is a continuous measurement system. By the end of this module you will understand the four RAGAS dimensions, how to measure each one, and how to build an evaluation loop that catches problems before users do.

By the end of this module you will be able to

The Three Evaluation Axes

A RAG system can fail in three distinct places. Each failure mode requires a different metric to detect it.

Retrieval quality measures whether the retriever found the right documents. If the right documents are not in the context, the generator cannot produce a correct answer regardless of how capable it is. Retrieval failure is invisible in end-to-end accuracy: you see a wrong answer, but you do not know if it came from bad retrieval or bad generation.

Generation faithfulness measures whether the generated answer is supported by the retrieved context. A faithfully grounded answer only makes claims that are directly stated or logically implied by the context. An unfaithful answer introduces facts that the context does not support, which is the definition of hallucination in RAG systems.

Answer relevance measures whether the answer actually addresses the question asked. A perfectly faithful answer to the wrong question is useless. This dimension catches cases where the retriever found relevant context but the generator went off-topic or answered a different aspect of the question.

The critical distinction: faithfulness vs fluency A language model can generate a fluent, confident, well-structured answer that contains no information from the retrieved context. It sounds correct. It reads well. It is completely wrong. Fluency evaluations catch nothing here. Faithfulness evaluation asks: is every claim in this answer supported by the provided context? That is the question that matters for RAG reliability.

The RAGAS Framework

RAGAS (Retrieval Augmented Generation Assessment), introduced by Es et al. (arXiv:2309.15217), provides a standardized set of four metrics for RAG evaluation. All four can be computed without human-labeled ground truth for the evaluation examples, using an LLM as the evaluator.

Metric 1
Context Precision
Of the retrieved chunks, what fraction are actually relevant to the question? High context precision means the retriever is not polluting the context with noise.
Metric 2
Context Recall
Of the information needed to answer the question, what fraction was present in the retrieved chunks? Low context recall means the retriever missed key information.
Metric 3
Faithfulness
What fraction of the claims in the generated answer are directly supported by the retrieved context? The hallucination detector for RAG systems.
Metric 4
Answer Relevance
Does the generated answer actually address the question asked? Penalizes answers that are faithful to the context but miss the point of the question.

These four metrics cover the full failure space of a RAG pipeline. Context precision and recall evaluate the retriever. Faithfulness evaluates the generator's grounding. Answer relevance evaluates end-to-end usefulness.

LLM-as-Judge for RAG Evaluation

Human annotation is accurate but slow and expensive. RAGAS uses an LLM (typically GPT-4 class) as the evaluator. For faithfulness, the LLM is asked to decompose the generated answer into atomic claims, then verify each claim against the retrieved context. For context precision, it is asked to label each retrieved chunk as relevant or irrelevant to the question.

This approach scales to thousands of test cases automatically. The LLM-as-judge methodology has known limitations: the judge model itself can make errors, and it tends to favor fluent answers. But for the specific structural questions RAGAS asks (is this claim in the context? is this chunk relevant?), judge accuracy is high enough to be practically useful.

Research on clinical AI systems, including work like Rao, Jaggi, Naidu (IEEE RMKMATE 2025, DOI:10.1109/RMKMATE64574.2025.11042816), highlights that domain-specific evaluation is essential: a general evaluator may not catch domain-specific hallucinations that a clinical or legal expert would immediately identify. RAGAS provides the framework; domain knowledge determines what to measure.

Fig 5 · RAGAS Evaluation Dimensions
RAGAS four-metric radar chart Faithfulness 88% Context Recall 74% Answer Relevance 79% Context Precision 82% 33% 66% 100% Directional illustration — RAGAS scores from a sample evaluation run
Interactive 5: RAGAS Score Explorer Try it

Adjust each RAGAS dimension to see the overall score and health status. Use this to understand how each metric affects the combined assessment.

75%
70%
80%
78%
RAGAS Score: 75.8%    Status: Acceptable
Python · RAGAS Evaluation Loop
from datasets import Dataset
from ragas import evaluate
from ragas.metrics import (
    context_precision,
    context_recall,
    faithfulness,
    answer_relevancy,
)

# Evaluation dataset: questions + ground truth + RAG outputs
data = {
    "question": [
        "What is the refund policy for digital products?",
        "How do I reset my password?",
    ],
    "answer": [
        rag_system.query("What is the refund policy for digital products?"),
        rag_system.query("How do I reset my password?"),
    ],
    "contexts": [
        retrieve("What is the refund policy for digital products?"),
        retrieve("How do I reset my password?"),
    ],
    "ground_truth": [
        "Digital products are non-refundable within 30 days of purchase.",
        "Visit the login page and click 'Forgot Password' to receive a reset email.",
    ]
}

dataset = Dataset.from_dict(data)
result = evaluate(
    dataset=dataset,
    metrics=[context_precision, context_recall, faithfulness, answer_relevancy],
)
print(result.to_pandas())
Try this

Write 5 questions for a knowledge base you know well. For each question, also write the ideal answer. Now imagine a RAG system retrieved the wrong context chunks and the model generated an answer that sounds correct but does not match your ideal. Score each of the four RAGAS dimensions by hand on a 0-10 scale. This manual scoring exercise makes the metrics concrete and builds intuition for what each dimension actually catches in practice.

Knowledge check
A RAG system returns an answer that is fluent and well-organized but contains facts not present in the retrieved context. Which RAGAS metric specifically catches this problem?
Correct. Faithfulness measures whether the claims in the generated answer are supported by the retrieved context. A fluent, unfaithful answer is exactly what faithfulness evaluation is designed to detect (Es et al., arXiv:2309.15217).
Context Precision and Recall evaluate the retriever. Answer Relevance checks if the answer addresses the question. Faithfulness is the metric that specifically measures whether the answer's claims are grounded in the retrieved context.
Your RAG system has high context precision (retrieved chunks are relevant) but low context recall. What does this indicate?
Correct. High precision but low recall means the retrieved chunks are relevant, but the retriever is not finding all the relevant chunks. The answer will be partially correct at best, limited to the subset of relevant information that was retrieved.
High precision means what was retrieved is relevant. Low recall means not enough relevant information was retrieved. The problem is the retriever's coverage, not the generator's behavior or answer focus.
Why might high RAGAS scores in testing not predict real-world performance?
Test datasets are finite and often constructed from documents in the knowledge base. Real users ask questions that were not anticipated, use vocabulary that was not in the test set, and ask about topics near the edges of the knowledge base. RAGAS scores on a 100-question test set tell you how the system performs on those 100 questions. They say less about the long tail of real user queries. This is why continuous evaluation, using production queries logged and periodically evaluated, is essential for detecting drift after initial deployment.
Before you go
Reflection: You deploy a RAG system for legal contract review. Which RAGAS metric would you weight most heavily when deciding whether to trust the system's answers? Which failures would be most costly, and how would that drive your evaluation design?
You might also like
Was this module helpful?
← Module 4: Retrieval and Reranking Module 6: Deploying RAG at Scale →