Library

Volume 2 · RAG Architecture

Notebook
Sign in

Section 25

RAG Evaluation Metrics

560 words · about 3 min

25.1 The RAGAS Framework

from ragas import evaluate
from ragas.metrics import (
    faithfulness, answer_relevancy, context_precision,
    context_recall, answer_correctness
)

eval_data = {
    "question": ["What is the vacation policy?", ...],
    "answer": ["Employees get 20 days PTO...", ...],
    "contexts": [["Policy doc: PTO section...", ...], ...],
    "ground_truth": ["20 days PTO for full-time...", ...]
}

results = evaluate(
    dataset=eval_data,
    metrics=[faithfulness, answer_relevancy, context_precision,
             context_recall, answer_correctness]
)
# faithfulness: 0.92, answer_relevancy: 0.88,
# context_precision: 0.85, context_recall: 0.90

25.2 RAG Metric Definitions & Targets

Metric What It Measures Tool/Framework Target
Faithfulness Is the answer grounded in retrieved context? RAGAS, TruLens >95%
Answer Relevancy Does the answer address the question? RAGAS >90%
Context Precision Are retrieved chunks actually relevant? RAGAS >80%
Context Recall Was all needed information retrieved? RAGAS >90%
Answer Correctness Is the answer factually correct vs. ground truth? Human eval, LLM-as-judge >90%
Hallucination Rate % of claims not supported by sources Custom evaluation <2%
Hit Rate % of queries where the correct doc is in top-K Retrieval-only metric >95%
MRR (Mean Reciprocal Rank) Average rank of the first relevant result Retrieval-only metric >0.7
NDCG@10 Normalized Discounted Cumulative Gain Retrieval-only metric >0.6

25.3 Building a Golden Evaluation Dataset

Requirements: 100-500 question-answer pairs minimum, representative of production query distribution, human-reviewed ground truth, updated quarterly.

Recommended category mix:

Golden Dataset Structure:
├── Simple factual (40%)      — "What is X?"
├── Complex analytical (20%)  — "Compare X and Y, considering Z"
├── Multi-hop reasoning (15%) — "Given A and B, what is C?"
├── Unanswerable (10%)        — Questions outside corpus scope
├── Adversarial (10%)         — Trick questions, ambiguous queries
└── Multi-turn (5%)           — Follow-up questions requiring context

Section 25 — Interview Q&A

Q: How do you evaluate RAG quality end-to-end? A: I use a RAGAS-style multi-metric framework rather than a single score: context relevance/precision to check whether the right chunks were retrieved, context recall to check whether all needed information was retrieved, faithfulness to check whether the generated answer is actually supported by the retrieved context (the primary hallucination signal), answer relevancy to check the answer actually addresses the question, and answer correctness against a ground-truth golden dataset. I run this nightly against a 100-500 pair golden dataset that’s representative of production traffic (including adversarial and unanswerable questions), with alerts if any metric drops below its threshold — this catches regressions from prompt changes, model version upgrades, or corpus drift before they reach users at scale.

Q: A stakeholder says “the AI’s accuracy is only 80%.” How do you investigate and respond? A: First define what “accuracy” actually measures — which metric, on which query population. Then segment failures by query type (factual/analytical/multi-hop), document type, department, and user tenure, and do root-cause analysis on a sample of ~50 failures using the four-bucket framework (retrieval / ranking / generation / knowledge-gap failure — see Section 21’s Q&A). Prioritize fixes by expected impact: quick wins like prompt optimization might get +5% in a week, medium-effort fixes like re-ranking or hybrid search might get +10% in 2-4 weeks, and longer-term corpus expansion or fine-tuning might get another +5-10% over 2-3 months. Set realistic staged targets with the stakeholder and be explicit that 100% is not a realistic target for any probabilistic system — 95%+ is state-of-the-art for most enterprise RAG use cases.