Ask an LLM about something that happened after its training cutoff, or about a fact buried deep in your company's internal docs, and you'll get one of two things: a confident "I don't have information on that," or worse, a confident answer that's just wrong. That second failure mode — a fluent, plausible-sounding, incorrect answer — is what people mean by hallucination. It happens because the model is generating the next token based on statistical patterns learned during training, not looking anything up.
Retrieval-Augmented Generation (RAG) is the standard fix. In one sentence: RAG gives a model access to an external knowledge source at the moment it answers your question, so the response is grounded in real, current documents instead of only what the model memorized during training.
The Problem, Concretely
Two separate failure modes push teams toward RAG:
- Staleness — the model was trained on a snapshot of data with a cutoff date. Anything after that date simply isn't in its weights.
- Hallucination — even for facts that were in the training data, the model can misremember, blend it with unrelated information, or state something false with total confidence.
For casual use, that's an annoyance. For legal research, medical Q&A, or an internal support bot answering questions off your company's actual documentation, ungrounded answers are a liability, not a quirk.
How RAG Actually Works: Retrieve, Augment, Generate
RAG runs in three phases on every query:
- Retrieve — a search component (usually vector similarity search, sometimes BM25 keyword search, often both) queries an external corpus — documents, wikis, a database, the web — and pulls back the chunks most relevant to the question.
- Augment — those retrieved chunks get inserted into the prompt alongside the user's question, forming an extended context the model can actually read.
- Generate — the model writes its answer with explicit reference to the retrieved text, instead of relying solely on its trained-in weights.
A minimal RAG loop looks roughly like this in pseudocode:
def answer_with_rag(question, corpus_index, llm):
query_embedding = embed(question)
top_chunks = corpus_index.search(query_embedding, k=5)
context = "\n\n".join(chunk.text for chunk in top_chunks)
prompt = f"""Answer the question using only the context below.
If the answer isn't in the context, say so.
Context:
{context}
Question: {question}"""
return llm.generate(prompt)
That k=5 (how many chunks you retrieve) and the instruction to admit when the answer isn't in the context are both places where RAG systems commonly go wrong — retrieve too few chunks and you miss the answer, retrieve too many and you crowd out the context window with noise.
RAG vs. Fine-Tuning — Don't Confuse These
This is the mix-up that trips people up most:
| Fine-tuning | RAG | |
|---|---|---|
| What it changes | The model's weights, via additional training | Nothing in the model — knowledge is supplied at inference time |
| Best for | Adjusting style, tone, format, task behavior | Currency and specificity of factual content |
| Update cycle | Retrain to update knowledge | Update the corpus, no retraining needed |
| Typical cost pattern | Upfront training cost | Ongoing retrieval/indexing infrastructure |
They're not competing techniques — plenty of production systems fine-tune a model for behavior and use RAG for facts.
Where RAG Falls Short
RAG is not a hallucination-proof switch you flip on:
- It's only as good as the retrieval step. Irrelevant chunks in, off-base answer out.
- Long retrieved context eats into the context window, leaving less room for instructions or follow-up turns.
- The model can still ignore the retrieved text or blend it incorrectly with its own priors — RAG reduces hallucination, it doesn't eliminate it.
- If the answer genuinely isn't anywhere in the corpus, the model still has nothing grounded to point to.
- Someone has to build and maintain the index. That's real engineering work, not a one-time setup.
Where You've Already Used RAG
- Perplexity AI — web search plus LLM synthesis over the results.
- ChatGPT with web search enabled.
- Microsoft Copilot pulling from your organization's documents.
- Most enterprise chatbots built on internal knowledge bases.
RAG was formalized in the 2020 NeurIPS paper "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (Lewis et al., Meta AI Research) — worth a read if you want the original framing straight from the source.
FAQ
What does RAG stand for in AI?
Retrieval-Augmented Generation — retrieving relevant documents, then using them to generate a grounded answer.
Does RAG eliminate AI hallucinations?
No. It reduces the odds by grounding answers in real text, but the model can still misread or ignore what it retrieved.
What's the difference between RAG and fine-tuning?
Fine-tuning changes the model's weights through extra training. RAG leaves the model untouched and supplies knowledge through the prompt at answer time.
How does RAG keep AI answers current?
Update the corpus it retrieves from — no retraining required, unlike fine-tuning.
What is vector search and why does RAG use it?
It's a similarity search over embeddings (numeric representations of meaning) rather than exact keyword matches, so retrieval can find semantically relevant chunks even when the wording doesn't match. Most RAG systems use it, sometimes alongside keyword search like BM25.
If you're building anything that needs an AI system to answer questions about your own ai agent workflows or a private knowledge base, RAG is the piece that connects "what the model knows" to "what's actually true right now."
Originally published at my-blog.org.
Top comments (0)