RAGAS Tutorial 2026: A Reproducible Scorecard for Your RAG Pipeline
RAGAS is the leading open-source framework for evaluating RAG pipelines with 14,855 GitHub stars. This tutorial covers both metric families - retrieval (context precision/recall) and generation (faithfulness/answer relevancy/correctness) - plus installation, dataset creation, and judge-LLM (GPT-4 or Claude) setup.
📜 Table of Contents
📖 Keep reading
RAGAS Tutorial 2026: A Reproducible Scorecard for Your RAG Pipeline
The trap in RAG tuning is judging each change by eyeballing a few samples. By the fifth iteration you cannot remember what the previous version looked like. RAGAS turns "feels better" into numbers you can compare.
What it measures
RAGAS uses an LLM as judge: give it a question, the answer, and the retrieved context, and it scores against fixed criteria. No large annotated set is needed, only a test set with reference answers.
| Metric | Measures | Needs | Rough target |
|---|---|---|---|
| Context Precision | Whether relevant chunks rank high | Q, contexts, reference | 0.7+ |
| Context Recall | Whether needed info was retrieved | Q, contexts, reference | 0.7+ |
| Faithfulness | Answer grounded in context | Q, answer, contexts | 0.8+ |
| Answer Relevancy | Answer addresses the question | Q, answer | 0.7+ |
| Answer Correctness | Factual agreement with reference | Q, answer, reference | Higher is better |
| Noise Sensitivity | Distraction from irrelevant chunks | Q, answer, contexts | Lower is better |
Retrieval metrics diagnose the wrong documents; generation metrics diagnose the wrong answer from right documents.
Setup
pip install -U ragas datasets
Use a stronger model as judge than the one under test, otherwise the student grades its own paper. Any OpenAI-compatible endpoint works, including a local model, though small judges score less consistently.
Build the test set
50-100 questions covering the main intents is enough to see differences; under 30 is too noisy.
samples = [{
"user_input": "How long does a refund take after I submit the request?",
"retrieved_contexts": ["...retrieved passage..."],
"response": "...what the system actually answered...",
"reference": "...human-verified correct answer...",
}]
Three ways to build it: harvest real logged questions (best, slowest), generate questions from documents (fast, often too formal), or top up by intent category so no single topic dominates. Then freeze the set — editing it invalidates historical scores.
Run an evaluation
from ragas import evaluate
from ragas.metrics import faithfulness, answer_relevancy, context_precision, context_recall
from datasets import Dataset
result = evaluate(Dataset.from_list(samples),
metrics=[faithfulness, answer_relevancy, context_precision, context_recall])
print(result)
print(result.to_pandas().head())
Look at per-sample rows, not just the mean: a single sample scoring 0.2 on Faithfulness usually means retrieval returned nothing relevant and the model improvised.
Judge configuration changed significantly across RAGAS versions; if arguments are rejected, read the current migration notes instead of copying older tutorials.
Reading the scores
- Low Recall + high Faithfulness: honest model, incomplete context. Adjust chunking, retrieve more, add keyword search.
- Low Precision: relevant chunks exist but rank badly. Add a reranker.
- Low Faithfulness: the model invents. Tighten the prompt, demand citations, allow "not in the material".
- Low Relevancy: too many instructions or too much context buried the question.
- All high but users unhappy: the test set misses real usage, or the problem is speed and formatting.
Put it in the change loop
| Change | Recall | Faithfulness | Keep? |
|---|---|---|---|
| Baseline | 0.62 | 0.81 | — |
| Chunk 500→800 chars | 0.71 | 0.83 | Yes |
| Add rerank | 0.74 | 0.84 | Yes |
| Bigger generator | 0.74 | 0.88 | Cost-dependent |
Log this table per release and gate merges on thresholds in CI.
FAQ
Q: No reference answers? Faithfulness, Answer Relevancy and Noise Sensitivity work without them, but Recall does not.
Q: Small local judge? Possible but inconsistent — run the same batch three times and check variance first.
Q: Cost control? Cap the set at 50-100, run full only on major changes, sample 20 for routine tweaks.
Q: Chinese? The metrics are language-agnostic but the judge's Chinese ability decides credibility. Validate with a Chinese set; do not reuse English thresholds blindly.
Q: Conflicts with human review? Trust the human first. High-score-but-bad samples usually reveal a mismatch between metric definition and business standard.
Q: What thresholds? 0.7/0.8 are community starting points. Use your baseline as the reference and track relative movement.
RAGAS APIs evolve; check official docs for current parameters.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.