What is RAG? How AI stops guessing and starts citing

In brief

RAG, short for retrieval augmented generation, is a technique where an AI model looks up relevant documents before it answers, then writes its reply from what it found. It exists because models only know their training data. RAG is how chatbots answer from your files, company wikis, and current web results.

What RAG actually is

A language model on its own is a closed book exam. Everything it can tell you was fixed when training ended, and asking about your contract, your codebase, or yesterday's news gets you either a refusal or a confident guess. Why AI gets things wrong covers the guessing problem in depth.

RAG turns the closed book exam into an open book one. Before the model writes an answer, the system searches a knowledge source, such as your uploaded files, a company wiki, or the live web, pulls back the most relevant passages, and pastes them into the prompt alongside your question. The model then answers from that retrieved text instead of from memory alone.

That's the whole idea. The name is intimidating; the mechanism is "look it up first". Everything else in RAG engineering is about making the look-up step find the right passages.

Why models need a retrieval step at all

Two hard limits create the need.

Training has an end date. A model trained through early 2026 knows nothing that happened after, and retraining a frontier model is a months-long, enormously expensive project. Retrieval is how an AI product answers about this morning's announcement without anyone retraining anything.

Training data was public. Your invoices, tickets, and internal docs were never in it, and no amount of clever prompting recovers information the model never saw. Retrieval is the only way a general model can answer from private data.

There's also a subtler third reason: grounding. When the answer must come from a supplied passage, the model can cite its source, and you can check it. An answer produced from memory offers nothing to verify against, which is exactly the failure mode that makes hallucinations dangerous.

One question on a 300,000-token manual: 60 cents pasted in, under half a cent retrieved
Paste the whole manual300,000 tokens a question at $2 per million$0.60Retrieve the right passages2,000 tokens a question at the same rateunder half a centone square is one cent

How a RAG pipeline works, step by step

Every RAG system, from a chat-with-PDF feature to an enterprise search product, runs the same five steps.

  1. Chunking. Source documents are split into passages, typically a few hundred words each, because retrieval works on passages rather than whole files.
  2. Indexing. Each chunk is converted into an embedding, a list of numbers representing its meaning, and stored in a vector database so that similar meanings sit near each other.
  3. Retrieval. Your question is embedded the same way, and the system pulls the chunks whose embeddings sit closest to it, usually the top 3 to 10 passages.
  4. Augmentation. Those passages are inserted into the prompt, wrapped in instructions like "answer only from the context below".
  5. Generation. The model writes the answer from the augmented prompt, ideally citing which passage supported each claim.

When you upload a long document to a chat tool and ask questions about it, some version of this is what runs. The chat with PDF guide shows what that looks like in practice inside Whizi.

RAG vs long context vs fine tuning

These three get confused because all three "teach the model about your data". They do it in incompatible ways.

ApproachHow it worksBest forWeakness
RAGSearch first, answer from resultsLarge or changing document sets, citationsAnswer quality depends on retrieval quality
Long contextPaste everything into the promptOne document, deep cross-referencingCost and attention limits
Fine tuningRetrain the model on examplesStyle, format, and behaviorBad at facts; expensive to update

The economics decide more than the theory does. A 1M token context window, which frontier models like Gemini and the GPT-5.6 family now offer, fits roughly 1,500 pages, so you genuinely can paste a whole manual. But at GPT-5.6 Terra's rate of $2 per million input tokens, sending 300,000 tokens of manual with every question costs about $0.60 per question, while retrieving the right 2,000 tokens costs under half a cent. Ask three questions and long context is 100 times more expensive for the same answers. What is a context window explains the underlying limit.

Fine tuning is the odd one out: it changes how the model behaves, not what it knows. Teams use it for tone and output format, then still bolt RAG on for facts.

Where you already use RAG without noticing

Web search in chatbots. When ChatGPT, Gemini, or Perplexity searches the web and answers with links, that's RAG with the internet as the knowledge source.

Chat with your files. Upload a PDF and ask questions: chunking, embedding, and retrieval run behind the scenes for any document too long to fit comfortably in context.

Customer support bots. The ones that answer from a real help center, and cite the article, are RAG systems. The ones that improvise aren't, and it shows.

AI assistants answering about current events. Any correct answer about something after the model's training cutoff arrived by retrieval, not memory.

Where RAG fails, and how to spot it

RAG reduces hallucination; it doesn't eliminate it, and it adds failure modes of its own.

Retrieval misses. If the search step pulls the wrong passages, the model answers fluently from irrelevant context. Symptom: an answer that cites your document but addresses a slightly different question.

Stale indexes. The vector database only knows documents at their last indexing. A RAG system over last quarter's policies gives confidently outdated answers with citations attached, which is more convincing than a plain hallucination and therefore worse.

Conflicting sources. When retrieved passages disagree, models tend to blend them into one smooth, wrong paragraph rather than flagging the conflict.

The practical defense is the same as for any AI answer: check the cited passage, not just the citation's existence. A RAG answer whose source doesn't actually say what the answer claims is the most common serious failure in production systems.

Workflow checklist
  • Use RAG-style tools (upload, web search) whenever the question is about your data or current events
  • Prefer long context for one document you will interrogate deeply; prefer retrieval for large or changing sets
  • Do not expect fine tuning to add facts; it changes behavior, not knowledge
  • Always open the cited passage and confirm it says what the answer claims
  • Treat a confident answer with no citation as a memory-based guess
Common questions

Frequently asked questions

What does RAG stand for in AI?

RAG stands for retrieval augmented generation. Retrieval means searching a knowledge source for relevant passages, augmented means adding those passages to the prompt, and generation means the model writing its answer from them. The technique lets a model answer from documents and data it was never trained on.

Is RAG better than fine tuning?

They solve different problems. RAG is better for facts, because updating knowledge means re-indexing documents rather than retraining, and answers can cite sources. Fine tuning is better for style, tone, and output format. Production systems commonly use both: fine tuning for behavior, RAG for knowledge.

Does a big context window make RAG obsolete?

No, it changes the threshold. With 1M token windows you can paste roughly 1,500 pages directly, which genuinely replaces RAG for single-document work. But pasting everything into every question costs input tokens each time, roughly $0.60 per question for a 300,000 token manual at $2 per million tokens, while retrieval sends a few thousand tokens instead. For large, changing, or frequently queried collections, retrieval stays the economical answer.

Do I need to build anything to use RAG?

Not as a user. Uploading a document to a chat tool, or turning on web search, already runs retrieval behind the scenes. Building your own pipeline with a vector database only becomes relevant when you're developing software that must answer from a private document collection automatically.

Does RAG stop AI hallucinations?

It reduces them substantially by grounding answers in retrieved text, but it introduces its own failures: retrieving the wrong passage, answering from a stale index, or blending conflicting sources. The reliable habit is checking that the cited passage actually supports the claim, which RAG makes possible and pure memory-based answers don't.