惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
L
LangChain Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
博客园_首页
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
美团技术团队
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Evaluating RAG Systems: Measuring Retrieval Quality, Grou...
Abhi Chatter · 2026-05-08 · via DEV Community

Part 3 of a series on building reliable AI systems


In Part 1, we explored why testing AI systems is different.
In Part 2, we built evaluation pipelines.

Now let’s focus on one of the most widely used (and misunderstood) patterns:

Retrieval-Augmented Generation (RAG).

RAG is often seen as a solution to hallucinations.

In reality, it just shifts the problem.


The Core Problem with RAG

A typical RAG pipeline looks like this:

User Query
    ↓
Retriever → Context
    ↓
LLM → Response

Enter fullscreen mode Exit fullscreen mode

When something goes wrong, it’s not always obvious where the failure is.

  • Did retrieval fail?
  • Was the context irrelevant?
  • Did the model ignore the context?
  • Or did it hallucinate anyway?

Without proper evaluation, everything looks like a “model problem.”


RAG Has Two Systems, Not One

This is the key insight:

You are not evaluating a single system—you are evaluating two tightly coupled systems.

  1. Retriever (search problem)
  2. Generator (language problem)

If you don’t evaluate them separately, debugging becomes guesswork.


What Should You Measure?

To evaluate RAG properly, you need to break it into components.


1. Retrieval Quality

Question: Did we fetch the right information?

Metrics to consider:

  • Top-K relevance
  • Context recall (was the correct doc retrieved?)
  • Ranking quality

Example failure:
The correct document exists—but wasn’t retrieved.

No model can fix missing context.


2. Context Relevance

Question: Is the retrieved content actually useful?

Even if retrieval “works,” the context may be:

  • Noisy
  • Partially relevant
  • Outdated

This leads to weak or incorrect answers.


3. Grounding / Faithfulness

Question: Did the model use the retrieved context?

This is one of the most critical checks.

Failure patterns:

  • Model ignores context
  • Adds unsupported information
  • Mixes correct and hallucinated facts

Evaluation idea:
Compare response against context—not just expected answer.


4. Answer Correctness

Question: Is the final answer actually correct?

This is what users see—but it’s the last layer.

Important:
Correct answers can still be poorly grounded, which is risky.


5. Hallucination Rate

Question: How often does the model generate unsupported information?

This is especially important in:

  • Customer support
  • Healthcare
  • Finance

Track it explicitly—it won’t surface automatically.


A Practical Evaluation Flow

Here’s how you can structure RAG evaluation:

Input (Query)
   ↓
Retrieve Documents
   ↓
Evaluate Retrieval
   ↓
Generate Answer
   ↓
Evaluate Grounding + Correctness

Enter fullscreen mode Exit fullscreen mode


Example Evaluation Loop

for sample in dataset:
    docs = retriever.retrieve(sample["query"])

    retrieval_score = evaluate_retrieval(docs, sample["expected_docs"])

    answer = llm.generate(sample["query"], context=docs)

    grounding_score = evaluate_grounding(answer, docs)
    correctness_score = evaluate_answer(answer, sample["expected_answer"])

    log({
        "query": sample["query"],
        "retrieval": retrieval_score,
        "grounding": grounding_score,
        "correctness": correctness_score
    })

Enter fullscreen mode Exit fullscreen mode


Real-World Failure Patterns

These show up again and again:

1. “Looks correct, but isn’t grounded”

  • Answer sounds right
  • Not supported by retrieved context

2. “Right data, wrong answer”

  • Correct document retrieved
  • Model misinterprets it

3. “No retrieval, full hallucination”

  • Retriever fails
  • Model still generates confident answer

4. “Too much context”

  • Irrelevant documents dilute signal
  • Model produces vague responses

Common Mistakes

  • Evaluating only final answer
  • Ignoring retrieval metrics
  • Assuming RAG eliminates hallucinations
  • Not separating retrieval vs generation failures

Practical Tips

  • Start with a small, high-quality dataset
  • Log retrieved documents for every query
  • Evaluate components separately
  • Track metrics over time (not just one run)

What’s Next

In the next part, I’ll go deeper into:

  • Evaluating AI agents (multi-step workflows)
  • Tracing and debugging agent behavior
  • Measuring task success and failure modes

Final Thoughts

RAG doesn’t remove hallucinations—it changes where they come from.

If you only evaluate outputs, you’ll miss the real problem.

Reliable RAG systems come from:

  • Strong retrieval
  • Grounded generation
  • Continuous evaluation

Because in RAG, the answer is only as good as the context behind it.