What is Retrieval-Augmented Generation?
Retrieval-augmented generation fetches relevant passages from your own corpus at query time and supplies them to a language model as context, so answers are grounded in specific sources rather than in the model's frozen training data.
The plain definition
A language model knows only what was in its training data, up to its cutoff, and it cannot cite a source. RAG addresses both problems with a straightforward pipeline: take the user's question, retrieve the most relevant passages from your document store, put those passages in the prompt, and ask the model to answer using them.
The payoff is substantial. Answers reflect your current, private, authoritative content. Citations become possible because you know which passages were supplied. Updating knowledge means updating documents rather than retraining a model. And hallucination drops sharply, because the model is asked to summarise provided text instead of recalling from weights.
Retrieval quality is the whole game
Almost every disappointing RAG system fails at retrieval, not generation. If the right passage is not in the context, no model can produce a correct grounded answer — and the model will usually produce a confident wrong one anyway. Before blaming the model, measure retrieval directly: for a set of real questions with known source passages, what fraction of the time does the correct passage appear in the top k?
The levers that actually move that number, roughly in order of impact. Chunking — split on semantic boundaries such as headings and sections rather than fixed character counts, with modest overlap, and prepend document and section titles to each chunk so it is interpretable alone. Hybrid search — combine embedding similarity with keyword matching; pure vector search reliably fails on part numbers, proper nouns, and exact identifiers. Reranking — retrieve 50 candidates cheaply, then reorder with a cross-encoder that scores query and passage jointly; this is often the single largest quality gain available. Query rewriting — expand or decompose the question before retrieving, since users rarely phrase queries the way documents are written.
Also handle the retrieval-fails case explicitly. Instruct the model to say it cannot find the answer when the context does not contain it, and verify that it does. A system that fabricates when retrieval misses is worse than one that admits ignorance.
RAG versus fine-tuning, and the security problem
These solve different problems and are frequently confused. RAG supplies knowledge — facts, documents, current state. Fine-tuning teaches behaviour — format, tone, domain vocabulary, task structure. If the complaint is 'it does not know our products', that is RAG. If the complaint is 'it will not answer in our required format', that is fine-tuning. Production systems often use both.
One security issue deserves specific attention, because it is easy to build in by accident. Retrieved content enters the prompt, and the model cannot reliably distinguish instructions written by you from instructions embedded in a retrieved document. If any part of your corpus is user-supplied or externally sourced, an attacker can plant text that hijacks the model's behaviour — indirect prompt injection. Treat retrieved content as untrusted input: never let it trigger privileged actions, enforce permissions at retrieval time so a user cannot pull documents they should not see, and keep the model's available tools narrowly scoped.
- Grounding, not memory — supplies current, private, citable knowledge at query time
- Retrieval is the bottleneck — measure top-k hit rate before touching the model
- Rerank and go hybrid — the two highest-return improvements in most pipelines
- Retrieved text is untrusted — indirect prompt injection is a real attack path
More on Retrieval-Augmented Generation.
Is RAG better than fine-tuning?
They address different problems, so the comparison is usually the wrong question. RAG injects knowledge the model does not have and lets you update it by editing documents. Fine-tuning changes how the model behaves — output format, tone, domain conventions, task structure. Use RAG when the gap is factual, fine-tuning when the gap is behavioural, and both when you need current facts delivered in a specific way.
Why does my RAG system give wrong answers?
In most cases the correct passage never reached the prompt. Measure retrieval in isolation first: take real questions with known source passages and check how often the right passage lands in the top k. If that number is poor, fix chunking, add hybrid keyword search, and add a reranking stage. If retrieval is good and answers are still wrong, the problem is in the generation prompt — and it should include an explicit instruction to answer only from the supplied context and to say so when the answer is absent.
Related terms.
Embedding
An embedding is a list of numbers representing a piece of content in a space where geometric closeness corresponds to semantic sim…
ReadVector Database
A vector database stores high-dimensional embeddings and retrieves the nearest ones to a query vector in sub-linear time, using ap…
ReadFine-Tuning
Fine-tuning continues training a pretrained model on a smaller task-specific dataset so that its weights adapt to your format, ton…
ReadLarge Language Model
A large language model is a neural network trained on enormous volumes of text to predict the next token, which turns out to produ…
ReadNeed this built?
Applying this to a
real system?
We build and ship production machine learning. If retrieval-augmented generation is part of a problem you are working on, tell us about it.
Start the conversationor write to us at [email protected]