What is retrieval-augmented generation (RAG)?
Retrieval-augmented generation (RAG) is a method in which a language model finds the passages in an organisation's documents that are relevant to a question before it answers, then grounds its answer in those passages.
The documents do not train the model; they are supplied as context at answer time and the answer can cite the passage it rests on. Unlike fine-tuning, which changes the model's weights through training, RAG leaves the weights untouched.
- Topic
- Embeddings, document processing and RAG
- Also known as
- RAG, retrieval augmented generation
- Origin
- 2020, Lewis et al.
How retrieval-augmented generation (RAG) works
- Documents are parsed, split into meaningful chunks and stored in an embedding or keyword index.
- When a question arrives, a retriever finds the most relevant chunks through vector, keyword or hybrid search.
- An optional reranking model reorders those chunks by relevance.
- The selected chunks go into the prompt with the question and the model answers from that context, citing the source.
When documents change, only the index is updated; the model is not retrained.
In more detail
Chunking strategies and preserving context
Chunking strategy directly governs retrieval quality: splitting documents purely by fixed character counts often severs tables, headings or clauses in half. Effective pipelines preserve document structure (layout-aware or recursive chunking), use modest overlap or apply parent-child indexing, matching on small granular chunks while passing the broader surrounding section to the generator.
Where RAG is heading: agentic RAG, GraphRAG and multimodal RAG
RAG evolved beyond the linear retrieve-then-generate loop into Agentic RAG (where the model iteratively decides when to search, reformulate queries or verify evidence), GraphRAG (combining vector search with knowledge graphs for multi-hop and corpus-wide questions) and Multimodal RAG (indexing PDFs, charts and tables visually with models such as ColPali without lossy OCR).
The RAG evaluation triangle: context precision, context recall and faithfulness
Debugging a RAG system requires separating retrieval quality from generation quality using frameworks such as RAGAS or TruLens. Key metrics include Context Precision and Context Recall (did the retriever surface the exact right evidence?), alongside Faithfulness and Answer Relevance (did the LLM stick strictly to that evidence without hallucinating?).
Why RAG still matters despite long context windows
Even as modern LLMs support very long context windows, RAG remains essential in enterprise deployments: stuffing large corpora into every prompt drives up latency and compute cost, degrades accuracy in the middle of long contexts (context rot) and bypasses fine-grained document permissions and live index updates.
Commonly confused terms
| Term | How it differs |
|---|---|
| Semantic search | Semantic search (or vector search) only retrieves relevant chunks and returns ranked results, whereas RAG passes those retrieved chunks into a generative language model to synthesise a grounded natural-language answer with citations. |
| Long-context prompting | Long-context prompting feeds entire documents directly into the model's prompt window without an external index, whereas RAG selectively retrieves only the most relevant snippets from large or rapidly changing corpora. |
Why retrieval-augmented generation (RAG) matters for on-premises AI
In an on-premise deployment the embedding model, the vector database and the language model run in the same environment, so document content can stay in the organisation. Document-level permissions are enforced at retrieval time (permission-aware retrieval), which keeps answers to documents each user may see. Once a document is removed from the index it no longer appears in answers; with fine-tuning, traces of the data stay in the model weights.
A bank makes its archive of internal regulations and procedures searchable with RAG. When an employee asks a question, the answer arrives with the regulation clause it is based on.
Common questions
Does RAG eliminate hallucinations?
No. If retrieval picks the wrong chunk or the model misreads the context, the answer can still be wrong. That is why reranking, citation checks and faithfulness measurement are used together.
RAG or fine-tuning?
RAG suits knowledge that changes often and needs a cited source. Fine-tuning suits changing the model's behaviour or the format of its answers. The two can also be combined.
Related terms
- Chunking
- Embedding
- Vector database
- Hybrid search
- Reranking
- Permission-aware retrieval
- Faithfulness
- Grounding
- Retrieval
- Semantic search
- Fine-tuning
- Agentic Retrieval-Augmented Generation
- Cache-augmented generation
Sources
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, 2020
- Gao et al., Retrieval-Augmented Generation for Large Language Models: A Survey, 2023
Related page on this site: Related FAQ · In the glossary: Glossary, R to Z