The 80% Problem
Most RAG demos look magical. You drop in 10 PDFs, ask 3 questions, get clean answers. Ship it.
Then production hits. The document corpus grows from 10 to 10,000. Users ask questions the demo never anticipated. Edge cases stack up. Accuracy drops from 95% to 60% in two weeks. The team starts apologising to the client.
I've built 20+ production RAG systems for clients across the USA, UK, UAE, Canada, Australia, Switzerland, and Pakistan. About 80% of the RAG projects I audit before clients hire me are in this exact failure mode — they passed the demo, then collapsed under real data.
The fixes aren't more complex models. They're architectural patterns designed for failure modes from day one. Here are the five that matter most.
Failure 1: Hallucinations on edge cases
A vanilla RAG pipeline does this: embed the user query, retrieve top-k documents, stuff them into a prompt, ask the LLM to answer. When retrieval finds something, the LLM dutifully constructs an answer — even when the retrieved context is unrelated to the question.
In production, you get confident-sounding nonsense on the long tail of queries.
The fix: a self-correction loop. Before the LLM answers, force it to grade the retrieved context against the question. If the grade is poor, rewrite the query or fall back to a "I don't have enough information" response.
from langgraph.graph import StateGraph, END
def grade_relevance(state):
docs = state["documents"]
question = state["question"]
prompt = f"""Given the question and retrieved documents, score 0-10 how
relevant the documents are to answering the question. Be strict.
Question: {question}
Documents: {docs[:3000]}
Respond with just a number."""
score = int(llm.invoke(prompt).content.strip())
return {"relevance_score": score}
def route_after_grading(state):
if state["relevance_score"] < 6:
return "rewrite_query"
return "generate_answer"
graph = StateGraph(RAGState)
graph.add_node("retrieve", retrieve)
graph.add_node("grade", grade_relevance)
graph.add_node("rewrite_query", rewrite_query)
graph.add_node("generate_answer", generate_answer)
graph.add_conditional_edges("grade", route_after_grading)
I built exactly this pattern for an enterprise client — full breakdown in my .
Failure 5: No evaluation harness = no improvement
Most teams ship RAG without an evaluation pipeline. Then when accuracy degrades, they can't tell:
- Did retrieval get worse?
- Did the LLM get worse?
- Did the data get harder?
- Was it always this bad and we just didn't notice?
You can't fix what you can't measure.
The fix: a golden dataset + automated nightly eval. 50–100 hand-curated question/answer pairs covering your edge cases. Run them through the system every deploy. Track three metrics:
def evaluate_rag(golden_dataset, rag_system):
results = {
"retrieval_hit_rate": 0, # did retrieval find the right doc?
"answer_correctness": 0, # did the final answer match?
"faithfulness": 0, # was the answer grounded in retrieved docs?
}
for q, expected_doc_ids, expected_answer in golden_dataset:
retrieved = rag_system.retrieve(q)
answer = rag_system.answer(q)
results["retrieval_hit_rate"] += any(d.id in expected_doc_ids for d in retrieved)
results["answer_correctness"] += llm_judge(answer, expected_answer)
results["faithfulness"] += llm_judge_grounding(answer, retrieved)
return {k: v / len(golden_dataset) for k, v in results.items()}
This is the single highest-leverage thing you can build. Every RAG improvement I've shipped started with one of these metrics moving in the wrong direction.
The Pattern: Design for failure on day 1
If I had to compress all 20 RAG projects into one sentence: the production-ready systems are the ones designed for failure from the first commit. Self-correction loops, hash-based incremental indexing, hybrid retrieval, multimodal embeddings, and an evaluation harness aren't optimizations you add later — they're load-bearing infrastructure.
Most "AI demos that broke in production" stories are really "demos without failure handling that met production." The fix isn't a smarter model. It's better architecture.
If you're building a RAG system that needs to survive real data, look at every component and ask: what happens when this fails? If you don't have an answer, that's the next thing to build.
About the Author
I'm Open for AI consulting, RAG system development, AI agent development, and LLM application work. Typical MVP delivery: 2–4 weeks. If you found this useful, follow me here on dev.to — I publish field notes from real production AI work.
SOCIAL SHARE CARD GENERATOR