Ask a general-purpose AI model about your company’s refund policy and it can only guess: the policy was never in its training data. Retrieval-augmented generation (RAG) is the usual way to fix that. Here is where the idea comes from, how a typical system works, and where it goes wrong.

A disclosure: one of the two sources below is a post by Anthropic, and this explainer was drafted by an Anthropic model acting as our editor.

Where the term comes from

The name comes from a 2020 paper by Patrick Lewis and colleagues, “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, presented at NeurIPS 2020. It started from a limitation: large language models store factual knowledge in their parameters, but their “ability to access and precisely manipulate knowledge is still limited,” and “providing provenance for their decisions and updating their world knowledge remain open research problems.”

The paper’s answer was to combine two kinds of memory: the model’s own parameters, and a non-parametric memory, in their case “a dense vector index of Wikipedia, accessed with a pre-trained neural retriever.” Their RAG models set the state of the art on three open-domain question-answering tasks, and on generation tasks produced language the authors found “more specific, diverse and factual” than a model without retrieval.

In the paper, RAG was a fine-tuning recipe: the combined models were fine-tuned and evaluated on each task. Today the term is used more broadly, for any system that looks up relevant information and gives it to a model with the question.

How a typical RAG system works

Anthropic’s 2024 post on retrieval gives a plain description of the common setup. It describes RAG as “a method that retrieves relevant information from a knowledge base and appends it to the user’s prompt.”

Once, in advance:

  1. Chunk: split the documents into smaller pieces, “usually no more than a few hundred tokens.”
  2. Embed: use an embedding model to turn each chunk into a vector that encodes its meaning.
  3. Store: put the vectors in a vector database that can be searched by similarity.

For every question:

  1. Retrieve: find the chunks most similar in meaning to the question.
  2. Generate: add those chunks to the prompt and let the model answer from them.

A common addition is a keyword search alongside the similarity search. The post’s example: for a query like “Error code TS-999”, an embedding search might return pages about error codes in general and miss the exact match, while BM25, a ranking method based on exact word matches, finds it.

Where it fails: retrieval

The model can only use what retrieval hands it. Anthropic’s post names a common cause of misses: “traditional RAG solutions remove context when encoding information,” so a chunk cut from a longer document may no longer say which company, product or period it is about, and the search fails to find it.

Its proposed fix, prepending a short explanation of each chunk’s context before it is embedded and indexed, reduced failed retrievals by 49% in Anthropic’s own tests, and by 67% combined with reranking. Those are the company’s measurements on its own test sets; they suggest retrieval is worth improving before the prompt or the model.

When you don’t need RAG

The same post points out that the simplest option may be enough: when it was written, Anthropic noted that a knowledge base under about 200,000 tokens, roughly 500 pages, could be included in the prompt in full for its models at the time, with no retrieval step. Context limits differ by model and change over time, so check yours. RAG earns its complexity when the material is too large, changes often, or must be filtered by who is asking.

A checklist before you build one

This part is our guidance:

  1. Test retrieval on its own. Write 20–50 real questions with the passage that should answer each, and check whether the system finds it. If it doesn’t, no prompt will fix the answer.
  2. Use keyword and meaning search together if your documents contain codes, product names or IDs.
  3. Keep context in each chunk: document title, section and date.
  4. Show the sources with every answer, so people can check them. Provenance was one of the problems the original paper set out to address.
  5. Control access. Retrieval must respect who may see which document; a shared index can leak what a user isn’t allowed to read.
  6. Keep the index current, and remove documents that are withdrawn.

RAG is often how an AI assistant gets access to company knowledge. Connecting the assistant to live systems and tools, rather than to a document index, is what standards like the Model Context Protocol are for.

Prepared with AI assistance and reviewed by an editor before publication. Editorial & AI policy.