GUIDE / ai evals
RAGAS: Evaluating RAG Pipelines
Learn Ragas for RAG evaluation: faithfulness, context precision, contextual recall, dataset design, and how to measure retrieval-augmented generation quality.
RAGAS (often written Ragas) is one of the most practical ways to evaluate retrieval-augmented generation quality with metrics instead of gut feel. When a RAG bot gives a bad answer, the defect might be retrieval, ranking, chunking, prompting, or generation. Without metrics that separate those layers, teams endlessly tweak prompts while the real bug lives in the retriever.
This guide explains what Ragas is, the core metrics for RAG pipelines, how to measure context precision and contextual recall, faithfulness workflows, RAG evaluation dataset design, interpretation patterns, CI usage, and common mistakes.
Why RAG Needs Its Own Evaluation Approach
A plain LLM call has one main moving part: generation.
A RAG pipeline has several:
- user question
- query transformation
- retrieval from a knowledge base
- ranking or re-ranking
- context assembly
- generation with citations or grounded instructions
- optional post-checks
A wrong answer can mean:
- the right doc was never retrieved
- the right doc was retrieved but buried under noise
- the chunk boundaries cut away the needed sentence
- the model ignored good context
- the model mixed good context with invented details
RAG evaluation must illuminate which layer failed. That is the job Ragas-style metrics take on.
What Ragas Is
Ragas is a RAG evaluation toolkit that scores pipeline outputs using metrics aligned to retrieval-augmented systems. You typically provide:
- question
- generated answer
- retrieved contexts
- optional reference answer or ground truth
Ragas then computes metrics such as faithfulness, answer relevancy, context precision, and context recall. Those scores help you compare pipeline versions and debug systematic weaknesses.
Ragas does not replace product analytics, red teaming, or human review. It gives you a structured offline lens on RAG quality.
Core Ragas Metrics for RAG Pipelines
| Metric | Question it answers | Low score suggests |
|---|---|---|
| Faithfulness | Is the answer supported by retrieved context? | Hallucination or unsupported claims |
| Answer relevancy | Does the answer address the question? | Off-topic or unfocused generation |
| Context precision | Are retrieved chunks actually useful/relevant? | Noisy retrieval or weak ranking |
| Context recall | Did retrieval include needed information? | Missed documents or weak query formulation |
These four already create a powerful diagnostic grid.
Diagnostic grid
| Faithfulness | Context recall | Likely story |
|---|---|---|
| Low | High | Generator invents or ignores good context |
| High | Low | Answer may be cautious or incomplete; retrieval missing info |
| Low | Low | Broad pipeline failure; fix retrieval first often |
| High | High | Strong grounded behavior on that set |
Always read metrics together, not in isolation.
Faithfulness: The Trust Metric
Faithfulness is the anti-hallucination metric for grounded answers.
Example
Context:
Enterprise plan includes SSO and audit logs. The free plan does not include SSO.
Question:
Does the free plan include SSO?
Faithful answer:
No. SSO is available on the enterprise plan, not the free plan.
Unfaithful answer:
Yes, all plans include SSO.
Even if a model’s world knowledge might sometimes be right in general, a RAG product that claims to answer from your docs must stay faithful to retrieved sources.
Tester workflow for faithfulness
- Build cases where the source of truth is explicit in docs.
- Run the pipeline.
- Score faithfulness.
- Inspect low-scoring answers claim by claim.
- Classify failures as retrieval miss vs generation invention.
For broader hallucination strategy beyond RAG metrics, see hallucination detection.
Answer Relevancy
Relevancy catches answers that are grounded in something but not useful.
Example failure:
- Question is about password reset.
- Retriever returns a security overview page.
- Answer summarizes MFA setup, never explains reset steps.
Faithfulness might be acceptable if it sticks to the MFA page. Relevancy should still fail.
Relevancy is also useful when models over-answer with long essays that bury the response.
Context Precision
Context precision asks whether the retrieved set is focused.
Symptoms of low precision:
- many unrelated chunks in the top-k
- answer quality depends on the model ignoring noise
- prompt context windows fill with junk
- cost rises because you stuff large noisy contexts
Improving precision may involve:
- better embeddings
- hybrid search
- re-rankers
- metadata filters
- query rewriting
- lower k with better ranking
Precision thought experiment
If top-5 contexts contain 1 useful chunk and 4 distractions, generation becomes harder and less stable. A precision-aware evaluation makes that visible even when occasional answers still look fine.
Context Recall / Contextual Recall
Context recall asks whether the necessary evidence was retrieved at all.
You often need a reference answer or annotated key facts to estimate this. If the gold answer requires “links expire in 30 minutes,” and no retrieved chunk contains that fact, recall is poor regardless of the generated text.
Precision vs recall tradeoff
| Retrieval style | Precision | Recall | Product effect |
|---|---|---|---|
| Very low k, strict filters | Higher | Risk lower | Clean but incomplete answers |
| Very high k, loose filters | Lower | Higher | Noisy contexts, higher cost |
| Hybrid + re-rank | Better balance | Better balance | Usually the engineering target |
Your metric dashboard should show both. Optimizing only one creates tunnel vision.
End-to-End Ragas Evaluation Workflow
Step 1: Define the RAG success criteria
Examples:
- policy answers must be faithful to the knowledge base
- out-of-scope questions should refuse
- citations required for billing answers
- p95 latency under a budget
Step 2: Build an evaluation dataset
Minimum fields:
questionreference_answeror key facts- optional
should_refuse - optional tags:
billing,auth,multi_hop
After running the pipeline, add:
answercontexts(list of retrieved chunk texts or ids)
Step 3: Run the pipeline in a frozen configuration
Record:
- model name
- prompt version
- embedding model
- chunking strategy
- top-k
- filters and re-ranker settings
If you do not freeze configuration, metric movement is uninterpretable.
Step 4: Score with Ragas metrics
Compute the core metrics per case and aggregate by tag.
Step 5: Diagnose by failure cluster
Group failures:
- retrieval misses
- noisy retrieval
- faithful but irrelevant answers
- relevant but unfaithful answers
- refusal errors
Step 6: Change one layer at a time
Do not simultaneously change embeddings, chunk size, prompt, and model. You will not know what helped.
Step 7: Re-score and compare
Ship only when critical tags improve or hold and no high-risk tag collapses.
RAG Evaluation Dataset Design
Dataset design is half the game.
Sources of good questions
- real support tickets anonymized
- search logs
- sales FAQs
- internal employee questions
- edge cases from incidents
Case types to include
| Type | Purpose |
|---|---|
| Single-hop factual | baseline retrieval and faithfulness |
| Multi-hop | requires combining chunks |
| Near-miss wording | semantic retrieval robustness |
| Out-of-scope | refusal behavior |
| Conflicting docs | version handling and recency policy |
| Tenant-specific | authorization and filter correctness |
| Numeric / date heavy | exact grounded values |
Size guidance
- 30-50 excellent cases can steer early development
- 100-300 tagged cases support serious regression
- thousands only help if quality and labeling remain trustworthy
A large dirty set creates metric theater.
For general dataset practices beyond RAG, see building an LLM eval dataset.
Worked Example: Billing Policy Bot
Knowledge base includes:
- Free plan has no SSO.
- Pro plan bills monthly or annually.
- Refunds are available within 14 days for annual plans.
Eval questions:
- Does free plan include SSO?
- What refund window applies to annual plans?
- Can I pay for Pro monthly?
- What is the refund window for hardware accessories? (out of scope doc set)
- Compare SSO availability across free and enterprise.
Expected diagnostic value:
- Q1-Q3 test straightforward grounded answers.
- Q4 tests refusal or “no info in knowledge base” behavior.
- Q5 tests multi-chunk composition.
Suppose results:
| Question | Faithfulness | Relevancy | Ctx precision | Ctx recall | Read |
|---|---|---|---|---|---|
| Q1 | 0.95 | 0.96 | 0.80 | 1.00 | healthy |
| Q2 | 0.40 | 0.90 | 0.75 | 1.00 | generator hallucination |
| Q3 | 0.90 | 0.70 | 0.30 | 1.00 | noisy retrieval, weak focus |
| Q4 | 0.85 | 0.40 | 0.20 | 0.00 | should refuse; retrieval garbage |
| Q5 | 0.70 | 0.80 | 0.55 | 0.50 | partial retrieval of comparison facts |
This table tells engineering what to do next far better than a single “quality = 0.72” number.
Ragas Faithfulness and Contextual Recall Tutorial Pattern
Teaching pattern for a single case:
# Pseudocode teaching pattern
case = {
"question": "What is the refund window for annual plans?",
"contexts": retrieve(question),
"answer": generate(question, contexts),
"reference": "Refunds are available within 14 days for annual plans.",
}
scores = evaluate_ragas(case)
assert scores["faithfulness"] >= 0.7
assert scores["context_recall"] >= 0.7
assert scores["answer_relevancy"] >= 0.7
When assertions fail:
if context_recall low:
inspect retriever, chunking, filters, query rewrite
elif faithfulness low:
inspect prompt grounding rules, model, temperature, citation constraints
elif relevancy low:
inspect instruction following and context noise
That triage loop is the operational heart of RAG evaluation.
Offline Evaluation vs Production Traces
Ragas is typically offline, but production traces can feed it.
Offline
- curated questions
- reproducible
- good for CI comparisons
Production replay
- sample real questions
- retrieve with current pipeline
- score faithfulness/relevancy
- watch for drift when docs change
Be careful with privacy: anonymize traces and avoid sending sensitive content to third-party judges without policy approval.
How Ragas Fits With DeepEval and Generic Metrics
Ragas is RAG-native. DeepEval is a broader unit-testing style framework for LLM apps. Generic metrics like BLEU rarely lead RAG debugging.
| Need | Good fit |
|---|---|
| Diagnose retrieval vs generation | Ragas |
| App-level pytest gates across many features | DeepEval |
| Metric theory and selection | LLM evaluation metrics guide |
| Hallucination product strategy | Hallucination detection guide |
See the DeepEval tutorial and LLM evaluation metrics for adjacent layers.
CI Design for RAG Metrics
PR smoke
- 20 critical billing/auth questions
- hard fail on faithfulness threshold
- hard fail on refusal cases that answer anyway
Nightly full
- full tagged set
- store metric history
- compare against main baseline
Release review
- metric deltas by tag
- human review of new failures
- doc change impact review
Engineering Levers Behind Metric Movements
| Metric movement | Try this |
|---|---|
| Context recall up needed | hybrid search, query expansion, higher k, better chunking |
| Context precision up needed | re-ranking, metadata filters, lower k, de-duplication |
| Faithfulness up needed | stronger grounding prompt, lower temperature, require citations, better context packing |
| Relevancy up needed | clearer system instructions, reduce noise, add answer outline rules |
| Cost too high | smaller k, compression, caching, smaller models for easy questions |
Metrics should point to levers, not shame the model abstractly.
Common Mistakes When Using Ragas
Mistake 1: Scoring Only Final Answers
If you ignore contexts, you cannot tell retrieval failures from generation failures.
Mistake 2: No Reference Coverage for Recall
Context recall needs a notion of required information. Without references or annotations, you under-measure misses.
Mistake 3: Synthetic-Only Datasets
If real users ask messy questions, synthetic perfect prose will overstate quality.
Mistake 4: Changing Everything Between Runs
Multi-knob experiments need controlled ablations.
Mistake 5: Over-trusting a Single Aggregate Score
Tag-level views catch safety or billing regressions hidden by averages.
Mistake 6: Not Refreshing After Doc Updates
Your knowledge base changed. Your eval set and expected answers must follow.
Mistake 7: Ignoring Authorization and Tenancy
A retrieved doc from the wrong tenant can look “relevant” and still be a critical defect. Add isolation tests beside Ragas metrics.
Mistake 8: Replacing Humans Entirely
Use humans to calibrate and to review high-risk failures.
Practical Team Workflow
- Pick one RAG feature, not the whole platform.
- Write 40 tagged questions with references.
- Log retrieved contexts and answers for baseline.
- Score faithfulness, relevancy, context precision, and context recall.
- Hold a one-hour triage reading ten worst cases.
- Choose one engineering lever.
- Re-run and compare.
- Automate the stable critical subset in CI.
- Add production failures back into the set weekly.
- Revisit thresholds after model provider changes.
Sample Reporting Format
RAG eval report - billing bot - 2026-07-09
pipeline: emb-v3 / chunk-512 / k=6 / rerank-on / gpt-X / prompt-17
Overall:
faithfulness: 0.84 (baseline 0.79)
answer_relevancy: 0.88 (0.87)
context_precision: 0.71 (0.62)
context_recall: 0.76 (0.70)
Critical tags:
refunds: pass 14/15
sso: pass 9/10
out_of_scope_refusal: pass 8/10 <-- investigate
Top actions:
1. Fix two refusal misses on hardware accessory questions
2. Keep reranker enabled (precision gain)
Reports like this make RAG quality discussable with engineering and product.
Cold Start and Empty Corpus Behavior
New products sometimes launch RAG against a thin or empty knowledge base. Evaluate that state explicitly.
Expected behaviors to define and test:
- clear “I do not have sources for that yet” refusals
- no confident invented policy answers
- admin visibility into missing coverage topics
- graceful handling when retrieval returns zero chunks
Empty-context generation is a major hallucination path. A dedicated zero-hit suite prevents the model from sounding certain when retrieval found nothing.
Also test partial corpus coverage: questions that are half-supported by docs should not be completed from model memory if product policy forbids it.
Multilingual and Locale-Specific RAG
If users ask in multiple languages, evaluation must reflect that.
Add cases for:
- question language differs from document language
- mixed-language queries
- locale-specific policies (region tax, regional support hours)
- translation drift that changes a legal meaning
Metric notes:
- relevancy judges may prefer fluent answers that are still factually wrong in translation
- retrieval may fail when embeddings are weak across languages
- faithfulness should still be judged against the authoritative locale source
Do not assume an English-only eval set protects a multilingual product.
Chunking Strategy and Its Metric Footprint
Chunking is an underrated RAG quality lever.
Common strategies:
- fixed token windows with overlap
- heading-aware document splits
- sentence packing to a size budget
- parent-child chunking where small chunks retrieve and large parents generate
How chunking shows up in Ragas-style metrics:
| Chunking issue | Likely metric symptom |
|---|---|
| Chunks too small | Low context recall; answers miss constraints |
| Chunks too large | Lower precision; model distracted or truncated |
| No overlap at boundaries | Recall fails when answer sits on a split |
| Heading ignored | Related policies mixed across products |
| Boilerplate repeated | Precision drops; repeated legal text dominates |
When faithfulness is fine and recall is weak, inspect chunk boundaries before rewriting the entire prompt.
Citations and User Trust
Many RAG products show citations. Citations need tests too.
Check that:
- cited chunk ids actually support the claim
- missing evidence produces fewer confident citations
- citation UI does not point to empty or wrong documents
- users can open the source and find the relevant sentence quickly
A faithful internal answer with decorative fake citations is still a product defect. Consider a citation support score in addition to plain faithfulness.
Hybrid Search and Re-Ranking Experiments
When context precision is low, teams often jump to “bigger top-k.” That can help recall and hurt precision.
A cleaner experiment ladder:
- baseline vector search
- add keyword/hybrid search
- add re-ranker on top-k candidates
- add metadata filters (product, version, tenant, language)
- only then consider larger k or query expansion
Score each step with the same dataset. Keep a leaderboard so the team does not regress to an older configuration by accident.
Governance for Knowledge Base Changes
Docs changes are code changes for RAG systems.
Process ideas:
- doc PRs trigger a smoke RAG eval on affected tags
- deprecated policies keep tombstone pages during migration
- version metadata is required on critical articles
- owners exist for each knowledge domain
- broken-link and stale-date crawlers feed the eval backlog
If legal updates a refund policy and eval references still expect the old window, your metrics will either fail loudly or, worse, be updated carelessly without product review. Treat reference answers as controlled artifacts.
When Not to Use Heavy RAG Metrics
Ragas-style evaluation may be overkill when:
- the feature is a short-lived prototype with no user trust requirement
- answers are purely creative and not grounded in a corpus
- you do not yet have any stable document set
In those cases, start with manual rubrics and a handful of golden examples. Introduce Ragas when retrieval quality becomes a real product risk.
Final Takeaways
Ragas helps you evaluate RAG pipelines with metrics that respect how RAG actually fails. Faithfulness protects trust. Relevancy protects usefulness. Context precision and contextual recall reveal whether retrieval is clean and complete. Chunking, citations, hybrid search, and knowledge governance are part of the same quality story.
Treat Ragas as a diagnostic system:
- measure
- separate retrieval from generation
- change one lever
- re-measure
- automate the high-signal subset
- refresh data when docs change
If you do that consistently, RAG quality stops being a debate about vibes and becomes an engineering loop you can run every week.
For hands-on practice judging grounded answers and retrieval failures, sign up at QABattle and use the battle arena to train the same evaluation instincts your metrics will later automate.
FAQ
Questions testers ask
What is Ragas in RAG evaluation?
Ragas is a framework and metric toolkit for evaluating retrieval-augmented generation pipelines. It helps teams score how well retrieved context supports answers and how well answers address questions, so you can improve retrieval, prompts, and generation without relying only on anecdotal review.
What metrics does Ragas use for RAG pipelines?
Common Ragas metrics include faithfulness, answer relevancy, context precision, and context recall. Together they separate retrieval quality problems from generation problems. Exact metric names and options evolve, but the core idea remains measuring groundedness, relevance, and context usefulness.
How do you measure context precision and recall?
Context precision checks whether the retrieved chunks are relevant and useful for the question, penalizing noisy retrieval. Context recall checks whether the information needed for a correct answer appears in the retrieved set, using reference answers or annotated requirements. High precision with low recall means clean but incomplete retrieval.
What is faithfulness in Ragas?
Faithfulness measures whether the generated answer is supported by the retrieved context rather than invented. Low faithfulness usually means hallucination relative to sources, even if the answer sounds fluent. It is one of the most important metrics for trusted RAG products.
How do you design a RAG evaluation dataset?
Collect real questions, pair them with source documents or gold answers, include easy and hard retrieval cases, add adversarial and out-of-scope questions, version the dataset, and refresh it when product docs change. A small high-quality set beats a large messy set that nobody trusts.
Can Ragas replace human evaluation?
No. Ragas scales offline evaluation and debugging for RAG systems, but humans still calibrate metrics, review safety edge cases, and judge product tone or policy nuance. Use Ragas for breadth and regression, and human review for calibration and high-risk decisions.
RELATED GUIDES
Continue the route
LLM Evaluation Metrics: A Practical Guide
A practical guide to LLM evaluation metrics: faithfulness, answer relevancy, BLEU vs semantic scores, LLM-as-judge, and offline vs online eval.
DeepEval Tutorial: Unit Testing for LLM Applications
DeepEval tutorial for unit testing LLM applications with pytest-style metrics, G-Eval rubrics, faithfulness examples, and DeepEval vs Ragas.
Building an LLM Eval Dataset: Golden Sets and Rubrics
Learn building an LLM eval dataset with golden sets, rubrics, synthetic data, human labels, edge cases, sizing rules, and versioning for reliable evals.
Hallucination Detection: Testing LLMs for Accuracy
Learn LLM hallucination detection with groundedness scoring, factual consistency checks, rate measurement methods, and practical accuracy test design.