Knowledge: Retrieval

Retrieval-augmented generation (RAG) explained: pipeline, variants, limits

Retrieval-augmented generation connects a language model to a searchable collection of an organisation's own documents. The architecture breaks down into a handful of steps, each with its own levers and its own typical points of failure in practice.

A white index card cabinet, three pulled-out cards lie in a row leading to a folded answer sheet, connected by an orange line with node pointsAI-GENERATED
UPDATED
12 September 2026
READING TIME
18 min

Short answer

RAG is an architectural pattern: for every question, a system first searches a defined document collection for matching passages and hands them to a language model, which answers only on that basis and names its sources. Answer quality depends more on chunking, search and reranking of the results than on the size of the model.

Definition

Retrieval-augmented generation: Retrieval-Augmented Generation (RAG) is an architectural pattern in which a system first searches a defined document collection for matching passages for every query and passes them to a language model as context. The model formulates its answer on that basis and points to the sources. The knowledge sits in the interchangeable index, not in the model's weights.

In the glossary: Retrieval-augmented generation, Retrieval, Chunking, Embedding, Vector database, Hybrid search, Reranking, Hallucination, Context window, Query decomposition, Knowledge graph, Visual document search

01

What is retrieval-augmented generation, and where does the term come from?

Retrieval-augmented generation refers to systems that retrieve matching passages from an index before formulating an answer. The term goes back to Lewis et al. (NeurIPS, 2020). Today it stands generally for any architecture in which search and language model are separate, individually testable components.

A large language model (LLM) generates text by calculating the most probable continuation. What it knows about the world sits in its weights, frozen at the point of training. It knows nothing about an organisation's manuals, contracts or tickets, and it cannot say where a statement comes from. Retrieval-augmented generation therefore splits the task in two: a search step (retrieval) finds supporting passages, and only then does the model formulate an answer.

The Lewis et al. paper (NeurIPS, 2020) coupled a generation model with a dense vector index and trained both together. In practice, search and model today usually stay separate components, connected through the prompt and therefore individually swappable and measurable. What is RAG? offers an introduction, and Knowledge management with AI places it in the wider picture.

Milestones that today's RAG systems build on
  1. HNSW graphs

    A graph method for fast, approximate nearest-neighbour search in vector indexes (Malkov and Yashunin).

  2. Reranking with BERT

    A pretrained language model reorders search results markedly better (Nogueira and Cho).

  3. The RAG paper

    Lewis et al. give the pattern its name.

  4. Survey paper

    A classification into naive, advanced and modular systems (Gao et al.).

  5. Visual retrieval

    Document pages are embedded as images (Faysse et al.).

  6. Contextual enrichment

    Chunks are enriched with document context before embedding (Anthropic).

  7. Today

02

What problem does RAG solve that a language model alone cannot?

A language model on its own knows no internal documents, goes stale along with its training cutoff, and cannot back up its statements. RAG supplies current sources at runtime, makes every answer traceable to its source, and allows access rights to be enforced at the index. New knowledge only needs to be ingested, not retrained.

RAG is usually weighed against three alternatives: the model with no data of its own, a very long context window, and fine-tuning, retraining on an organisation's own examples. RAG or fine-tuning goes deeper into the choice against fine-tuning.

Four ways to connect a language model to enterprise knowledge

CriterionModel aloneLong context windowFine-tuningRAG
CurrencyAs current as the training dataAs current as the files suppliedAs current as the last training runAs current as the last ingestion
TraceabilityNo provenanceProvenance possible, but hidden in the full textNo provenanceA source per statement
Access rightsCannot be representedOnly by choosing which files to includeCannot be represented, knowledge sits in the weightsFiltered at the index at query time
Cost per queryLowHigh, grows with the volume of textLowMedium: search plus a short context
Typical weaknessInvented detailsInformation in the middle gets overlookedKnowledge goes stale, training has to repeatIf retrieval finds nothing, there is no basis to answer from

The entry on long contexts rests on Lost in the Middle (Liu et al., 2023): information in the middle of long inputs is used markedly worse than information at the beginning or end.

03

How does a RAG pipeline work, step by step?

A RAG pipeline has two phases. At index time, documents are ingested, split into chunks, embedded as vectors and written to an index. At query time, the question is embedded the same way, matching chunks are retrieved, reranked and passed to the model together with the question, which then answers and names its sources.

The seven stages of a RAG pipeline
  1. 01IngestionText, structure, metadata, rights
  2. 02ChunkingSplitting into passages
  3. 03EmbeddingOne embedding per chunk
  4. 04IndexVector and keyword index
  5. 05RetrievalMatching passages to the question
  6. 06RerankingReordering the candidates
  7. 07AnswerGeneration with source citation

The first four stages run whenever the underlying material changes, the last three run for every question. Mistakes made at index time, such as a table torn apart, cannot be fixed at query time any more.

What happens during ingestion

  1. Reading text and structure

    Extract text along with headings, lists and tables. Scans need OCR or visual retrieval, see Understanding documents with AI.

  2. Carrying metadata along

    Attach title, source, version and validity to every chunk, otherwise neither filtering nor clean citation is possible.

  3. Carrying over access rights

    Store read permissions from the source system on each chunk, see Access control in AI knowledge systems.

  4. Detecting changes

    Track new, changed and deleted documents so that no outdated version gets cited.

04

How should documents be chunked for RAG?

Good chunking follows the structure of the document: splits at headings, paragraphs and table boundaries, large enough to hold a complete thought, small enough for a precise match. Fixed character lengths are the simplest starting point, but they tear apart tables and lists. Contextual enrichment and parent-child chunks help when individual chunks make no sense without their surroundings.

Chunking decides which units can be found at all. Chunks that are too small lose their context: The deadline is four weeks is worthless without its heading. Chunks that are too large dilute the vector and fill the prompt with text that has nothing to do with the question.

StrategyPrincipleStrengthWeakness
Fixed length with overlapCut every n tokens, neighbouring chunks share an edgeSimple, even sizesCuts straight through sentences, tables and lists
Sentence or paragraph basedCut at sentence or paragraph boundaries up to a maximum lengthThoughts stay intactParagraphs vary widely in length
Structure basedCut at headings, tables, list blocks; the heading path is carried alongPreserves context and source locationNeeds clean structure during ingestion
SemanticCut where the meaning of neighbouring sentences changes markedlyDetects topic shiftsAn extra computation step, hard to trace
Parent-childSmall chunks for search, the larger parent chunk for the modelPrecise match, complete contextMore storage and logic in the index
Late chunkingThe whole document is embedded with a long-context model, then split into chunks (Günther et al., 2024)Chunk vectors carry document contextOnly works with suitable embedding models
Contextual enrichmentEvery chunk gets a short explanatory sentence about the document before embedding (Anthropic, 2024)Makes isolated chunks findableOne model call per chunk during ingestion
Chunking strategies compared

05

What happens during embedding and indexing?

An embedding model translates every chunk into a numerical vector, whose closeness to other vectors represents content similarity. These vectors sit in an index that finds approximate nearest neighbours quickly. A classic keyword index alongside it is worth having, because vectors are poor at matching exact identifiers such as part numbers.

An embedding is only comparable to vectors from the same model. The question and the chunks must therefore be embedded with the same model. The vectors are stored in a vector database or a database extension, which usually works with approximation methods such as HNSW graphs (Malkov and Yashunin, 2016): these very likely, but not necessarily exactly, find the nearest neighbours.

Semantic search in the enterprise goes deeper into vector and full-text search, the particulars of German, and measuring relevance.

06

Why is pure vector search usually not enough for RAG?

Vector search finds meaning but misses exact terms such as standard designations, part numbers and proper names. Hybrid search therefore combines it with BM25 keyword search and merges the two rankings. A reranking step downstream scores the best candidates more precisely, so less irrelevant text ends up in the prompt and the model answers more accurately.

Karpukhin et al. (EMNLP, 2020) measured dense vector search at a top-20 hit rate 9 to 19 percentage points higher than a strong BM25 system. That holds for the data used there. For abbreviations, model designations and rare technical terms, keyword search is often just as good or better.

Hybrid search runs both methods in parallel and merges the rankings, usually with Reciprocal Rank Fusion (Cormack et al., SIGIR 2009). A reranking model then scores the question and candidate together, more precisely than two separately computed vectors.

67%fewer retrieval misses in the top 20 from contextual enrichment, hybrid search and reranking combinedAnthropic, 2024
9 to 19 ptshigher top-20 hit rate for dense search versus BM25 in the original testKarpukhin et al., EMNLP 2020
27%relative improvement in MRR@10 from reranking with BERT on MS MARCONogueira and Cho, 2019

The 67% figure comes from Anthropic's measurement of Contextual Retrieval (2024): the share of relevant chunks outside the top 20 fell from 5.7% to 1.9%. The order of magnitude transfers, not the exact value.

07

How does the model answer only from the sources and cite them?

The model receives the retrieved chunks numbered and with their provenance, along with an instruction to answer only from them, to back every statement with its number, and to say openly when the chunks contain no answer. The system then checks that the cited numbers actually exist and links the sources.

Three decisions shape generation. Quantity: a few well-ordered chunks beat many mediocre ones. Order: following Liu et al. (2023), the strongest matches belong at the start, not in the middle. Citation discipline: a statement with no number counts as an error in the system.

text
Answer the question using only the excerpts below.
Support every statement with the number of the excerpt in square brackets, for example [2].
If the excerpts contain no answer, say so and state which information is missing.

[1] Source: maintenance manual, section 4.2, version 2026-03
<excerpt text>

[2] Source: test bench work instruction, section 1
<excerpt text>

Question: <the user's question>
A simplified pattern for a RAG prompt with mandatory citation

08

Where do RAG systems fail in practice?

RAG systems mostly fail at a handful of recurring points: the right chunk is not found, it is found but not used, outdated versions compete with valid ones, questions span multiple sources, or access rights are mapped incorrectly. Each failure mode has its own diagnostic step, and most causes sit upstream of the language model.

What you observeLikely causeFirst diagnostic step
The answer says there is no information, even though it exists in the storeRetrieval misses the chunk: chunking, embedding or a missing keyword searchShow the chunks retrieved for the question and check whether the right one is among them
The right chunk was retrieved, but the answer is still wrongToo much context, an unfavourable order, or an unclear instructionReduce the number of chunks, put the strongest matches first, check the citation requirement
The answer cites an outdated versionOld documents in the index, missing version or validity metadataSearch the store for duplicates and versions, introduce a validity filter
Questions spanning two documents failA single retrieval step only finds one side of the connectionSplit the question into sub-questions and retrieve separately
Overview questions such as the main themes in the store come back thinThat is summarisation across everything, not retrieval of individual passagesCheck a graph approach or summaries generated in advance
Users see content they should not be able to seeAccess rights are filtered too late, or not at allTest filtering at query time in the index, using accounts with different roles
Failure modes, likely causes and the first diagnostic step

Common assumptions about RAG

09

What RAG variants exist, and when are they needed?

Gao et al. (2023) distinguish naive, advanced and modular RAG systems. Beyond that, there are variants for specific failure modes: query decomposition for questions spanning multiple sources, graph approaches for connections and overview questions, agentic retrieval for multi-step research, and visual retrieval for layout-heavy documents. Every variant costs extra computation and should solve a measured problem.

Naive RAG is the simple chain of index, retrieval and generation, advanced RAG adds steps such as rewriting the query and reranking, and modular RAG wires together interchangeable building blocks depending on the query. In practice, what matters is which observed failure an extension actually fixes.

Decision path

Which extension should you check first?

This assumes a small set of real test questions with known correct sources.

    All questions and results as a list
    • For your test questions, is the right chunk usually among the first ten results?
      • Yes, continue with: Which questions still fail?
      • No, continue with: Are the affected documents scanned, or dominated by tables and forms?
    • Which questions still fail?
      • Questions that connect two or more documents, Result: Check query decomposition
      • Overview questions across the entire store, Result: Check a graph approach or summaries
      • Single questions whose answer is phrased incorrectly, Result: Check generation and context
    • Are the affected documents scanned, or dominated by tables and forms?
      • Yes, Result: Check ingestion and visual retrieval
      • No, continue with: Do the failing questions contain exact identifiers such as numbers, standards or proper names?
    • Do the failing questions contain exact identifiers such as numbers, standards or proper names?
      • Yes, Result: Check hybrid search
      • No, Result: Check chunking and embedding
    • Result: Check query decompositionWorth discussing: what share of questions genuinely need multiple sources, and whether a switch decomposes only those questions, so simple questions do not get slower.
    • Result: Check a graph approach or summariesWorth discussing: whether overview questions are frequent enough to justify a graph and its upkeep, or whether summaries generated in advance for each topic area are enough.
    • Result: Check generation and contextWorth discussing: the number and order of chunks, mandatory citation in the prompt, and a measurement of faithfulness to source, before a different model gets tested.
    • Result: Check ingestion and visual retrievalWorth discussing: whether OCR preserves tables and columns, and whether visual retrieval delivers more correct sources for this document class in testing.
    • Result: Check hybrid searchWorth discussing: whether a keyword search runs in parallel, how the two rankings get merged, and whether identifiers stay intact cleanly during ingestion.
    • Result: Check chunking and embeddingWorth discussing: whether chunks make sense on their own, whether headings are carried along, and whether contextual enrichment or a different embedding model yields more hits on the test set.

    10

    When is RAG the right choice, and when is it not?

    RAG fits when answers live in written documents, those documents change, sources are needed, and access rights apply. It fits poorly for exact calculations from databases, for knowledge that exists nowhere in writing, and for contradictory material with no owner. In those cases a database query, a knowledge-elicitation effort, or cleaning up the material first, helps more.

    Checklist

    Prerequisites for a RAG project

    0 of7

    The more points hold true, the more likely a first prototype will hold up against real data.

    If the knowledge sits only in people's heads, the work starts before the index: Capturing knowledge before it retires. For running on an organisation's own network: Local language models. Self-test: RAG readiness check, implementation: RAG implementation.

    Read more on iiterate.de

    Frequently asked questions

    Does a RAG system strictly need a vector database?

    No. For small stores, a database extension or even plain keyword search with good reranking is enough. A dedicated vector database pays off when the store is large, many metadata and access filters are needed, or multiple vectors per page need to be stored. What matters is not the product, but whether retrieval delivers the right sources on the test set.

    How many chunks should you give the model per question?

    As few as are needed for a source-backed answer. In practice, more candidates are retrieved than are passed on, reranked, and only the best ones are kept. The right number is a measured quantity: comparing on the test set shows at what point extra chunks stop adding correct answers and start adding only distraction.

    Can RAG handle tables and spreadsheets?

    With limits. Tables inside running-text documents work if they are kept intact during ingestion and split with their header row retained. For analysis across many rows, such as sums or comparisons over time periods, text retrieval is unsuitable: the table belongs in a database that the system queries directly, rather than searching rows as text chunks.

    Does RAG work as well with German documents as with English ones?

    In principle yes, but not automatically. Embedding models vary widely in their quality for German, and compound words such as Wartungsintervallanpassung (maintenance interval adjustment) pose their own challenges for keyword search and chunking. The embedding model and keyword analysis should therefore be compared against German test questions drawn from an organisation's own store. Semantic search in the enterprise covers these linguistic particulars in more depth.

    Can RAG run without cloud services?

    Yes. Ingestion, the embedding model, the index, the reranker and the language model can all run entirely in an organisation's own data centre, provided a model with open weights is used. The cost then shifts from usage fees to hardware, updates and operations. Local language models covers what scale of storage and what operational tasks this involves.

    How do you keep a RAG system's index current?

    Through a connection that detects changes in the source system: ingesting new documents, replacing changed chunks, removing deleted ones and tracking changed access rights. On top of that comes domain maintenance that no technology replaces: someone has to decide which version holds and what gets weeded out. Without that ownership, the system cites outdated documents with just as much confidence as valid ones.

    Read on

    Related topics

    Sources

    1. 01 Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks Lewis et al., arXiv, NeurIPS 2020, 2020 · arxiv.org
    2. 02 Dense Passage Retrieval for Open-Domain Question Answering Karpukhin et al., arXiv, EMNLP 2020, 2020 · arxiv.org
    3. 03 Passage Re-ranking with BERT Nogueira und Cho, arXiv, 2019 · arxiv.org
    4. 04 Lost in the Middle: How Language Models Use Long Contexts Liu et al., arXiv, TACL, 2023 · arxiv.org
    5. 05 Retrieval-Augmented Generation for Large Language Models: A Survey Gao et al., arXiv, 2023 · arxiv.org
    6. 06 From Local to Global: A Graph RAG Approach to Query-Focused Summarization Edge et al., Microsoft Research, arXiv, 2024 · arxiv.org
    7. 07 ColPali: Efficient Document Retrieval with Vision Language Models Faysse et al., arXiv, ICLR 2025, 2024 · arxiv.org
    8. 08 Late Chunking: Contextual Chunk Embeddings Using Long-Context Embedding Models Günther et al., arXiv, 2024 · arxiv.org
    9. 09 Introducing Contextual Retrieval Anthropic, 2024 · anthropic.com
    10. 10 Ragas: Automated Evaluation of Retrieval Augmented Generation Es et al., arXiv, 2023 · arxiv.org
    11. 11 Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods Cormack, Clarke und Büttcher, ACM SIGIR, 2009 · dl.acm.org
    12. 12 Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs Malkov und Yashunin, arXiv, 2016 · arxiv.org

    Let us talk about your project

    Whether it is a prototype, an internal tool or an AI application: describe briefly what you are building or want to take into production.

    Arthur C. Clarke

    “Any sufficiently advanced technology is indistinguishable from magic.”