Learn/LangChain Mastery/Part 9 · 8. Production, Evaluation & Governance
Lesson 64 of 68
SyllabusLangChain Mastery · Part 9

RAG Evaluation Basics

Beyond 'vibes'. Measuring what matters.

Course outline & contents
LangChain Mastery
Async & High-Throughput PatternsLatency & TTFT OptimizationTracing with LangSmithRAG Evaluation BasicsFaithfulness & RelevancePrompt Injection DefenseInput & Output GuardrailsDeployment & API Serving

You act as the QA. You ask 5 questions. The bot answers 4 correctly. You ship it. In production, users ask 5,000 questions. The bot fails 2,000 of them. Anecdotal Testing is not Evaluation.

Before you deploy, run a test suite. You need a Gold Dataset: A CSV of (Question, Ground_Truth_Answer, Ground_Truth_Document_ID).

Metrics:

  1. Retrieval Metrics:
    • Recall@5: Is the correct Document ID in the top 5 results?
    • MRR (Mean Reciprocal Rank): How high up was it?
  2. Generation Metrics:
    • Semantic Similarity: Is the generated answer effectively the same as the Ground Truth answer? (Use an LLM to judge this).

Users are the best testers. Add a "Thumbs Up / Thumbs Down" button. Log every Thumbs Down to LangSmith. Review them weekly. These are your "Hard Negatives." Add them to your Offline Dataset. This creates a Data Flywheel.

We can't manually read 5,000 logs. We use a strong model (GPT-4) to grade the weak model (GPT-3.5). Prompt: "You are a judge. Verify if the Student Answer matches the Ground Truth. Score 1 to 5."

Evaluation is not a one-time event. It is a Continuous Integration (CI) pipeline. Code has Unit Tests. AI has Evals.

Key Intuition: "If you don't measure it, you can't improve it."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonTracing with LangSmithNext lesson →Faithfulness & Relevance