AI Explained

What Is RAG (Retrieval-Augmented Generation)?

Retrieval-augmented generation (RAG) means fetching the most relevant passages from your own documents and adding them to the prompt, so the AI model answers from that material instead of memory alone. It helps with large or changing knowledge. For a small collection of documents, simply including all of it in the prompt can be enough.

Cover reading "Look it up, then answer" beside an open book with glowing index cards flying in from a small card-catalogue drawer (AI-generated image)
AI-generated image

You ask an AI assistant about your company’s refund policy, and it confidently invents one, because it never saw your policy. RAG is the usual fix.

The Idea in One Sentence

Retrieval-augmented generation means: first retrieve the passages from your own documents that best match the question, then generate an answer with those passages included in the prompt.

The term comes from a 2020 research paper by Patrick Lewis and colleagues, Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. Today it’s used broadly for any system that looks things up before answering. Anthropic describes it as retrieving relevant information from a knowledge base and adding it to the user’s prompt.

Think of an open-book exam. The model is a bright student, but instead of answering from memory, it’s allowed to look up the right pages first.

How It Works, Step by Step

  1. Prepare your documents. Split them into chunks (for example a few paragraphs each).
  2. Index the chunks. Most systems turn each chunk into an embedding, a list of numbers that captures its meaning, and many also keep a keyword index.
  3. Search at question time. The question is compared with the index to find the closest chunks.
  4. Build the prompt. The best chunks are added to the prompt with an instruction to answer only from those passages.
  5. Generate and cite. The model answers, ideally pointing to the passages it used.

Why Not Just Paste Everything In?

Sometimes you should. Anthropic’s article on contextual retrieval makes the point plainly: if your knowledge base is smaller than about 200,000 tokens (roughly 500 pages), you can include all of it in the prompt and skip RAG. Prompt caching makes repeating that large prompt cheaper.

On our price board on 2026-11-22, 36 of the 42 models listed a context window of about 1 million tokens, so pasting everything in covers more cases than it used to. RAG still matters when:

  • the material is far larger than any context window
  • it changes often, and re-sending everything each time would be slow or costly
  • you need to show which document an answer came from
  • different users may see only certain documents

Did you know? Anthropic reports that its contextual retrieval method cut failed retrievals by 49%, and by 67% when combined with reranking, in its own tests. Small changes to how chunks are prepared can matter a lot.

RAG vs Fine-Tuning

RAG Fine-tuning
What changes The prompt (fresh documents each time) The model itself (further training)
Best for Facts that change; answers that need sources Style, format or a specialised skill
Updating knowledge Update the documents Retrain
Showing sources Natural Hard

Many systems use RAG for knowledge, and leave fine-tuning out unless they need a particular style or skill.

Where RAG Goes Wrong

  • Wrong chunks retrieved: if search misses the right passage, the answer will be wrong or vague.
  • Too many chunks: stuffing in lots of loosely related text can confuse the model and raise costs.
  • Stale documents: RAG is only as current as the index.
  • No citations: without pointing to sources, you can’t check the answer.

What It Costs

Each RAG answer sends the retrieved passages as input tokens. Five chunks of 400 tokens add 2,000 input tokens to every question. At $2 per 1M input tokens, that’s $0.004 per question, or $4 per 1,000 questions. Small, but it adds up at volume. Our explainer What Is a Token in AI? covers the basics.

What This Means for You

  • Developers: start simple: if your material fits in about 200,000 tokens, try the whole thing in a cached prompt before building retrieval. If you need RAG, log which chunks each answer used.
  • Founders and team leads: RAG is how you make an AI assistant answer from your policies and documents; insist that answers cite their sources.
  • Curious beginners: RAG is an AI looking things up in your files before answering, like an open-book exam.

Copy-Ready Prompt for RAG Answers

Answer the question using only the passages below. If the answer is not in the passages, say "I can't find that in the documents." After each claim, cite the passage number in brackets.

Passages:
[1] ...
[2] ...

Question: ...

What’s one document your team keeps answering questions about that an AI could look up instead?

Bottom Line

RAG gives an AI model the right pages before it answers, which keeps answers grounded in your own material. For small document sets, a long cached prompt may be all you need; for large or changing ones, RAG earns its keep. Learn how AI systems use tools in our collection Learn to build AI agents, explore How large language models work inside, and compare input prices on our price board. Want these updates by email? Sign up here, or follow new guides and data stories through our RSS feed.

Get the Weekly AI News Bay Email

The week’s biggest AI stories, model price changes and outages in one short email. The first issue goes out in early 2027; sign up now to get it.

Double opt-in: we email you a link to confirm. One-click unsubscribe in every email. Privacy policy.

Sources

Written by AI News Bay’s AI writers and checked by a separate AI auditor before publishing. Prices and uptime figures come from our own measurements. Spotted something out of date? Tell us.

Related on AI News Bay

More in AI Explained

Type a name, a topic or a format. Enter opens the full results.