RAG & retrieval Guide 19 of 25
Retrieval-augmented generation (RAG), explained
Retrieval-augmented generation is the standard way to put company knowledge in front of a language model. How it works, seven common ways it breaks, and when to skip it altogether.
Key takeaways
- RAG searches a collection you control at question time and puts the best passages into the prompt, so answers can be current, private, and checkable.
- Many RAG failures happen before the model writes a word: poor parsing, chunks stripped of context, or the right passage ranked just outside the cut-off.
- If your corpus is small (Anthropic’s 2024 rule of thumb was about 200,000 tokens), rarely changes, and everyone may see all of it, try full context with caching first.
- Retrieval is turning into a tool that agents call repeatedly, trading latency for better answers on multi-step questions.
- Build a golden set of real questions, including unanswerable ones, and score retrieval and generation separately before tuning anything.
On this page 7 sections
Ask a general-purpose language model about your company’s refund policy and one of two things happens. It admits it does not know, or it invents something plausible. Its knowledge stops at a training cutoff, it has never seen your internal documents, and it cannot say where any particular claim came from.
Retrieval-augmented generation (RAG) is the standard fix, and the usual starting point for assistants and copilots built on large language models (LLMs). It is also where many such projects stall. A demo that handles twenty friendly questions often fails on the next two hundred real ones, and nobody can tell whether search or the model is to blame.
This guide covers how RAG works, where it fails, and how long context and agents have changed it, as of October 2026.
What is retrieval-augmented generation?
RAG is a pattern, not a product. Before the model answers, a search step finds passages relevant to the question in a collection you control. Those passages go into the prompt next to the question, with instructions to answer from them. The model then writes a response grounded in that text and, ideally, cites it.
Luis Lastras of IBM Research summed up the idea in the company’s 2023 explainer:
“It’s the difference between an open-book and a closed-book exam.”
The open book buys three things. Freshness: you update knowledge by re-indexing documents, not by retraining a model. Private knowledge: the model can work with contracts, tickets, and runbooks it never saw in training. Provenance: each answer can point to its source passage, so a reader can check it.
What RAG does not do is change how the model behaves. It supplies facts at question time; it does not teach a new skill, format, or tone. That is a job for prompting or fine-tuning.
Where RAG came from: the 2020 paper
The term comes from a paper by Patrick Lewis and colleagues at Facebook AI Research, University College London, and New York University, first posted on 22 May 2020. It framed the problem as two kinds of memory. Parametric memory is whatever a model stores in its weights. Non-parametric memory is an external index that the model searches and that people can inspect, edit, or replace.
The system’s retriever was dense passage retrieval (DPR), which encodes questions and passages as vectors so that matching pairs sit close together. Its generator was BART-large, a sequence-to-sequence model with about 400 million parameters. The index was Wikipedia’s December 2018 dump, cut into 100-word chunks — 21 million passages, searched with FAISS (Facebook AI Similarity Search).
The most instructive experiment was about updating knowledge. The authors listed 82 world leaders who changed between 2016 and 2018, then swapped the index under the model. With a matching index, it named the right leader 70% of the time for 2016 and 68% for 2018; with mismatched indexes, accuracy collapsed to 12% and 4%. Swapping the index changed the answers without touching a weight.
One part did not survive. The original trained the question encoder and the generator together, end to end, with the passage index held fixed. Today’s RAG usually wires an unmodified LLM to a search system through the prompt alone. The name stuck to the pattern, not the architecture.
How does a RAG pipeline work?
A RAG system has two halves on different clocks. Indexing runs offline whenever documents change. Answering runs on every question, inside a latency budget.
A typical pipeline has six steps:
- Parse. Extract text from PDFs, wikis, and tickets while keeping the structure that carries meaning: headings, tables, lists, and who may see what.
- Chunk. Split documents into passages of a few hundred tokens, and attach metadata such as title, section, date, and access-control lists (ACLs).
- Index. Turn each chunk into an embedding — a vector placed so that passages with similar meaning sit close together — and store it in an approximate nearest-neighbor index for fast search. Keep a keyword index as well, usually BM25 (short for Best Matching 25), a classic ranking function that scores exact term matches and weights rare terms more heavily.
- Interpret the question. Optionally rewrite it: resolve “it” from earlier turns, expand internal acronyms, or split a compound question into parts.
- Retrieve and rerank. Pull a few dozen candidates from both indexes, filtered by the user’s permissions. A reranking model then reads each candidate together with the question and scores it, and only the strongest few reach the prompt.
- Generate. Place those passages in the prompt with instructions to answer only from them, cite them, and say so when the answer is not there.
Every step has knobs — chunk size, embedding model, candidate count — and defaults are only a starting point.
Why the details matter: contextual retrieval
Chunking quietly destroys context. Picture a credit-card policy split into passages, one of which says the limit rises to $5,000 after 90 days. Which card, and for which customers? The passage no longer says, so neither vector nor keyword search can match it to a question that names the product.
Anthropic’s contextual retrieval write-up (19 September 2024) fixes this by having an LLM write a short note that situates each chunk within its document, prepended before both embedding and keyword indexing. Combined with keyword search and reranking, Anthropic reported two-thirds fewer cases where the right passage missed the top 20 results. Later independent tests were more skeptical; our guide to chunking, hybrid search, and reranking weighs both and says when the extra indexing cost pays.
The lesson outlasts the technique: data preparation, not the answering model, usually decides retrieval quality.
Where does RAG break? Seven failure points
Researchers at Deakin University’s Applied Artificial Intelligence Institute studied three RAG systems built for research, education, and biomedicine. Their 2024 experience report names seven failure points, which map neatly onto the pipeline above. The right-hand column is our own first-response checklist.
| # | Failure point | What the user sees | Where to look first |
|---|---|---|---|
| 1 | Missing content | A confident answer the documents cannot support | Corpus coverage; abstention instructions and tests |
| 2 | Missed top-ranked documents | A weak answer; the right passage ranked just below the cut-off | Hybrid search, reranking, more candidates |
| 3 | Not in context | Passage retrieved, then dropped while assembling the prompt | Context budget and consolidation logic |
| 4 | Not extracted | The answer was in the prompt, but the model missed it | Noise and contradictions; fewer, better passages |
| 5 | Wrong format | A requested table or list ignored | Structured outputs; explicit format rules |
| 6 | Incorrect specificity | Too general or too detailed for the asker | Prompt design; clarifying questions |
| 7 | Incomplete | Part of the answer missing, though it was available | Separate retrievals for each part of the question |
The first failure is the most dangerous because it looks like success. IBM’s explainer describes a chatbot without retrieval that, asked about maternity leave, cheerfully told the employee to take as long as she liked. A RAG system not built and tested to say “I don’t know” fills gaps the same way.
The report’s two lessons belong on every RAG team’s wall: such a system can only be fully validated once it runs with real users, and robustness grows through iteration rather than up-front design.
Do long context windows make RAG obsolete?
Context windows grew fast. Gemini 1.5 could already process up to a million tokens in 2024, so why retrieve when you can paste in everything?
Sometimes you shouldn’t. Anthropic’s 2024 rule of thumb was direct: below about 200,000 tokens, roughly 500 pages, put the whole knowledge base in the prompt and use prompt caching to keep repeat calls fast and cheap. Windows are larger in 2026, as our guide to tokens and context windows shows, but recall still falls as context grows, so test at your real corpus size.
Even with long-context models, the evidence favors a mix. A Google DeepMind and University of Michigan study, presented in 2024, compared both approaches on Gemini 1.5 Pro, GPT-4o, and GPT-3.5-Turbo. Given enough budget, long context won on average quality while RAG cost far less, and the two gave identical predictions on 63% of queries.
The authors’ hybrid, Self-Route, tries RAG first, lets the model declare a query unanswerable from the passages, and only then sends the full text. It came close to long-context quality while cutting cost by 65% on Gemini 1.5 Pro and by 39% on GPT-4o. When the RAG step gave up, the usual cause was a multi-step question, where one answer shapes the next search. Other failures came from vague questions, long and tangled ones, and implicit ones that need the whole text.
Long windows carry a quality cost too. Anthropic’s context engineering guidance (29 September 2025) describes context rot: recall declines as the token count rises, to some degree in every model. Add per-call cost, latency, corpora larger than any window, and documents some users may not see, and retrieval stays necessary for most enterprise knowledge.
| Approach | Best when | Watch out for |
|---|---|---|
| Full context with caching | Small corpus (2024 rule of thumb: under ~200,000 tokens), rarely changes, everyone may see all of it | Per-call cost and latency; recall drops as context grows |
| Classic RAG | Large or fast-changing corpus; answers sit in a few passages | Lost chunk context; questions that need a whole document or links across many (GraphRAG) |
| Agentic retrieval | Multi-step or ambiguous questions; knowledge spread across systems | Slower and costlier; needs good tools and step limits |
Agentic RAG: retrieval becomes a tool
Classic RAG makes one retrieval pass, up front, before the model has reasoned about the question. Agentic retrieval instead gives search to the model as a tool: it can rewrite the query, search again, open a full document, or stop.
Anthropic’s 2025 guidance describes teams adding just-in-time retrieval on top of embedding search done before inference. The agent keeps light references, such as file paths or saved queries, and loads content through tools as needed. Claude Code, Anthropic’s coding agent, reads project instruction files up front, then uses file-search commands (glob and grep) to find code on demand, avoiding stale indexes. The price is speed, and an agent without good tools wastes context chasing dead ends.
Genie, Uber’s internal on-call copilot, shows a middle ground in a working system. In a 29 May 2025 write-up, Uber engineers tested a conventional pipeline over 40-plus security and privacy policy documents against 100-plus expert-curated questions, and many answers were incomplete or wrong.
The fixes were mostly plumbing. Sources moved from PDFs to Google Docs, which parse more cleanly and carry access controls that can be indexed. A custom loader kept tables intact. An LLM wrote document summaries, plus frequently asked questions and keywords for each chunk, all stored as searchable metadata.
Uber then added agents that clarify or split the query, choose which documents to search, and de-duplicate results, with BM25 beside vector search. It reported a relative 27% rise in acceptable answers and a relative 60% drop in incorrect advice, and an LLM judge cut evaluation cycles from weeks to minutes.
Meanwhile, basic RAG has become a commodity. Google’s File Search tool for the Gemini API, launched on 6 November 2025, manages storage, chunking, embeddings, and citations as a service. At launch, indexing cost $0.15 per million tokens, with storage and query-time embeddings free. When the plumbing is cheap and hosted, the differentiation moves to data preparation, permissions, and evaluation.
What this means for your team
- Size the problem first. If the corpus is near Anthropic’s 2024 rule of thumb of about 200,000 tokens, changes rarely, and everyone may see all of it, try full context with caching. Measure at your real size before building a pipeline.
- Write the evals before the pipeline. Collect 100–300 real questions, the size our evals guide suggests for cheap-to-label items, with expected answers and sources, including some the corpus cannot answer, and check that the system abstains on those. Score retrieval and generation separately: was the right passage retrieved, and did the answer stay faithful to it?
- Spend effort on parsing. Tables, headings, and document context carry meaning, and many failures start there.
- Default to hybrid search with reranking. Vector search misses exact identifiers such as product codes and error strings; keyword search misses paraphrases. Retrieve broadly, then rerank narrowly.
- Enforce permissions at retrieval time. Filter by the user’s access rights before passages reach the prompt. Telling the model not to reveal something is not access control.
- Treat the index as a product. Give it an owner, a freshness target, and a reliable way to delete documents that must disappear.
- Use agentic retrieval for multi-step questions. Set step limits and accept the latency; for simple lookups, one well-tuned retrieval is faster and cheaper.
The usual pitfalls are judging by a demo, tuning prompts when retrieval is the real problem, and letting the index go stale. When SurgeX Labs builds a knowledge assistant, the first milestone is a retrieval score on real questions, reported before anyone tunes a prompt.
Sources
-
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (opens in new tab) — Facebook AI Research, University College London, and New York University (arXiv), 2020 arxiv.org
-
What is retrieval-augmented generation (RAG)? (opens in new tab) — IBM Research, 2023 research.ibm.com
-
Introducing Contextual Retrieval (opens in new tab) — Anthropic Engineering, 2024 anthropic.com
-
Seven Failure Points When Engineering a Retrieval Augmented Generation System (opens in new tab) — Deakin University Applied Artificial Intelligence Institute (arXiv), 2024 arxiv.org
-
Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid Approach (opens in new tab) — Google DeepMind and University of Michigan (arXiv), 2024 arxiv.org
-
Effective context engineering for AI agents (opens in new tab) — Anthropic Engineering, 2025 anthropic.com
-
Enhanced Agentic-RAG: What If Chatbots Could Deliver Near-Human Precision? (opens in new tab) — Uber Engineering, 2025 uber.com
-
Introducing the File Search Tool in Gemini API (opens in new tab) — Google, 2025 blog.google
Where this shows up in our work
- Solution blueprint Your knowledge, answering with citations — RAG knowledge assistant with citations
- Solution blueprint First drafts for every ticket — AI support copilot inside your helpdesk