Definition
Retrieval-augmented generation (RAG) is a pattern where an AI system first searches a set of documents for passages relevant to a question, then gives those passages to a language model so it answers from them, ideally with citations.
How RAG works in a product
A RAG feature has two halves. Ingestion runs ahead of time: documents are cleaned, split into chunks of a few hundred words, turned into embeddings (lists of numbers that capture meaning), and stored in a search index. Answering runs per question: the system embeds the question, finds the closest chunks, puts them into the prompt with instructions to answer only from them, and returns the answer with references to the chunks it used.
The idea comes from a 2020 paper by Patrick Lewis and colleagues, which paired a language model's built-in knowledge with a searchable index of documents. Production systems usually add keyword search (BM25) alongside vector search, because embeddings are weak at exact matches such as product codes, error messages and names.
When you need it, and when you do not
RAG earns its place when answers depend on facts the model was never trained on, when those facts change (prices, policies, help articles), when users need to see where an answer came from, or when different users are allowed to see different documents.
It is often unnecessary for small collections. Anthropic's guidance is that a knowledge base under roughly 200,000 tokens, about 500 pages, can go straight into the prompt, and prompt caching keeps that affordable. A long prompt has no index to maintain and no retrieval step that can miss the right passage. We reach for RAG when the corpus is too large for that, changes daily, or needs per-user access control.
The pitfall: the corpus, not the model
Most bad RAG answers trace back to retrieval, not generation. Scanned PDFs with no text layer, three versions of the same policy, tables flattened into noise, and chunks cut mid-sentence all produce confident answers built on the wrong passage. Switching to a bigger model does not fix that.
Two decisions matter more than the framework. First, decide what not to ingest: drafts, superseded versions and anything a given user should not see. Second, log the chunk IDs behind every answer, so a wrong answer can be traced to the passage that caused it in minutes instead of guessed at. Then add a refusal when the best match scores poorly. "I could not find that in our documents" is a better answer than a plausible invention.
What it does to a quote
RAG is part of the $1,150 AI build when the product needs it, and a support bot over your documents starts at $490. The variable is the state of your files. If the corpus needs a cleanup pass for scans, duplicates or tables, the written quote says so and prices that work. Model and embedding usage is billed by the provider directly to your account, outside the build price.
Questions
Is RAG the same as training a model on our data?
No. RAG leaves the model unchanged and shows it relevant passages at question time. Updating an answer means updating a document, not running a training job. Fine-tuning changes the model's weights and suits format or classification problems, not facts that change.
How many documents is too many for RAG?
The search index is rarely the bottleneck. The limit is quality: the more overlapping, outdated or contradictory documents you ingest, the more often retrieval surfaces the wrong one. A curated corpus of current documents beats a dump of everything on the shared drive.
Sources
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, arXiv (Lewis et al.), 2020-05-22
- Introducing Contextual Retrieval, Anthropic, 2024-09-19