What Is RAG? Retrieval-Augmented Generation Explained
RAG lets a language model answer from documents fetched at question time. Learn how retrieval, chunking and generation fit together, with a worked example.
Updated · Markdown version
Retrieval-augmented generation (RAG) combines information retrieved from an external source with a generative model's output. In a typical request-time pipeline, retrieved passages are supplied to the model without updating its learned parameters. Updating that external index and training the model are separate operations.
How RAG works
The original RAG paper combines a retriever with a generator. The retriever searches a dense vector index of documents for passages related to the input, and the generator conditions its output on those passages. The index acts as non-parametric memory: facts live outside the model's parameters, so the system can look them up instead of relying only on what was learned in training. A system can retain the retrieved passages and show them as candidate evidence for an answer. Those passages and the answer still need verification; retrieval alone does not guarantee good provenance.
A typical production pipeline runs in two phases:
- Indexing (offline): split each document into chunks, convert each chunk into an embedding, and store the vectors with their source metadata.
- Query (online): embed the question, retrieve the closest chunks, place them in the prompt, and instruct the model to answer from them.
Worked example: chunking
Suppose a quarterly filing contains the sentence "Revenue grew 3% over the prior quarter." Stored alone, that chunk does not name the company, the quarter, or the year. A question such as "How did Example Corp's revenue change in Q2?" may never retrieve it, and if it does, the model cannot tell which company or period the number describes.
Two adjustments help. First, split on document structure such as headings and paragraphs rather than a fixed character count, so each chunk keeps its section. Second, prepend a short context line to each chunk before embedding, such as "From Example Corp's Q2 filing, revenue discussion: ..." Anthropic's contextual retrieval write-up describes generating a context of roughly 50 to 100 tokens per chunk. In its own evaluation, contextual embeddings plus contextual BM25 lowered the rate of chunks missed within the first 20 results from 5.7% to 2.9%. Treat that as one team's test set, not a forecast for your documents.
Chunk size, boundaries and overlap all change retrieval results, so measure them on questions whose answers you already know.
What RAG is not
Retrieval supplies external evidence, while fine-tuning updates learned model parameters. A system can combine both: the original RAG paper jointly fine-tunes a query encoder and generator and also shows that its external index can be replaced at test time. RAG is also not a protocol. In the MCP introduction rechecked on 2026-11-25, the documentation describes MCP as a standard way to connect AI applications to data sources and tools. It does not retrieve or index documents by itself, so a RAG pipeline can be exposed to an assistant through an MCP server, but the two sit at different layers.
Pitfalls
- The answer is in the docs but never reaches the prompt. Log the top retrieved chunks for each failing question. If the answer is absent from them, fix chunking or add context lines before touching the prompt.
- Chunks are too small or too large. Very small chunks lose the context needed to match a question. Very large chunks blur the embedding and use prompt space. Compare two or three sizes on the same question set.
- The index is stale. Edited documents keep returning old text. Store a source timestamp per chunk and re-embed changed documents.
- The model answers from memory anyway. Tell the model to answer only from supplied passages and to say so when they lack the answer. Check each claim against the cited chunk.
- No provenance. Without a document ID and section on every chunk, users cannot check sources. Store both at indexing time.
When to use a skill instead
A RAG pipeline is a system you build and maintain, while a reusable skill is a set of instructions a model follows for a task. For a one-off question about a single document, pasting the relevant text into the prompt is usually enough and needs no setup. Chunking decisions repeat, though, once you have several document sets, and a skill makes the same questions get asked in the same order each time. rag-chunking-planner lays out how to choose chunk size, overlap and boundaries for a document set, so those values get decided on purpose. It fits the case where retrieval keeps missing answers that are in your documents.
FAQ
Is RAG the same as an MCP server?
No. MCP is a protocol that lets AI clients reach outside systems, yet it has no indexing or retrieval step of its own. A RAG pipeline can be exposed through an MCP server, which makes the two complementary rather than alternatives.
Can RAG answer questions the model was never trained on?
It can use retrieved information that was not in the generator's training data. The relevant information must be available to the retrieval pipeline, and retrieval and generation can still fail.
Why does chunk size matter in RAG?
Chunk size affects whether a question matches the right text. Anthropic's write-up notes that chunk size, boundaries and overlap all change retrieval results, so test a few settings on your own questions.
Related skills in this catalog
Platform Score is our assessment under a published method. It is not a safety guarantee.
Related guides
Terms this guide uses
This item is a worked example in the AI glossary for:
- Agentic RAG
- Agentic search
- AnythingLLM
- BM25
- Chroma (vector database)
- Chunking
- Cohere
- Cosine similarity
- Cross-encoder
- Embedding
- Encoder-decoder
- FAISS
- Fine-tuning
- Firecrawl
- GraphRAG
- Hierarchical Navigable Small World (HNSW)
- Hybrid search
- LangChain
- LlamaIndex
- Matryoshka embeddings
- Mean average precision (mAP)
- Milvus
- NotebookLM
- pgvector
- Pinecone (vector database)
- Qdrant
- Question answering (QA)
- Reranking
- Retrieval-augmented generation (RAG)
- Sentence Transformers
- TF-IDF
- Vector database
- Vector search
- Weaviate
- Word embedding
- Word2vec
Sources
- https://arxiv.org/pdf/2005.11401 (accessed 2026-11-25)
- https://www.anthropic.com/news/contextual-retrieval (accessed 2026-11-25)
- https://modelcontextprotocol.io/docs/getting-started/intro (accessed 2026-11-25)