Evaluating RAG with RAGAS

AIRAGEvaluationRAGAS
Share on LinkedIn

The team swapped embedding models and celebrated a 12% latency improvement. Nobody ran evals until support tickets spiked two weeks later — context recall on billing questions had dropped 23 points, and the new model consistently missed refund policy chunks. Latency metrics looked great; quality metrics were never measured. RAGAS exists so you catch that regression before users do.

Why RAG needs component-level metrics

End-to-end accuracy alone cannot tell you whether to fix retrieval or generation. A wrong answer might mean:

RAGAS decomposes the pipeline into measurable components so you know which knob to turn.

Core RAGAS metrics explained

Faithfulness — measures whether statements in the generated answer are supported by retrieved context. Low faithfulness means hallucination or over-extrapolation even when retrieval was correct.

Answer relevancy — measures whether the answer actually addresses the question. High faithfulness with low relevancy means the model cited real docs but answered a different question.

Context precision — measures what fraction of retrieved chunks are relevant to the question. Low precision means noisy retrieval crowding the context window.

Context recall — measures whether retrieved context contains the information needed to produce the ground truth answer. Requires reference answers. Low recall means chunking or search problems.

Symptom Likely low metric Fix direction
Wrong facts with good sources available Faithfulness Prompt, model, post-checks
Right facts, wrong question answered Answer relevancy Prompt, query routing
Right answer buried in irrelevant chunks Context precision Reranking, smaller top-k
Correct answer not in retrieved set Context recall Chunking, embeddings, hybrid

Running RAGAS in Python

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

eval_data = {
    "question": ["What is the refund window for Enterprise plans?"],
    "answer": ["Enterprise plans allow refunds within 60 days of purchase."],
    "contexts": [[
        "Enterprise plan terms: Refunds requested within 60 days...",
        "Starter plan terms: All sales are final..."
    ]],
    "ground_truth": ["Enterprise refunds are available within 60 days."],
}

dataset = Dataset.from_dict(eval_data)
results = evaluate(
    dataset,
    metrics=[faithfulness, answer_relevancy, context_precision, context_recall],
    llm=eval_llm,       # judge model — lock the version
    embeddings=eval_emb,
)

print(results)

RAGAS uses an LLM as judge for several metrics. Lock the judge model version — switching judges changes absolute scores and breaks comparability across runs.

Building a useful eval dataset

Quality beats quantity. 50 well-crafted examples covering:

Source questions from production logs (anonymized), support ticket themes, and onboarding FAQs. Label ground truth answers and the chunk IDs that should retrieve.

CI integration pattern

# Simplified CI step
- name: RAG eval gate
  run: |
    python scripts/run_ragas_eval.py \
      --dataset evals/rag_golden_v3.jsonl \
      --min-faithfulness 0.85 \
      --min-context-recall 0.75

Fail the build when metrics drop below thresholds compared to the baseline stored from the last approved run. Store full result JSON as CI artifacts for trend analysis.

Run evals on pipeline changes, not every application deploy. Embedding model swaps, chunk strategy changes, prompt rewrites, and reranker updates all warrant a RAGAS run.

Limitations to plan around

Use RAGAS for regression detection and component debugging. Pair it with human review on a sample of production answers monthly.

Ragas metrics interpretation

Metric Measures Target
faithfulness Answer grounded in context > 0.85
answer_relevancy Answer addresses question > 0.80
context_precision Retrieved chunks relevant > 0.75
context_recall Needed info retrieved > 0.80

Run Ragas on 100-question golden set weekly — track drift when changing chunking or embedding model.

Common production mistakes

Teams get evaluation ragas framework wrong in predictable ways:

RAG pipelines for evaluation ragas framework degrade when chunk boundaries split tables, embeddings go stale after doc updates, and retrieval metrics are measured offline only. Re-index incrementally and monitor answer faithfulness on live traffic samples.

Debugging and triage workflow

When evaluation ragas framework misbehaves in production, work top-down instead of guessing:

  1. Confirm scope — one tenant, region, or deployment stage? Narrow blast radius before deep diving.
  2. Check recent changes — deploys, flag flips, config pushes, and schema migrations in the last 24 hours.
  3. Compare golden signals — latency, error rate, saturation, and traffic for the affected surface vs. baseline.
  4. Reproduce minimally — smallest input or scenario that triggers the failure; capture traces/logs with correlation IDs.
  5. Fix forward or rollback — if rollback is faster than root-cause during incident, rollback first, postmortem second.
  6. Add a guard — alert, integration test, or circuit breaker so the same class of failure is caught earlier next time.

Document the timeline during triage. Future you (and on-call) will need timestamps, not just conclusions.

Resources

Frequently asked questions

What metrics does RAGAS provide for RAG evaluation?

Core metrics include faithfulness (are claims supported by retrieved context?), answer relevancy (does the answer address the question?), context precision (are retrieved chunks relevant?), and context recall (was all necessary information retrieved?). RAGAS also offers aspect-specific critiques and newer agent-focused metrics. Together they decompose pipeline failures into retrieval vs generation problems.

Do I need ground truth answers to use RAGAS?

Some metrics like context recall and answer correctness require ground truth references. Faithfulness and answer relevancy can run without golden answers by using LLM-as-judge evaluation against retrieved context. Start with faithfulness on production logs even before you build a full golden eval set.

How do I integrate RAGAS into CI/CD?

Maintain a frozen eval dataset of 50–200 question-context-answer triples. Run RAGAS scoring on every pipeline change — embedding model, chunk size, prompt template — and fail CI if key metrics drop below thresholds. Keep eval LLM calls separate from production inference to control cost and version lock the judge model.

Hiring a senior Android / Flutter engineer?

I architect and ship production mobile software — Kotlin, Jetpack Compose, Flutter — for robotics, EV infrastructure, fintech, and real-time systems. Open to remote roles in Europe and the US.

Get in touch →