
TL;DR
Retrieval-augmented generation (RAG) gives a language model extra text at the moment it answers. A retrieval step finds relevant passages in a knowledge base and adds them to the prompt. The model still can only use what the retrieval step finds.
- Purpose: RAG lets a model answer from documents it was never trained on, such as a company's private data.
- Steps: Data is split into chunks, turned into embeddings, indexed, searched at question time and passed to the model.
- Origin: Patrick Lewis and colleagues introduced RAG models in a paper first submitted on May 22, 2020.
- Limit: Anthropic reports that traditional RAG often fails to retrieve the relevant information, because encoding removes context.
What RAG is
A language model answers from what it learned in training and from what is in its prompt. RAG adds a third source. It fetches text from outside the model and puts it into the prompt.
Anthropic's glossary defines it: “Retrieval augmented generation (RAG) is a technique that combines information retrieval with language model generation to improve the accuracy and relevance of the generated text, and to better ground the model’s response in evidence.”
The glossary adds where the text goes. A language model is augmented with a knowledge base “that is passed into the context window”. The article on tokens and context windows explains that window: Tokens and Context Windows: What the Numbers Mean
The model does not have to fetch the data itself. The glossary says the data is retrieved at runtime when a query is sent, “although the model itself does not necessarily retrieve the data”.
The article on large language models explains the model that receives the result: What Is an LLM? Large Language Models Explained
Why RAG exists
A model has gaps. Google's Cloud documentation names one: “A common problem with LLMs is that they don't understand private knowledge, that is, your organization's data.”
The research behind RAG names others. Patrick Lewis, Ethan Perez and colleagues wrote that pre-trained models store knowledge in their parameters. Their ability to access and precisely manipulate it, they wrote, “is still limited”. They also wrote that providing provenance for decisions and updating world knowledge “remain open research problems”.
Their paper, “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, was first submitted on May 22, 2020. It describes “models which combine pre-trained parametric and non-parametric memory for language generation”.
In their setup, the non-parametric memory “is a dense vector index of Wikipedia, accessed with a pre-trained neural retriever”. The authors report that their models set the state of the art on three open domain question answering tasks. For language generation, they found RAG models generate “more specific, diverse and factual language” than a parametric-only baseline.
How RAG works, step by step
Google's documentation for its RAG Engine lists the stages in order. This is one vendor's pipeline, not a standard.
Data ingestion. Data comes in from different sources, for example local files or Google Drive.
Data transformation. The data is prepared for indexing. Google's example is that data is split into chunks.
Embedding. An embedding is a numerical representation of words or pieces of text. Google says these numbers capture the semantic meaning and context of the text, and that similar text has similar embeddings. Anthropic's documentation gives a shorter definition: “Text embeddings are numerical representations of text that let you measure semantic similarity.”
Indexing. The index structures the knowledge base so it is optimized for searching. Google calls its index a corpus.
Retrieval and generation. When a question arrives, relevant information is retrieved from the knowledge base. Anthropic describes the result as passed “to the model along with the original query”, and the model uses it “to guide the output it generates”.
Two ways to search
Retrieval can work on words or on meaning. Vladimir Karpukhin and colleagues wrote in a paper first submitted on April 10, 2020, that “traditional sparse vector space models, such as TF-IDF or BM25, are the de facto method” for passage retrieval in open-domain question answering.
Their paper showed an alternative. Retrieval “can be practically implemented using dense representations alone”. Their dense retriever outperformed a strong Lucene-BM25 system “largely by 9%-19% absolute” in top-20 passage retrieval accuracy.
Products often offer both. OpenAI's file search tool retrieves information from previously uploaded files “through semantic and keyword search”. OpenAI calls it a hosted tool managed by OpenAI, so there is no code to write for its execution.
Where retrieval fails
RAG is only as good as its retrieval step. Anthropic's research post of September 19, 2024 says: “traditional RAG solutions remove context when encoding information, which often results in the system failing to retrieve the relevant information from the knowledge base.”
Its example is a method called Contextual Retrieval. In Anthropic's own experiments, Contextual Embeddings reduced the top-20-chunk retrieval failure rate by 35 percent, from 5.7 percent to 3.7 percent. Combined with Contextual BM25, the reduction was 49 percent, to 2.9 percent. Anthropic says the method can reduce failed retrievals by 67 percent when combined with reranking.
These are Anthropic's numbers, measured on its own test sets. The post also says that chunk size, chunk boundary and chunk overlap “can affect retrieval performance”.
A second limit sits after retrieval. A model does not use every passage equally well. Nelson Liu and colleagues submitted “Lost in the Middle” on July 6, 2023. They found that performance “significantly degrades when models must access relevant information in the middle of long contexts”. More retrieved text is therefore not automatically better.
When RAG is not needed
Sometimes the knowledge base is small. Anthropic writes: “If your knowledge base is smaller than 200,000 tokens (about 500 pages of material), you can just include the entire knowledge base in the prompt that you give the model, with no need for RAG or similar methods.”
That statement dates from 2024 and refers to Claude models of the time. Context windows differ by model and change. Check the current size for the model you use before you decide.
Managed services
RAG does not have to be built from scratch. Google's Gemini documentation calls building RAG systems “a common use case for AI products”. It points to a managed File Search tool for those who prefer it.
OpenAI and Google both sell hosted pieces of the pipeline. These documents describe what the tools do. They do not show how well they work for your data.
What to take from this
RAG changes what is in the prompt. It does not change the model. Its quality depends on how the data is chunked, embedded, indexed and searched, and on whether the model uses what it receives.
Two questions help you judge a RAG claim. How was retrieval tested, and by whom? And does the knowledge base fit into the window without any retrieval at all?
Sources
- Patrick Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv 2005.11401, May 22, 2020): https://arxiv.org/abs/2005.11401
- Vladimir Karpukhin et al., Dense Passage Retrieval for Open-Domain Question Answering (arXiv 2004.04906, April 10, 2020): https://arxiv.org/abs/2004.04906
- Nelson F. Liu et al., Lost in the Middle: How Language Models Use Long Contexts (arXiv 2307.03172, July 6, 2023): https://arxiv.org/abs/2307.03172
- Anthropic, Glossary (Claude documentation): https://platform.claude.com/docs/en/about-claude/glossary
- Anthropic, Contextual Retrieval in AI systems (September 19, 2024): https://www.anthropic.com/research/contextual-retrieval
- Anthropic, Embeddings (Claude documentation): https://platform.claude.com/docs/en/build-with-claude/embeddings
- Google Cloud, RAG Engine overview: https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview
- Google, Embeddings (Gemini API documentation): https://aistudio.google.com/docs/embeddings
- OpenAI, File search (API documentation): https://developers.openai.com/api/docs/guides/tools-file-search







