What happens when a language model is asked about something that occurred after its training data ended, or about a document that was never public? In a plain model, the answer is often a confident guess. Retrieval-augmented generation, usually shortened to RAG, exists to change that outcome. Instead of relying only on what a model memorized during training, a RAG system fetches relevant documents at the moment of the query and hands them to the model as context. The idea is simple to describe and surprisingly hard to run well.
This article explains where the technique came from, how the pipeline is built, what it genuinely fixes, and where teams most often get it wrong. The emphasis is on the gap between the demo and the production system, because that gap is where most RAG projects live or die.
Where the term came from
The label was introduced in a 2020 paper, “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks,” by Patrick Lewis and colleagues at Facebook AI Research, University College London, and New York University. The paper described a specific architecture: a dense retriever paired with a sequence-to-sequence generator, evaluated on open-domain question answering datasets such as Natural Questions, TriviaQA, and WebQuestions.
Two design choices from that paper still shape how people talk about RAG. In the RAG-Sequence variant, one set of retrieved passages conditions the entire output. In the RAG-Token variant, different passages can influence different parts of the generated answer. The authors framed the approach as a way to give a model access to non-parametric memory that can be updated without retraining, and to make provenance easier to inspect than in a purely parametric system. That rationale is the paper’s stated motivation, not an independently measured result.
The retriever in that original setup was Dense Passage Retrieval, a dual-encoder model that maps questions and passages into the same vector space. DPR became a standard reference point for the retrieval half of any RAG pipeline, and much of the later tooling is a descendant of it.
Since roughly 2023, the term has drifted. In industry usage, “RAG” now often means any pipeline that injects retrieved context into a large language model prompt, which is considerably broader than the 2020 architecture. That drift matters when two teams say they “do RAG” and mean very different things.
How a RAG pipeline is put together

A working system has four moving parts, and each one can fail independently.
- Ingestion. Documents are collected, cleaned, and split into chunks. Chunk size and overlap are decisions, not defaults, and they affect everything downstream.
- Indexing. Chunks are converted into vectors by an embedding model and stored in a vector database, often alongside keyword indexes.
- Retrieval. At query time, the system embeds the question, searches the index, and returns the top-k passages. Many production systems combine dense vectors with lexical search in a hybrid setup.
- Generation. The retrieved passages are inserted into the prompt, and the model writes an answer grounded in them.
The step people underestimate is the first one. A chunk that splits a table in half, or cuts a sentence off mid-clause, produces an embedding that represents nothing useful. Practical teams often test two or three chunking strategies before touching the retriever, because garbage chunks cannot be rescued by a better search algorithm.
Dense, sparse, and hybrid retrieval
Dense retrieval uses embeddings and captures meaning, so a query about “cancellation windows” can match a passage about “notice periods” even without shared words. Sparse retrieval, classically BM25, matches on terms and handles exact identifiers, product codes, and rare names far better than embeddings usually do.
The BEIR benchmark, a heterogeneous zero-shot information retrieval benchmark, found that BM25 remains a strong baseline across domains. That finding is widely cited when teams choose retrieval methods, and it is a useful corrective to the assumption that newer always means better. For readers who want the underlying mechanics, the standard textbook Introduction to Information Retrieval covers ranking functions like BM25 in detail. (A practical checklist for evaluating retrieval quality) (Retrieval-augmented generation (Wikipedia))
In practice, most mature systems run both and merge the results, a pattern called hybrid search. It costs more compute and adds a ranking step, but it covers the failure modes of each method alone.
What RAG genuinely fixes, and what it does not
The honest answer is narrower than the marketing suggests.
RAG fixes the problem of stale or private knowledge. If the answer lives in a document the model never saw, retrieval can bring it into context. It also improves inspectability: you can look at the passages that were retrieved and judge whether the answer had a fair basis.
RAG does not fix everything. Three limits come up again and again:
| Claim | What actually holds |
|---|---|
| “RAG eliminates hallucination” | Retrieval reduces some unsupported claims but does not guarantee that generated text is supported by the retrieved passages. Models can still contradict or drift from their context. |
| “RAG removes the need for fine-tuning” | RAG changes what the model can see at inference time. It does not teach new formats, styles, or behaviors reliably. |
| “Better retrieval always means better answers” | Only if the generator uses the context faithfully. A perfect passage can still be misread. |
The hallucination point deserves emphasis. The 2020 paper reported task accuracy gains; it did not claim to eliminate hallucination. Research on attribution, such as work measuring whether generated statements are supported by cited sources, exists precisely because retrieval and faithfulness are separate problems. Measuring attribution is now a research area in its own right, and any vendor claiming retrieval makes fabrication impossible is overstating the evidence.
Why retrieval quality is the ceiling
There is a blunt design property in every RAG system: if the relevant passage is not retrieved, the generator cannot ground on it. No prompt instruction recovers a document that never made it into the context window. This is consensus framing rather than a single measured result, but it explains why teams that tune prompts for weeks and never touch retrieval tend to plateau.
A few practical habits separate teams that get this right from teams that do not.
Build an evaluation set before tuning. Twenty to fifty real questions with known correct source passages will tell you more than any intuition. If the right passage is not in the top-k results, the retriever is the problem, not the prompt. A structured approach helps here; this checklist for evaluating retrieval quality walks through the metrics that matter.
Separate retrieval failures from generation failures. When an answer is wrong, check first whether the correct passage was retrieved. If it was, the problem is in the prompt or the model. If it was not, chunking, embeddings, or the query itself need attention. Conflating the two wastes weeks.
Watch access control. In any system with per-user permissions, retrieval must respect them. A pipeline that indexes everything and filters nothing will happily surface a confidential document to the wrong person. Reviewing who can reach which part of the index is not optional; this guide to reviewing access to a retrieval index covers the checks worth running.
Log the retrieved passages, along with the answer. Without retrieval logs, debugging is guesswork. With logs, you can see patterns: a whole document class that never gets retrieved, a query type that always fails, an embedding model that handles one language poorly.
Common mistakes that sink RAG projects
The failure modes are remarkably consistent across teams.
Treating chunk size as a solved problem. Fixed-size chunks with no overlap are the default in most tutorials and a frequent source of broken context. Tables, code, and long procedures need structure-aware splitting.
Skipping the reranker. Retrieving fifty candidates and reranking them with a cross-encoder often beats retrieving five with a better embedding model, and it is usually cheaper to implement.
Ignoring query rewriting. Users ask messy, context-dependent questions. A short rewriting step that turns “what about the second one?” into a standalone query can lift retrieval quality noticeably.
Assuming the demo generalizes. A pipeline that works on ten hand-picked questions may collapse on real traffic. The distribution of real queries is wider, messier, and full of typos.
Forgetting that documents change. An index built once and never refreshed drifts out of date. Incremental reindexing and deletion handling are part of the system, not an afterthought.
How to evaluate a RAG system
Evaluation has two layers, and both need attention.
The retrieval layer asks: did we find the right passages? Common measures include recall at k (was the correct passage in the top k results?), mean reciprocal rank, and normalized discounted cumulative gain. These are standard information retrieval metrics, and they are well understood.
The generation layer asks: is the answer correct, and is it supported by the retrieved context? Correctness can be graded by humans or by a model acting as a judge, with the usual caveats about judge reliability. Faithfulness needs its own check, because an answer can be correct and still unsupported by the passages provided.
Benchmarks help frame the problem. The KILT benchmark standardized evaluation of knowledge-intensive tasks against a single Wikipedia snapshot with provenance back to source pages, which makes comparisons between retrieval-augmented systems more meaningful than ad hoc test sets. It is not a substitute for your own evaluation set, but it is a useful reference point.
For teams building this out, keeping an eye on how the field reports results is worthwhile; general news coverage of retrieval and evaluation research is collected regularly. (News)
Conclusion
Retrieval-augmented generation is a practical answer to a real limitation: language models only know what they were trained on. The architecture introduced in 2020 gave the idea a name and a baseline, and the industry has spent the years since broadening it into everything from simple prompt injection to elaborate hybrid pipelines. What has not changed is the underlying logic. The quality of the answer is bounded by the quality of the retrieved context, and the faithfulness of the answer is a separate problem that retrieval alone does not solve.
Teams that succeed with RAG tend to be unglamorous about it. They build evaluation sets early, they measure retrieval separately from generation, they respect access controls, and they treat chunking as an engineering decision rather than a default. The demo is easy. The system is the work.
Frequently asked questions
What is retrieval-augmented generation in plain terms?
It is a way of letting a language model look things up before answering. Instead of relying only on what it learned during training, the system searches a document collection, pulls the most relevant passages, and passes them to the model as context. The model then writes an answer grounded in those passages.
Does RAG stop a model from making things up?
No, and this is one of the most common misunderstandings. Retrieval reduces some unsupported claims by giving the model better material, but it does not guarantee that the generated text is actually supported by the retrieved passages. Models can still contradict their context or blend in outside knowledge. Faithfulness needs to be measured separately.
Is RAG better than fine-tuning?
They solve different problems, so the comparison is mostly a category error. RAG changes what the model can see at inference time, which suits knowledge that changes often or lives in private documents. Fine-tuning changes how the model behaves, which suits format, tone, and task-specific patterns. Many production systems use both.
How many documents should a RAG system retrieve?
There is no universal number. Retrieving more passages raises the chance the right one is included but also adds noise and cost, and long contexts can dilute attention. A common pattern is to retrieve a larger candidate set, rerank it, and pass only the top handful to the generator. The right number comes from measuring recall on your own questions.
Why does my RAG system give wrong answers when the document clearly exists?
Usually the document exists but the chunk containing the answer was never retrieved. Possible causes include poor chunk boundaries, an embedding model that handles your domain or language badly, or a query that does not resemble the passage text. Check whether the correct passage appeared in the top-k results before blaming the model.
Can RAG work with private or permissioned documents?
Yes, but access control has to be built into the retrieval layer rather than bolted on afterward. If the index contains documents from multiple permission levels, retrieval must filter by the requesting user’s rights before passages reach the prompt. Systems that skip this step risk exposing confidential material in generated answers. (How to review access to a retrieval index) (NIST AI Risk Management Framework)







