What Is Retrieval-Augmented Generation?
Retrieval-augmented generation, or RAG, finds information in an external source and supplies it as context before a generative model produces an answer. It helps a model use knowledge that is more relevant, current, private, or traceable than its parametric knowledge alone.
RAG is not one particular model. It is a system architecture connecting data sources, retrieval, context construction, a large language model, and evaluation.
For the wider system view, begin with how generative AI and LLMs work, then use this guide to examine the retrieval layer more closely.
- RAG combines retrieval with generation.
- Documents are not permanently inserted into the LLM; relevant passages are selected at request time.
- It suits private, changing, or citation-dependent information.
- Answer quality is constrained by sources and retrieval, not only the model.
- RAG can reduce factual risk but cannot eliminate hallucinations.
- Document governance and evaluation are core system components.
Why Is RAG Useful?
A large language model learns patterns from training data. Knowledge embedded in its parameters has practical limits:
- information can change after training;
- an organisation’s private data may never enter training;
- the origin of a claim can be difficult to trace;
- updating facts through retraining is costly and impractical;
- the model may still answer when its knowledge is insufficient.
RAG gives an application a route to find information when required. An internal assistant can retrieve the latest policy, a support system can consult product documentation, and a research tool can attach evidence to its response.
The original Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks paper combined parametric memory in a generative model with non-parametric memory in a document index accessed by a retriever. Modern implementations vary, but the retrieval-plus-generation principle remains.
How Does a RAG Pipeline Work?
A typical pipeline has two broad phases: preparing knowledge and answering a request.
Preparing sources
- Documents are collected from permitted sources.
- Content is cleaned and separated from navigation or noise.
- Documents are divided into passages small enough to retrieve without losing necessary context.
- Passages may be converted into embeddings and stored in a vector index.
- Metadata such as title, date, owner, permission, and version is retained.
Answering a question
- The question becomes a retrieval query.
- The system finds passages considered relevant.
- Candidates may be filtered or reranked.
- Selected evidence enters the context with instructions.
- The LLM composes an answer from that context.
- The application may show citations, ask for clarification, or decline when evidence is insufficient.
Retrieval does not have to use a vector database. Keyword search, relational queries, knowledge graphs, APIs, and hybrid search can suit different information types.
The Main Components
| Component | Principal job |
|---|---|
| Data source | Supplies authorised documents or facts |
| Ingestion | Collects, cleans, and refreshes content |
| Chunking | Divides documents while preserving useful context |
| Index | Stores searchable representations |
| Retriever | Finds candidate evidence |
| Reranker or filter | Improves ordering, relevance, and permission checks |
| Context builder | Assembles evidence and model instructions |
| Generator | Produces the response |
| Citation layer | Connects claims with sources |
| Evaluation | Measures retrieval and answer quality |
A failure in one component can look like a model failure. A wrong response might begin with an obsolete document, weak metadata, an isolated chunk, a poor query, or truncated evidence.
When Does RAG Make Sense?
It is particularly relevant when work requires:
- internal knowledge unavailable to a public model;
- frequently changing information;
- answers limited to a defined document set;
- role-based access or permissions;
- provenance, source links, or citations;
- source correction without model retraining;
- search over catalogues, policies, knowledge bases, or documentation.
Examples include employee-policy assistants, documentation search, knowledge-based customer support, contract analysis, and sourced research.
Not every task needs RAG. Tone transformation, short-text classification, general outlining, and consistent formatting may be solved with an appropriate model and prompt.
RAG, Search, Fine-Tuning, and Long Context
These approaches can complement one another.
| Approach | Question addressed |
|---|---|
| Search | Which documents are relevant? |
| RAG | How should retrieved evidence inform a generated response? |
| Fine-tuning | How should model behaviour or output patterns change? |
| Long context | How much information can enter one interaction? |
Loading every document into a long context can work for a limited corpus. At scale, cost, latency, permissions, document changes, and relevance often preserve a role for retrieval.
Fine-tuning is not a direct replacement either. It suits stable task behaviour or style, while RAG is easier to refresh when facts change and need traceability.
Why Can a RAG Answer Still Be Wrong?
RAG moves part of the problem from “what does the model know?” to “which evidence was found and how was it used?” Common failures include:
- incorrect, incomplete, or obsolete sources;
- chunks separating a condition from its explanation;
- queries using vocabulary different from the source;
- retrieval of a similar passage that does not answer the question;
- permission-filter failure;
- conflicting evidence in the context;
- the model ignoring evidence or adding unsupported details;
- a citation pointing to a document that does not support the specific claim.
LLM hallucinations therefore remain an evaluation concern. RAG can improve groundedness in suitable conditions, but it is not a guarantee of factuality.
How Should RAG Be Evaluated?
Retrieval and generation should be tested separately so that failures can be located.
Retrieval
- Does the correct evidence appear among the leading candidates?
- Do permissions and filters work?
- Do chunks retain the context required to answer?
- Are difficult queries and alternative terminology represented?
Generation
- Is the answer supported by the evidence?
- Does each citation substantiate the nearby claim?
- Does the model express uncertainty when sources are inadequate?
- Is the response relevant and instruction-compliant?
Complete system
- What are latency and cost per request?
- Do source changes reach the index on time?
- Is sensitive data recorded or exposed?
- Which query patterns fail most often?
A useful test set includes ordinary, ambiguous, unanswerable, conflicting-source, version-sensitive, and unauthorised-access questions.
Sound Implementation Principles
- Identify authoritative sources and document owners.
- Preserve version, date, entity, and permission metadata.
- Chunk by information structure rather than character count alone.
- Use hybrid retrieval where exact terms and semantic similarity both matter.
- Allow clarification or refusal when evidence is insufficient.
- Show accessible citations that support the actual claim.
- Retain feedback and failed queries for evaluation.
- Retest whenever sources, indexes, models, or prompts change.
Frequently Asked Questions
Is RAG the same as a vector database?
No. A vector database can support retrieval, but a RAG system includes sources, ingestion, search, context, generation, citations, and evaluation. Retrieval can also use keywords or conventional databases.
Does RAG retrain the LLM?
Not by default. It supplies information during inference. Adding a document to an index does not change model parameters.
Can RAG use real-time data?
Yes, when it queries a live source or an index refreshed within the required interval. “Real time” still needs a definition based on delay tolerance and risk.
Does RAG guarantee sourced answers?
No. The application must implement attribution and test whether a citation genuinely supports each generated claim.
Conclusion
RAG connects an LLM’s language capabilities with external information that can be refreshed and traced. It is valuable when answers need to follow documents, private data, or changing facts.
Its value does not come from a vector database alone. Source governance, retrieval quality, context construction, citations, permissions, and evaluation determine whether the system produces more trustworthy answers.