RAG in the LLM Era: From Demo to Production
RAG in the LLM Era: From Demo to Production
In November 2024, the head of engineering at a 200-person B2B SaaS company in San Mateo spent roughly six weeks and about $140,000 building what was, on paper, a state-of-the-art retrieval-augmented generation system. The internal demo wowed the board: an assistant that could answer nuanced questions about customer onboarding, billing edge cases, and product roadmap tradeoffs by synthesizing information from 30,000 internal documents, with citations that linked back to the exact source paragraph. A 250-question evaluation harness scored it 4.7 out of 5, and a panel of 12 customer success managers gave it a thumbs-up in user testing. Three months after launch, 58% of customer-facing answers were demonstrably wrong, 22% of those with high confidence. The system is now being rebuilt from scratch, the director who greenlit it is no longer in the role, and the company has publicly committed to shipping "version 2" in 2025 with a fundamentally different architecture.
The story is not unusual. It is, in fact, the modal production RAG failure of 2024: a system that is technically correct on a benchmark but operationally wrong on real traffic. The benchmark was hand-curated by the team that built the system. The real users asked questions nobody had anticipated. The retrieval pipeline surfaced semantically related chunks that did not contain the actual answer. The model then summarized those chunks confidently, with citations that pointed to the wrong place, and customers lost trust faster than the analytics dashboard could measure it.
This chapter is about closing that gap. We will trace the evolution of retrieval-augmented generation from the 2020 paper to the agentic and graph-based variants that dominate 2025, and then move quickly to the engineering reality. We will introduce a five-axis quality framework you can use to audit any RAG system, walk through a real production failure in detail, and catalog the four failure modes that account for the majority of production incidents. By the end of the chapter, you should be able to take any existing RAG deployment, score it against the funnel, and produce a prioritized list of remediation work. This is also a framing chapter: the rest of the book is organized around the engineering lifecycle of a production RAG system, and Section 1.3 contains the map.
1.1 The Historical Arc: From 2020 to 2025
When Patrick Lewis and colleagues at Facebook AI published "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" in May 2020, the architecture they proposed was straightforward by today's standards. A pre-trained Dense Passage Retrieval (DPR) encoder would embed a question into a vector, retrieve the top-20 most similar passages from a Wikipedia-scale corpus, and a BART sequence-to-sequence model would condition its generation on those passages. The paper reported state-of-the-art results on five knowledge-intensive benchmarks including Natural Questions, TriviaQA, and WebQuestions, and the field took notice. What the paper assumed, however, was that retrieval was a static, single-shot operation over a fixed corpus, and that a sufficiently capable generator would obediently follow the retrieved context. Both assumptions turned out to be incomplete when the architecture met the open web and, later, the enterprise.
The naive RAG pattern that dominated 2023 demos was a direct descendant. You take a corpus, chunk it into 500-token windows, embed each chunk with a sentence-transformer model, store the vectors in Pinecone, Weaviate, or Chroma, and at query time embed the user question, do a cosine similarity lookup, take the top-5 chunks, and stuff them into a prompt asking the LLM to answer. The pattern is sometimes called "search then stuff," and it is almost exactly the architecture behind the doomed San Mateo demo we opened with. The reason it works on small, clean datasets is that the failure modes have not yet had a chance to manifest. The reason it fails in production is that every single component of the pipeline has a long tail of failure that does not show up in 250 hand-curated questions.
Between 2023 and late 2024, the field coalesced around a layered taxonomy. Gao et al. at Renmin University formalized four patterns in a 2024 survey that has become the standard reference, and the taxonomy is worth internalizing because it gives you a vocabulary for talking about your system.
Naive RAG is the baseline: chunk, embed, retrieve, generate, with no pre-retrieval or post-retrieval processing. It is what every five-line LangChain tutorial implements, and it is what most failed production systems of 2023 and 2024 were. Naive RAG is sensitive to chunk boundary artifacts, embedding model choice, and prompt format. A 512-token chunk that cuts a clause in half can produce a top-5 result that is technically similar but semantically incomplete. A user question that uses different vocabulary from the corpus can return irrelevant chunks. A prompt that does not explicitly instruct "answer only from the context" will produce confident hallucinations when the retrieved context is wrong or empty. The taxonomy's value here is not that it tells you naive RAG is bad — you already suspected that — but that it gives you a vocabulary for the things you need to add.
Advanced RAG adds pre-retrieval and post-retrieval stages. Pre-retrieval includes query rewriting (using an LLM to expand, decompose, or transform the user question into a form more likely to match relevant chunks), query routing (deciding which index or corpus to query, often based on metadata filters or intent classification), and Hypothetical Document Embedding, or HyDE, where an LLM generates a hypothetical answer that is then embedded and used as the query vector. Post-retrieval includes reranking (using a cross-encoder or LLM-based reranker to reorder the top-K candidates by a more expensive but more accurate relevance signal), context compression (trimming retrieved chunks to only the spans relevant to the question), and citation extraction. Advanced RAG is what most teams that ship to production in 2024 actually run. The improvement over naive RAG is substantial: reranking alone typically lifts top-5 precision by 10 to 20 percentage points on internal benchmarks, and query rewriting can recover another 5 to 10.
Modular RAG generalizes the pattern further. Instead of a fixed pipeline, you have a set of composable modules — search, memory, routing, reasoning, generation, verification — that can be wired together in different configurations for different query types. This is where frameworks like LangGraph, LlamaIndex Workflows, and Haystack pipelines start to make sense, and where the abstractions map closely to how production systems are actually structured. The modular view exposes a useful design principle that is easy to miss: every stage of the pipeline should be independently testable and replaceable. If you cannot swap your reranker without breaking the system, you do not have a modular system; you have a coupling problem. The modular pattern also makes it natural to specialize: a query about a customer's billing history can be routed to a structured query path, while a query about product policy can be routed to a semantic search path, all through the same orchestration layer.
Agentic RAG, which became the dominant pattern in late 2024 and into 2025, treats retrieval as a tool that an LLM agent can call, possibly multiple times, possibly in parallel, possibly with self-correction. The agent decides whether it has enough information to answer, whether it needs to look at a different source, whether the retrieved context is contradictory, whether to ask the user a clarifying question, and whether to break the question into sub-questions. Frameworks like ReAct, AutoGen, LangGraph's prebuilt agents, and the OpenAI Agents SDK have made this pattern accessible, and a growing fracti