Let's define RAG carefully.
Retrieval Augmented Generation is a pattern that has two phases for every user question:
- Retrieve: Search a collection of documents for those most relevant to the user's question.
- Generate: Pass the retrieved documents, along with the question, to an LLM to produce an answer.
The "augmentation" refers to augmenting the LLM's input with retrieved information.
The LLM still does the heavy lifting of producing a natural-language response, but it does so grounded in real, retrieved content rather than relying purely on what it memorized during training.
A Working Analogy
Imagine you've hired a brilliant generalist consultant who has read most of the world's books.
You hire them to help your company.
Without RAG: You ask, "What's our company's policy on parental leave?" The consultant has never seen your company's policies.
They give you a reasonable-sounding answer based on common practices — which may or may not be what your actual policy says.
You can't tell.
With RAG: Before each question, an assistant pulls the relevant sections from your employee handbook and hands them to the consultant.
Now when you ask, "What's our company's policy on parental leave?", the consultant reads the relevant handbook pages and tells you exactly what they say.
They can even cite the page number.
That's RAG: an LLM, given the relevant material as part of its input, answering grounded in real content.
Why Not Just Paste All Your Documents Into the Prompt?
Good question.
If you only had, say, ten pages of documents, you could indeed just paste them all into the prompt every time.
But what if you have:
- 100,000 pages of legal documents?
- 5 million customer support tickets?
- Every Wikipedia article ever written?
You can't fit them all in any model's context window, and even if you could, it would be wildly expensive (you'd be paying for all those tokens every single time) and the model would struggle to find what's relevant.
So RAG is essentially a smart filter: out of all the information available, find the small subset that's actually relevant to this question, and only give the model that.