LIVEΒ·The trends shaping tomorrow's world.
AI

What Is Retrieval-Augmented Generation (RAG)?

Retrieval-augmented generation gives an LLM relevant documents at answer time. How the pipeline works, where it fails, and how to build it well.

Retrieval-augmented generation (RAG) is a way of answering questions with a language model by first fetching relevant passages from an external collection, such as your documents, a wiki or a product catalog, and then handing those passages to the model along with the question. The model writes its answer from that supplied evidence instead of relying only on what it absorbed during training. The result is answers that can reflect current, private or specialized information, and that can point to their sources.

Where the idea comes from

The term comes from a 2020 paper by Patrick Lewis and colleagues at Facebook AI Research, University College London and New York University, presented at NeurIPS 2020 [1]. Their starting point was a known weakness: large pretrained models store facts in their weights, but they can't reliably access or update that knowledge, and they can't show where a fact came from [1].

Their fix combined two kinds of memory [1]:

  • Parametric memory: the knowledge baked into a model's weights. In the paper, this was BART-large, a 400-million-parameter sequence-to-sequence model.
  • Non-parametric memory: a searchable index of text that sits outside the model. In the paper, this was the December 2018 English Wikipedia, split into 100-word chunks to make 21 million passages, each turned into a vector and stored in a FAISS index using HNSW search.

A neural retriever, based on Dense Passage Retrieval (DPR) [2], found the passages most relevant to a question. The generator then conditioned on those passages to produce the answer.

One experiment in the paper is the clearest argument for the whole approach. The authors built a second index from a December 2016 Wikipedia dump and asked the model "Who is {position}?" for 82 world leaders who changed between 2016 and 2018. With the matching index, it answered 70% (2016) and 68% (2018) correctly. With the mismatched index, accuracy fell to 12% and 4% [1]. Swapping the documents changed what the model "knew," with no retraining. That property is why RAG became the default pattern for grounding LLMs in company data.

Today's production RAG systems look different from the 2020 research system. The paper trained the retriever's query encoder and the generator together [1], whereas most current deployments plug an off-the-shelf embedding model and a general-purpose LLM together without joint training. The core loop of retrieve, then generate, is the same.

How a RAG pipeline works

A RAG system has two halves: an indexing path that runs ahead of time, and a query path that runs every time someone asks a question.

Indexing (offline)

  1. Ingest. Pull content from its sources: PDFs, web pages, tickets, database rows, slide decks. Convert it to clean text and keep metadata such as title, URL, author, date and access permissions.
  2. Chunk. Split each document into passages small enough to retrieve precisely and to fit several in a prompt. The original paper used fixed 100-word chunks [1]. Production systems often split on headings or paragraphs and add overlap so that sentences aren't cut in half.
  3. Embed. Run each chunk through an embedding model, which turns text into a fixed-length list of numbers (a vector). Text with similar meaning lands close together in that vector space. DPR showed that such learned dense vectors could beat the classic BM25 keyword method by 9 to 19 percentage points on top-20 passage retrieval accuracy across several question-answering datasets [2].
  4. Index. Store the vectors in a structure that can find near neighbors quickly, usually an approximate nearest neighbor (ANN) index such as HNSW [3] inside a vector database or library like Faiss [4]. Our explainer on how vector databases work covers this layer in detail.

Query (online)

  1. Retrieve. Embed the user's question with the same model, then ask the index for the k nearest chunks. Many systems also run a keyword search and merge the results (more on that below).
  2. Augment. Insert the retrieved chunks into the prompt, usually with instructions such as "answer only from the sources below and cite them."
  3. Generate. The LLM writes an answer grounded in those chunks. Because the system knows which chunks it supplied, it can attach citations.

If you want a refresher on what the generator itself is doing, see our explainer on how large language models work.

The parts that decide quality

Most RAG failures are retrieval failures. If the right passage never reaches the prompt, the model can't use it. These are the levers that matter most.

Chunking and lost context

A chunk pulled out of a long document can lose the information needed to interpret it. Anthropic's example is a chunk from an SEC filing that says revenue grew 3% over the previous quarter, without naming the company or the quarter [5]. A search for "ACME Q2 2023 revenue growth" may never match it.

Anthropic's "Contextual Retrieval" technique addresses this by having a model write a short, chunk-specific summary of where the chunk sits in its document (usually 50 to 100 tokens), and prepending it before embedding and keyword indexing [5]. On Anthropic's own evaluation across several datasets, it reported that the top-20 retrieval failure rate fell by 35% with contextual embeddings alone, by 49% when combined with contextual BM25, and by 67% when reranking was added [5]. Those figures come from the vendor's internal tests, so treat them as directional, but the underlying problem applies to any chunked corpus.

Hybrid search: meaning plus exact words

Embeddings capture meaning well, but they can miss exact strings: error codes, part numbers, names. Keyword methods like BM25 are good at exactly that. The RAG paper itself found BM25 beat its dense retriever on FEVER, a fact-checking dataset whose claims are heavily entity-centric [1].

Many vector databases now support hybrid search, which runs both and fuses the results. Pinecone's documentation describes combining a keyword signal (BM25 or sparse vectors) with a dense signal at query time, often followed by reranking [7]. Weaviate exposes an alpha parameter, where 1 means pure vector search and 0 means pure keyword search, and offers two fusion methods: one combines the two result sets by normalized scores (the default in recent versions), the other by rank position [8].

Reranking

Retrieval is fast but coarse. A reranker is a slower model that scores each candidate chunk against the question more carefully. A common pattern is to retrieve a wide set and keep only the best. In Anthropic's tests, for example, the system retrieved 150 candidates and passed the top 20 to the model after reranking [5].

Where the chunks go in the prompt

More context isn't automatically better. Liu and colleagues found that language models used information best when it appeared at the beginning or end of a long input, and worse when the relevant passage sat in the middle, even for models built for long contexts [6]. That's a reason to keep the number of retrieved chunks modest and ordered by relevance.

RAG compared with the alternatives

Approach

Where knowledge lives

Updating knowledge

Can cite sources

Best fit

Plain prompting

Model weights only

Wait for a new model

No

General knowledge, drafting

Long-context prompting

Whole corpus pasted into the prompt

Edit the text you paste

Yes, if you ask

Small, stable corpora

RAG

External index, searched per question

Re-index changed documents

Yes

Large, changing or private corpora

Fine-tuning

Adjusted model weights

Retrain

Not inherently

Style, format, task behavior

The long-context row deserves a note. Anthropic suggests that if a knowledge base is under about 200,000 tokens (roughly 500 pages), it can be simpler to put the whole thing in the prompt and skip retrieval, using prompt caching to reduce cost and latency [5]. RAG earns its complexity when the corpus is bigger than that, changes often, or needs per-user access control. The trade-offs with training are covered in our RAG vs fine-tuning comparison.

Variations you'll hear about

  • Agentic RAG. Instead of a single retrieval step, an agent decides when to search, rewrites queries, and searches again based on what it found. Anthropic contrasts its multi-agent Research system with "static" RAG that retrieves once, describing a system that searches iteratively and adapts to intermediate findings [9]. See our guides to agentic AI and multi-agent systems.
  • Tool-based retrieval. Retrieval exposed as a tool the model can call, often through the Model Context Protocol, so the same search backend can serve different AI applications.
  • Query rewriting. A model reformulates a vague or conversational question into one or more search queries before retrieval.

Where RAG is used

The pattern fits anywhere answers must come from a specific, changing body of text:

  • Internal knowledge assistants over policies, wikis and runbooks.
  • Customer support bots grounded in help-center articles and product manuals.
  • Research assistants that search the web or a document store and cite what they used, as in Anthropic's Research feature [9].
  • Developer tools that search a codebase or API docs before suggesting code.

Benefits

  • Fresh knowledge without retraining. Update the index and the answers change, as the 2016-versus-2018 Wikipedia experiment showed [1].
  • Provenance. The system knows exactly which passages it supplied, so it can cite them and a user can check them.
  • Access control. Because retrieval is a query, you can filter by user permissions before anything reaches the model.
  • Model independence. You can swap the LLM without rebuilding the knowledge store, as long as you keep the same embedding model for the index.

Limitations and risks

  • Retrieval misses. If the right chunk isn't retrieved, the model either says it doesn't know or, worse, answers from its own memory. Measure retrieval quality separately from answer quality.
  • Grounded doesn't mean correct. The model can still misread or over-generalize from a passage. Citations make errors easier to catch, not impossible.
  • Stale or conflicting sources. RAG faithfully surfaces whatever is in the index, including outdated documents. Content hygiene and metadata such as dates matter.
  • Prompt injection. Retrieved text is untrusted input. A document containing instructions ("ignore previous instructions and…") can try to steer the model. Treat retrieved content as data, and limit what actions the model can take based on it.
  • Re-embedding cost. Changing the embedding model means re-embedding the whole corpus, because vectors from different models aren't comparable.

How to get started

  1. Check whether you need it. If your material fits comfortably in a long-context prompt, try that first [5].
  2. Build an evaluation set early. Collect 20 to 50 real questions with known answers and the passages that contain them. Track whether the right passage appears in the top results.
  3. Start simple, then add layers. Begin with sensible chunking and dense retrieval. Add hybrid search, contextual chunk headers and reranking when your evaluation shows misses that each addresses.
  4. Keep metadata. Titles, dates, URLs and permissions make filtering, citation and debugging possible.
  5. Instruct the model to abstain. Tell it to say when the sources don't contain an answer, and test that it does.

Outlook

RAG started as a research architecture and became the standard way to ground language models in specific data. The open question for teams in late 2026 isn't whether to use retrieval, but how much of it should be a fixed pipeline and how much should be left to agents that search iteratively. Both rest on the same foundation: good chunks, good embeddings and a retrieval step you can measure.

Frequently asked questions

Does RAG stop hallucinations?

It reduces them for questions the indexed documents can answer, because the model has relevant evidence in front of it. It doesn't eliminate them: the model can still misinterpret a passage or answer from memory when retrieval misses. Citations and an instruction to abstain help users catch the remaining errors.

Do I need a vector database for RAG?

Not necessarily. You need some way to search your content. That can be a dedicated vector database, a vector extension in a database you already run, a library like Faiss, or even plain keyword search. The original RAG paper used a Faiss index [1][4].

What's the difference between RAG and fine-tuning?

RAG supplies knowledge at question time from an external index. Fine-tuning changes the model's weights through additional training. RAG is usually the better tool for adding facts that change, while fine-tuning is better for teaching a consistent format, tone or task behavior. Our RAG vs fine-tuning guide goes deeper.

How big should chunks be?

There's no universal number. The 2020 paper used 100-word passages [1], and many systems use a few hundred tokens split on natural boundaries like headings. Test a few sizes against your evaluation questions and pick what retrieves the right passages most often.

Is RAG the same as giving a model web search?

Web search is one form of retrieval, so an LLM with search is doing a version of RAG. The term is more often used for search over a curated, private collection where you control the index, chunking and permissions.

Sources

  1. Lewis, P. et al. "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks." NeurIPS 2020. arXiv:2005.11401. https://arxiv.org/abs/2005.11401
  2. Karpukhin, V. et al. "Dense Passage Retrieval for Open-Domain Question Answering." EMNLP 2020. arXiv:2004.04906. https://arxiv.org/abs/2004.04906
  3. Malkov, Y. A. and Yashunin, D. A. "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs." arXiv:1603.09320. https://arxiv.org/abs/1603.09320
  4. Douze, M. et al. "The Faiss library." arXiv:2401.08281. https://arxiv.org/abs/2401.08281
  5. Anthropic. "Introducing Contextual Retrieval." September 2024. https://www.anthropic.com/news/contextual-retrieval
  6. Liu, N. F. et al. "Lost in the Middle: How Language Models Use Long Contexts." TACL 2023. arXiv:2307.03172. https://arxiv.org/abs/2307.03172
  7. Pinecone. "Indexing overview." Documentation. https://docs.pinecone.io/guides/index-data/indexing-overview
  8. Weaviate. "Hybrid search." Documentation. https://docs.weaviate.io/weaviate/search/hybrid
  9. Anthropic. "How we built our multi-agent research system." June 2025. https://www.anthropic.com/engineering/multi-agent-research-system