The Problem: LLMs Hallucinate
An LLM (large language model) says convincing things that are sometimes completely false. Why? Its knowledge is frozen at the date of its last training data. You ask it for last quarter's financial results? Hallucination. You ask it to answer questions about your internal documents it's never seen? Hallucination again. The model doesn't know how to say "I don't know", it makes things up with confidence.
RAG (Retrieval-Augmented Generation) solves this problem with a simple idea: instead of asking the LLM to answer from memory, you provide it with relevant documents as context. It's the difference between a closed-book exam (the LLM alone) and an open-book exam (the LLM with RAG).
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al., 2020)Instead of relying solely on its weights (its internal memory), the LLM receives relevant documents directly in the prompt. It can cite its sources, use up-to-date data, and answer questions about your private documents.
Two steps, therefore two ways to fail
Take away one consequence of this architecture right now, because it governs everything else in this module. A RAG system does two things in sequence: it searches for passages, then it writes an answer from them. So when the final answer is bad, there are two possible explanations, and only one of them is true at a time:
- the right passage was never retrieved, the writer never stood a chance;
- the right passage was retrieved and then misused, the search engine did its job.
These two failures have nothing in common and are not fixed the same way. Yet looking only at the final answer, you cannot tell them apart. That is why evaluating a RAG system always means two separate measurements, one for retrieval, one for generation. The Search Toolkit page develops this with a useful analogy (the intern, the case file and the memo); RAG evaluation gives the actual metrics.
RAG Pipeline: 3 Steps
1. Indexing (offline, done once)
This is the preparation phase, executed ahead of time:
- Split your documents into chunks (pieces of a few hundred words, how to choose the size is covered in Chunking strategies)
- Generate an embedding for each chunk (a list of numbers meant to stand for its content) using an embedding model (Text embeddings)
- Store those lists of numbers in a vector database (Chroma, Qdrant, Pinecone… see Vector databases)
2. Retrieval (online, for each question)
When a user asks a question:
- Convert the question into an embedding, using the same model as for the documents
- Compare that vector against every vector in the database and keep the K chunks whose vector is closest (K is typically 5 to 10)
- These chunks become the "context" for the answer
It is worth being precise about this step, because the usual vocabulary misleads. People say the system "understands the question" or "grasps the user's intent": that is not what happens. It computes one number per chunk (a proximity score between two lists of numbers) sorts the chunks by that number, and keeps the top K. Nothing more. That this ordering often matches what a human would judge relevant is an empirical result, obtained by training the embedding model; it is not a guaranteed property of the procedure.
3. Generation (online)
The LLM comes into play:
- Build a prompt that combines the context (retrieved chunks) and the question
- The LLM generates an answer grounded in the provided documents
Context: [Document 1: ...] [Document 2: ...]
Question: your question
Answer based ONLY on the context provided.

Why It Works
Fewer Hallucinations
By providing sources directly in the prompt, the LLM no longer needs to guess, it restates information it has in front of it. The model shifts from "I'm reciting what I memorized" mode to "I'm reading and summarizing" mode. How big the gain is depends entirely on the corpus, the questions and the quality of retrieval: it is something to measure on your own data, not a universal number.
Always Up-to-Date Data
The vector database can be updated continuously. A new document is published? Index it, and it's immediately available for answers. That costs a handful of embedding computations, whereas getting the same information into the model's weights would require retraining, incomparably slower and more expensive.
Private Documents Without Retraining
Your internal documents (emails, reports, source code) are not used to train the model: they stay in your vector database and enter it only as embeddings. That is a real advantage, but be clear about what it does not cover. If the model doing the writing is called through a provider's API, the retrieved passages are sent to that provider on every request, that is the whole point of the operation. So corpus confidentiality does not come from RAG itself; it comes from where the model runs and what the provider commits to regarding reuse of the data you send. A genuinely sensitive corpus calls for a model you run yourself.
RAG: when data changes frequently, when you need traceability (citing sources), or for factual knowledge. Fine-tuning: when you want to change the model's behavior, style, or response format. In practice: you'll probably do both. RAG for knowledge, fine-tuning for behavior.
Key Components
Embeddings
The embedding model turns text into vectors. Retrieval quality depends directly on it: if two texts about the same thing don't produce two nearby vectors, no later stage can recover from that.
Typical choices in 2026: all-MiniLM for a prototype (free, fast, vectors of 384 numbers), BGE-M3 or the Qwen3-Embedding family for an open multilingual model, or a paid service available through an API (Gemini Embedding, Voyage, Cohere, Mistral Embed...). The selection criteria are detailed in Text embeddings.
Vector Database
Stores embeddings and quickly finds the ones closest to a given vector, even across millions of entries.
"Closest" is usually measured by cosine similarity: you look at the angle between the two vectors and ignore their length, which makes the comparison insensitive to how long the text was. Two vectors pointing the same way score 1, two perpendicular vectors score 0. The formula is in norms and distances.
Options: Chroma (prototyping), Qdrant (open-source, production), Pinecone (hosted service, no ops).

Chunking
How you split documents is a problem in its own right. Too small: each chunk loses its context and becomes incomprehensible on its own. Too large: a single vector has to summarise several topics at once, and the useful passage gets diluted in the rest. You also need an overlap between consecutive chunks, otherwise an idea that straddles a cut is lost on both sides. The consequences of each setting are laid out in Chunking strategies.
Pitfalls of Naive RAG
- What isn't retrieved doesn't exist: if retrieval doesn't find the right documents, the LLM can't produce a good answer, regardless of its power
- Lost in the middle: with a long context, models answer better when the useful information sits at the beginning or the end than in the middle (see Long context vs RAG)
- Conflicting sources: when retrieved documents contradict each other, the LLM can produce an incoherent answer
- Multi-step questions: "Which supplier has the best price among those that deliver to Europe?" requires cross-referencing several pieces of information, one retrieval isn't enough, you need to chain them (see Agentic RAG)
RAG reduces hallucinations but doesn't eliminate them. Plan for human validation in critical cases.

RAG in 2026: What Has Changed
The basic scheme (search, then write) has not moved since the 2020 paper. What has changed is who decides to search, where the search happens, and what gets indexed.
Search Has Become One of the Agent's Tools
In the RAG described above, search happens once, before writing, whatever the question. In agentic RAG, search is a tool among others, which the model calls when it needs it, as many times as needed, rewording its query based on what it found. It is the answer to the multi-step-question trap. Since 2025, models have even been trained with reinforcement learning to behave this way: they are rewarded when the final answer is right, and learn by themselves when and what to search (the Search-R1 paper is an open example). The patterns, costs and risks are in agentic RAG.
Search-R1: Training LLMs to Reason and Leverage Search Engines with Reinforcement LearningWeb Search Built Into Assistants
The most used RAG system in the world does not query a vector database: it queries the web. ChatGPT added web search in late 2024, Claude in spring 2025, and Le Chat and Gemini did the same. The mechanism is the one on this page, with a search engine in place of the vector database: the question is turned into queries, an engine returns pages, excerpts are placed in the input, and the answer cites its sources. Deep research agents push the logic to dozens of chained searches for a single report (see agents: the landscape).
The two failure causes from the top of the page are still there, with one more difficulty: nobody controls the corpus. A low-quality, outdated or deliberately misleading page can be retrieved and cited with the same confidence as a solid source, and a page can contain hidden instructions aimed at the model (prompt injection). On the enterprise side, Mistral released a toolkit in 2026 for building and above all measuring this kind of pipeline, described in Search Toolkit.
Long Context Versus RAG
Context windows of a million tokens, now common, raise the question: why search, if you can hand over everything to read? A 2024 study compared the two on the same questions: when you can afford it, long context does better on average, but RAG costs a small fraction of the price; the authors propose letting the model choose between the two, question by question. In practice, for a small, stable corpus read often, putting the whole corpus in the input (with prompt caching, which avoids paying full price for the repeated part) has become a serious option; for a large corpus or changing data, RAG remains essential. The details are in long context vs RAG.
Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid ApproachSeveral Vectors per Document, and Documents Read as Images
The RAG on this page summarises each chunk of text as one vector. Another family, called late interaction, keeps one vector per token and compares the question with the document word by word: that is ColBERT, explained in reranking. It is finer, and costs far more storage.
The idea found a striking application in 2024 with ColPali. Many business documents are PDFs full of tables, charts and layouts that text extraction mangles. ColPali skips that step: each page is treated as an image, cut into small patches, and a vision-language model produces one vector per patch. The question produces one vector per word, and the comparison works as in ColBERT: for each word of the question, find the page patch that matches it best. You can thus retrieve a page thanks to a chart or a table, without ever extracting its text. Models in this family (ColPali, ColQwen and their successors) lead the ViDoRe benchmark, dedicated to retrieval in visual documents, in 2026. The alternative, extracting each page's text before indexing it, is covered in document OCR.
ColPali: Efficient Document Retrieval with Vision Language ModelsAll these developments move the search (towards the agent, the web, the image) without removing the rule from the top of the page: a wrong answer can come from a passage never found or from a passage badly used, and only measuring the two steps separately tells you which. The more automatic and repeated the search, the more that measurement matters.
Evaluation: One Measurement per Half
This brings us back to the point made at the top of the page. The metrics fall into two families, and you always need to look at both.
For retrieval, the basic metric is recall@K: out of all the passages in the corpus that should have been found for this question, what proportion actually appears in the K that came back? A recall@10 of 0.9 means 9 useful passages out of 10 are in the top ten results. It is computed without involving the LLM at all, which is exactly what makes it useful as a diagnostic. Recall comes from classification, where it is defined in Evaluation metrics.
For generation, two distinct questions:
- faithfulness: is every claim in the answer supported by the passages provided, or did the model add something of its own?
- answer relevancy: does the answer actually address the question? An answer can be perfectly faithful to the documents and beside the point.
These metrics, how they are computed and where they break down are the subject of RAG evaluation.
The following sections take each component in turn (chunking, retrieval methods, reranking) then the techniques that go beyond basic RAG.
1. A RAG system gives a wrong answer even though the requested information is definitely in the indexed corpus. What can you conclude?
2. When people say the retrieval step understands the question, what does the system actually do?
3. A company queries its confidential contracts through a RAG system whose LLM is called via an external provider's API. Do the contracts stay confidential?
4. Why does a question like which supplier has the best price among those that deliver to Europe give naive RAG trouble?
5. A corpus contains PDF reports full of tables and charts. What does an approach like ColPali bring?