Retrieval-Augmented Generation (RAG) Explained
Also known as: RAG · Retrieval-augmented generation
Definition
Retrieval-Augmented Generation is a method that retrieves relevant external information for a query and supplies it to a generative model as context before the model produces an answer.
Contents
Retrieval-Augmented Generation, commonly shortened to RAG, combines an information-retrieval system with a generative model. Instead of asking the model to answer only from patterns encoded in its parameters, a RAG system first searches an external collection, selects relevant material, and places that material in the model's context. The model then generates a response grounded in the retrieved evidence.

Simple analogy
Imagine answering a difficult question in an open-book exam. You could rely on memory alone, but a better process is to search the approved books, open the most relevant pages, and write an answer using those pages. Retrieval is the act of finding and opening the pages. Generation is the act of composing the answer.
The analogy also reveals the limits. If the search returns the wrong pages, the final answer may be wrong even if the writer is capable. If the writer ignores the pages or misreads them, good retrieval is not enough. RAG is a pipeline whose quality depends on both stages and on the connection between them.
How it works
Preparing the knowledge collection
Documents are collected from approved sources and usually divided into passages or chunks. Each chunk receives metadata such as its title, URL, owner, date, permissions, or product version. Many systems convert each chunk into an embedding: a numerical vector intended to place semantically related text near each other. The vectors and metadata are stored in a search index.
Chunking is not a neutral preprocessing detail. A chunk that is too small may lose the surrounding explanation; one that is too large may bury the useful sentence and consume the model's context budget. Structure-aware splitting, overlap, headings, and document-specific rules can improve retrieval.
Turning a query into candidates
At question time, the system converts the query into a search request. Dense retrieval compares query and passage embeddings. Lexical retrieval, such as BM25-style search, emphasizes shared terms. Hybrid systems combine dense and lexical signals because semantic similarity and exact keywords solve different failure cases. Filters may restrict results by tenant, access permission, language, date, or content type.
The first search often returns a larger candidate set. A reranker can then apply a more expensive relevance model to choose the strongest few passages. Query rewriting or decomposition may help when the original question is ambiguous or contains several subquestions. These steps should be evaluated on real queries rather than added automatically, because each one increases latency and complexity.
Supplying evidence to the generator
The selected passages are placed in a prompt together with the user's question and instructions. The instructions may require the model to answer only from the provided material, cite passage identifiers, or say when evidence is insufficient. The generator reads this constructed context and produces a response.
Some systems retrieve once. Others repeat retrieval during a task, search separately for subquestions, or let an agent decide when more evidence is needed. These are extensions of the basic pattern, not requirements for something to count as RAG.
Evaluating the whole pipeline
Retrieval can be measured with metrics such as recall at a cutoff: did the candidate set contain material needed for the answer? Ranking can be checked by whether the best evidence appears near the top. Generation should be evaluated for correctness, faithfulness to the supplied passages, citation accuracy, completeness, and appropriate refusal when evidence is missing.
End-to-end answer scores alone can hide the source of a failure. Teams should preserve traces showing the query, filters, retrieved passages, ranking scores, final context, and answer while respecting privacy requirements. This makes it possible to distinguish a retrieval failure from a generation failure.
Why it matters
Model parameters are not a convenient database. Updating them generally requires training, and a model may reproduce learned facts imprecisely. Retrieval lets an application use a changing knowledge collection without retraining the base model for every document update. It can also connect the model to private material that was never part of training.
RAG can improve traceability because the application knows which passages were supplied. It can show citations or links and let a reader inspect the evidence. However, a displayed citation is useful only if it actually supports the nearby claim. RAG does not automatically make an answer factual, and the model can still combine, omit, or contradict retrieved material.
The approach also creates operational controls. Documents can be deleted from the index, filtered by permission, versioned, or refreshed on a schedule. These controls are often more practical than trying to encode every changing business fact into model weights.
Practical use cases
- Support assistants: Retrieve product documentation, policies, and known issue reports before drafting a response.
- Enterprise knowledge: Search internal handbooks, project records, or approved research while enforcing access controls.
- Research tools: Find relevant papers or passages and provide links that a user can verify.
- Current-information systems: Refresh an index with new material more frequently than a model can be retrained.
- Specialized drafting: Ground contracts, reports, or technical explanations in a controlled source collection while retaining human review.
RAG is most useful when answers depend on identifiable external knowledge. It is less helpful for tasks that need no knowledge lookup, or when the collection is incomplete, untrusted, or poorly maintained.
Common misconceptions
“RAG eliminates hallucinations.” It can reduce unsupported answers when retrieval and prompting work well, but it cannot guarantee truth. The retrieved documents may be wrong, irrelevant, outdated, or malicious, and the generator may misuse them.
“A vector database is the RAG system.” A vector index is one possible retrieval component. A production RAG system also needs ingestion, permissions, chunking, ranking, context construction, generation, evaluation, and monitoring. Lexical or structured retrieval may be equally important.
“More retrieved text always improves the answer.” Excess context can introduce distractions, contradictions, and higher cost. The goal is sufficient high-quality evidence, not the largest possible prompt.
“Fine-tuning and RAG are interchangeable.” Fine-tuning changes model behavior or learned patterns; RAG supplies information at inference time. They solve different problems and can be used together.
Frequently asked questions
Does RAG require a vector database?
No. Retrieval can use lexical search, a relational database, a knowledge graph, web search, dense vectors, or a hybrid. The defining feature is retrieving external information and giving selected evidence to the generator.
How many passages should a RAG system retrieve?
There is no universal number. It depends on passage size, context limits, question complexity, ranking quality, and latency. Evaluate several cutoffs on representative questions and measure both evidence recall and answer faithfulness.
Can RAG use private company documents safely?
It can, but only when ingestion, retrieval, logging, and generation enforce the same access controls as the source systems. Tenant and user permissions must be applied before passages enter the model context.
What is the difference between retrieval and reranking?
Retrieval efficiently finds a candidate set from a large collection. Reranking applies a more detailed relevance calculation to those candidates so the best evidence is more likely to enter the final context.
