TL;DR: Building a RAG system that works in production requires five steps: scope a narrow MVP, create a golden dataset of query-context pairs, build a baseline retrieval system with proper eval metrics, build a baseline response system with error analysis, then iterate with controlled experiments. Most failures come from skipping the golden dataset and eval steps.
Why RAG Demos Collapse in Production
RAG (Retrieval-Augmented Generation) is straightforward in concept: retrieve relevant documents, feed them to an LLM, get a grounded answer. The demo cycle is predictable — dump documents into a vector database, wire up a retrieval pipeline, test with questions you already know the answers to, demo looks great.
Then deployment happens and the system underperforms. The problem isn’t the technology — it’s the process. People skip the evaluation infrastructure and jump straight to building, which means they have no way to systematically improve what they’ve built.
Step 1 — Scope the MVP
Before writing any code, answer three questions:
- Who are the users? Technical or non-technical, what roles, what teams.
- What is the use case? Customer support, legal, insurance claims, internal knowledge base — and equally important, what the system will not do.
- What is the inventory? Which source documents go into the knowledge base.
The most common mistake is over-scoping: trying to serve all users, all use cases, all data sources. In practice, a small percentage of possible RAG systems generates most of the value. Start with one user persona, one use case, and one or two data sources. A six-week timeline for the first version is realistic — over-scoped projects stall or produce mediocre results.
Step 2 — Create a Golden Dataset
A golden dataset is a set of query-context pairs that serves as ground truth for evaluating your retrieval system. Each entry has a user input (a question, a claim, any input the system receives) and the correct retrieval result (the document, video ID, or chunk that should be retrieved).
How to Build It
Best approach: use real-world queries from an existing system. Extract actual user inputs and manually curate the correct context for each.
When no baseline exists: synthetic query generation. Feed your source documents to an LLM with a carefully crafted prompt that generates diverse queries across multiple dimensions:
- Personas: individual contributor vs. manager
- Use cases: onboarding, policy lookup, troubleshooting
- Query types: factual (what is X), conceptual (why does Y matter), procedural (how do I do Z)
- Difficulty: easy (grounded in a clear snippet), medium, hard (includes typos, false assumptions, confused phrasing)
Shaw Talebi’s YouTube answer engine used a 3×3 matrix: three query types × three difficulty levels = 9 queries per video, then manually reviewed and trimmed to 6 per video. Quality over quantity — a smaller set of high-quality examples beats a larger set of noisy ones.
Dev/Test Split
Reserve a portion of the golden dataset for development and keep a separate test split. Optimize on the dev set, evaluate on the test set. This prevents overfitting your eval suite to a specific set of queries.
Step 3 — Build Baseline Retrieval with Eval Metrics
Build the simplest retrieval system that works — vector search, lexical search, or hybrid. The tool choice matters less than defining how you measure success.
Retrieval Evaluation Metrics
Precision: percentage of retrieved chunks that are relevant. Useful when you care about the relevance ratio in results.
precision = true positives / (true positives + false positives)Recall@K: percentage of all relevant chunks that appear in the top K results. Useful when you just need the right document to be in the results, regardless of position.
recall@K = (relevant results in top K) / (total relevant results)MRR (Mean Reciprocal Rank): aggregate metric across multiple queries based on the rank of the first relevant result.
MRR = (1/Q) × Σ(1/rank_i)Pick the metric that fits your use case. For a system where each query has one correct document, recall@K is straightforward — either the right document is in the top K or it isn’t.
Step 4 — Build Baseline RAG with Error Analysis
Keep retrieval and response generation as separate components. This lets you isolate whether problems come from bad search results or bad generation.
Classic RAG vs. Agentic RAG
Classic RAG follows a linear pipeline: user query triggers retrieval, results go to the LLM, LLM generates a response. Simple, predictable, but has failure modes — unnecessary retrievals for greetings, failed retrievals for unclear queries.
Agentic RAG gives the LLM a retrieval tool and lets it decide when to search. More flexible, but introduces new failure modes — the agent might retrieve when it shouldn’t, or skip retrieval when it should. Start with classic RAG, then transition to agentic once the base system is solid.
Evaluating Open-Ended Responses
There’s no off-the-shelf metric for evaluating natural language responses. The answer is manual error analysis:
- Run your system on the test split
- Read every response and leave open-ended notes
- Look for patterns — read at least 30 responses, ideally 100
- When a failure appears more than once, tag it
Common failure tags that emerged from Shaw’s system:
- Bad framing: model responds as if the user provided the source documents, not an internal retrieval tool
- Overly complex language: too technical for the target audience
- Outdated code: generating code examples that no longer work
- Bad narrative: unstructured word vomit instead of coherent response
Automating Evaluations
Once patterns are identified, automate them:
Code-based evals — simple string checks for predictable failure patterns. Example: if “based on the provided transcripts” appears in the response when it shouldn’t, flag it. Prefer these whenever possible — they’re simple, deterministic, and easy to debug.
LLM-based evals — use an LLM judge for failures that can’t be caught with string checks (e.g., bad narrative structure). The critical gotcha: the LLM judge’s labels won’t automatically align with your manual labels. Tuning this alignment is a mini-project in itself. Use a dev/test split for the judge labels too.
Step 5 — Run Controlled Experiments
With a baseline system and eval suite in place, iterate by changing one thing at a time:
- Experiment 1: baseline (classic RAG, raw transcripts, no prompt optimization)
- Experiment 2: prompt change to fix bad framing (bad framing drops from 50% to 7%)
- Experiment 3: data preprocessing (lowercase, stop word removal, lemmatization)
- Experiment 4: chunking strategy (smaller chunks, 2–5 minute segments)
- Experiment 5: reranker, different embedding model, hybrid search tuning
The key principle: improvements should be driven by specific failures, not guesses. If recall@3 is low, focus on the retrieval pipeline (preprocessing, chunking, embedding model). If bad framing is high, focus on the prompt. If narrative quality is poor, consider prompt engineering or a more capable model.
Design for experimentation, not production, in the early stages. Remove all friction from running experiments quickly — the goal is rapid iteration with clear before/after metrics.
Where to Start
Almost always, the best place to start improving is the retrieval system. Better extraction, better preprocessing, better chunking, and better sources typically yield the biggest gains. Rerankers, query rewriting, and model upgrades come after the data foundation is solid.
References
- “How to Build RAG Systems (in the real world)” — Shaw Talebi, YouTube (January 1, 2026) — https://www.youtube.com/watch?v=2peE6mwoiXs
- yt-answer-engine — GitHub repository with eval pipeline, query generation, and experiment code — https://github.com/ShawhinT/yt-answer-engine
- “LLM Judge with Human Preferences” — Hamel Husain (step-by-step dataset creation for LLM evaluation) — https://hamel.dev/blog/posts/llm-judge/
- “Evaluation of Retrieval-Augmented Generation: A Survey” — arXiv.07437 — https://arxiv.org/abs/2405.07437
- Query Generation Utility — ShawhinT/yt-answer-engine utils/query_gen — https://github.com/ShawhinT/yt-answer-engine/tree/main/utils/query_gen
This article was written by Hermes (glm-5-turbo | zai), based on content from: https://www.youtube.com/watch?v=2peE6mwoiXs

