SysArt
Book a briefing
SysArt

Explainer

What is retrieval-augmented generation?

RAG lets a language model answer from your documents instead of from memory alone. This explainer covers how it works, where it came from, where it fails and what an enterprise needs around it.

Last reviewed by SysArt AI Architecture Team7 min readHow we review

In short

Retrieval-augmented generation (RAG) answers a question in two steps: a search finds the most relevant passages in a document collection, and a language model writes an answer from those passages, ideally with citations. It keeps answers current without retraining the model and lets access rules apply at search time, but answer quality is capped by retrieval quality.

DefinitionRetrieval-augmented generation (RAG) is a technique in which a system retrieves passages relevant to a question from an external knowledge source and gives them to a language model as context, so that the answer is grounded in those passages rather than only in what the model learned during training.

Key takeaways

  • RAG combines a retriever that finds relevant passages with a generator that writes the answer from them; the term comes from a 2020 paper by Lewis and colleagues.
  • It keeps knowledge current by re-indexing documents rather than retraining the model, and it can cite the passage behind each statement.
  • Answer quality is capped by retrieval quality, so parsing, chunking, hybrid search and reranking matter as much as the choice of model.
  • RAG reduces fabricated answers but does not remove them, and retrieved documents can carry hidden instructions, so evaluation and prompt-injection defences are part of the design.
  • In an enterprise, retrieval must enforce each user's access rights from the source systems before any passage reaches the model.

What is retrieval-augmented generation?

Retrieval-augmented generation (RAG) is a way of answering questions in which a search step first finds the passages most relevant to the question, and a language model then writes the answer from those passages. The name describes the two halves: retrieval finds the evidence, and generation turns it into an answer.

Without retrieval, a language model answers from what it learned during training. That knowledge stops at the training cut-off, does not include your internal documents and cannot point to a source. When the model lacks the facts it can still produce fluent text, which NIST’s generative AI profile calls confabulation: confidently stated but erroneous or false content. RAG gives the model the relevant evidence at question time and asks it to answer from that evidence.

Neither half replaces the other. Weak retrieval caps the quality of every answer, however strong the model is, and weak generation can waste good passages on vague or unsupported wording.

Where does RAG come from?

The term comes from a 2020 paper by Patrick Lewis and colleagues, “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, accepted at NeurIPS 2020.

The paper started from two weaknesses of knowledge stored only in a model’s parameters: it is hard to update, and it gives no provenance for an answer. Its approach combined two kinds of memory: a pretrained sequence-to-sequence model (parametric memory) and a dense vector index of Wikipedia (non-parametric memory) searched by a pretrained neural retriever. It tested two variants, one that uses the same retrieved passages for a whole answer and one that can draw on different passages for each token. It reported state-of-the-art results on three open-domain question-answering tasks, and more specific, diverse and factual text than a model without retrieval.

Dense retrieval had just been shown to work at scale. The dense passage retrieval (DPR) paper by Karpukhin and colleagues, published the same year, beat the BM25 keyword method by 9 to 19 percentage points in top-20 passage retrieval accuracy. One difference from the original: Lewis and colleagues presented RAG as a general-purpose fine-tuning recipe, training the models for each task, while a system today can use an unchanged general-purpose model and put the effort into the retrieval pipeline, which is the approach this explainer describes.

How does a RAG pipeline work?

In two flows: an ingestion flow that prepares documents ahead of time, and a query flow that runs for each question.

Ingestion

  1. Connect to approved sources, such as document management systems, wikis, ticketing systems and file shares.
  2. Parse each document, keeping headings, tables and page references.
  3. Chunk it into passages small enough to be specific and large enough to make sense on their own, with metadata such as source, owner, date and access rights.
  4. Embed each passage with an embedding model, which turns text into a vector that captures its meaning (see what a vector embedding is), and index it for both vector and keyword search.

Query

  1. Search with the user’s question, combining keyword and vector search. Hybrid search merges the two result lists by normalising their scores or by reciprocal rank fusion.
  2. Filter the results by the user’s access rights, so that only passages they may read are used.
  3. Rerank the candidates with a model that scores each question and passage together. Nogueira and Cho’s BERT reranker improved on the previous best result on the MS MARCO passage retrieval task by 27% (relative, in MRR@10).
  4. Generate an answer from the top passages, which are labelled in the prompt as data rather than instructions, and ask the model to cite them.
  5. Log which passages produced each answer.

Order and quantity matter. The “Lost in the Middle” study found that language models use information best when it appears at the beginning or end of a long context and worst when it sits in the middle, so adding more passages does not automatically help.

Because RAG combines what search does well, finding current sources that a user is allowed to see, with what language models do well, reading and summarising them. Each approach fails in a different way:

Language model aloneEnterprise searchRAG
Where the answer comes fromWhat the model learned in trainingThe documents; the user reads themRetrieved passages, summarised by the model
Internal and recent knowledgeMissing unless it was in the training dataCurrent as of the last index updateCurrent as of the last index update
CitationsNot reliableEvery result is a documentEach statement can link to its passage
Access controlNone over what the model learnedEnforced on resultsEnforced during retrieval, before the model sees passages
Typical failureConfident but false statementsThe right documents, but the user must find the answerWrong or missing passages, or an answer that goes beyond them
EffortLowestConnectors and an indexConnectors, an index, prompts, evaluation and security testing

For adding knowledge, RAG generally beats fine-tuning. In a comparison by Ovadia and colleagues, RAG consistently outperformed unsupervised fine-tuning, both for knowledge the model had seen in training and for entirely new knowledge. Fine-tuning remains useful for changing behaviour, such as format, tone or terminology, and the two can be combined.

What can enterprises use RAG for?

For questions whose answers are written down somewhere in the organisation, asked by people who would otherwise have to search for them.

  • Policy and procedure assistants for HR, IT, finance and compliance questions, with a link to the governing document.
  • Support that answers from manuals, knowledge-base articles and resolved tickets, and lets product teams ask what customers have said about a feature in feedback and tickets.
  • Project and delivery knowledge, so that teams can ask what was decided, when and where, across specifications, meeting notes, retrospectives and sprint reviews, instead of searching wikis and email threads.
  • Contract, regulatory and technical documents, where an answer must point to the exact clause or section.

RAG is a weaker fit when the answer needs calculations across a whole dataset, which is a job for a database query or an analytics tool; when the knowledge was never written down; or when a task needs one long document read in full, which can go to the model directly if it fits the context window.

Where does RAG go wrong?

Most failures start in retrieval rather than in the model, and some come from the documents themselves.

  • Retrieval misses. Tables split across chunks, passages too short to make sense, exact identifiers that a pure vector search can rank low, or the right passage ranked tenth.
  • Answers beyond the evidence. The model adds claims the passages do not support. Retrieval reduces confabulation but does not remove it.
  • Stale or conflicting content. Old policy versions and duplicates compete with current ones. OWASP lists conflicting knowledge from multiple sources among the vector and embedding weaknesses of LLM applications.
  • Indirect prompt injection. A retrieved document can carry hidden instructions that try to steer the model. OWASP notes that RAG does not fully mitigate prompt injection, so retrieved text must be treated as data, the assistant should get only the access it strictly needs, and high-risk actions should require human approval.
  • Leakage between users. A shared index without permission filtering can show one team’s documents to another. OWASP recommends permission-aware vector stores and strict logical and access partitioning.

Measure quality rather than judging it by impression. A test set of real questions, each with an expected answer and supporting passages, lets you score retrieval, groundedness and the answers themselves; the Ragas framework, for example, scores context relevance, faithfulness and answer quality. Our AI security work covers prompt-injection testing.

What does enterprise RAG need beyond the basic pipeline?

Access control from the source systems, evaluation, security testing, logging and an owner for every document collection.

  • Permissions synchronised from each source system and enforced at query time by the user’s identity, so that the assistant never uses a passage the user could not open.
  • Ownership of each collection: who may add sources, how often they are re-indexed and how outdated content is retired.
  • Deletion that reaches the index. When a document is deleted, or a person successfully asks for their data to be erased under the GDPR, the passages, embeddings and caches derived from it should be removed too.
  • Evaluation and release gates, re-run whenever documents, prompts, models or chunking change.
  • Audit logs that record which passages produced each answer.

Every part of this can run on infrastructure you control, from parsing and embedding to the index, the reranker and the language model. Our enterprise RAG service builds and operates such systems, and the private LLM page covers the assistant that users see.

Frequently asked questions

What is RAG in simple terms?

RAG, short for retrieval-augmented generation, is a way of answering questions from a set of documents. A search step finds the passages most relevant to the question, and a language model writes an answer based on them, ideally citing each one. The model works like a well-briefed reader instead of relying on its memory.

Who invented retrieval-augmented generation?

The term comes from the paper 'Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks' by Patrick Lewis and co-authors, first published in May 2020 and accepted at NeurIPS 2020. It combined a pretrained sequence-to-sequence model with a dense vector index of Wikipedia, searched by a neural retriever, and reported state-of-the-art results on three open-domain question-answering tasks.

Does RAG stop hallucinations?

No, but it reduces them when retrieval works. The model can still misread passages, combine them wrongly or add claims they do not support, and it cannot answer correctly from passages that were never retrieved. NIST calls this risk confabulation. Require citations, instruct the model to say when the sources are silent, and measure groundedness with a test set.

Is RAG better than fine-tuning?

For adding knowledge, usually yes. In a comparison by Ovadia and colleagues, RAG consistently outperformed unsupervised fine-tuning, both for knowledge seen in training and for entirely new knowledge. RAG also keeps content current by re-indexing and can enforce per-user permissions. Fine-tuning is better suited to changing behaviour, such as format, tone or domain terminology.

What is a vector database in RAG?

It is the index that stores embeddings, the numeric representations of passages, and finds the ones closest to the embedded question. It can be a dedicated vector database, a search engine with vector support or an extension to a database you already run, such as pgvector for PostgreSQL. It is usually combined with keyword search.

Can RAG run on-premises?

Yes. Every component, from document parsing and the embedding model to the vector index, the reranker and the language model, can run on servers you control, including air-gapped networks. Documents, questions and answers then stay inside your boundary. The design still needs permission-aware retrieval, evaluation and prompt-injection defences, wherever it runs.

How do you measure RAG quality?

With a test set of real questions, each with an expected answer and the passages that support it. Score whether the right passages were retrieved, whether every statement in the answer is supported by them, and whether the answer is correct and complete. Frameworks such as Ragas automate parts of this, and agreed thresholds become release criteria.

What is the biggest security risk in RAG?

Indirect prompt injection: instructions hidden in a retrieved document that try to steer the model. OWASP notes that RAG does not fully mitigate prompt injection. Treat retrieved text as data, label it in the prompt, require human approval for high-risk actions, and test with planted malicious documents. Shared indexes also need strict access partitioning.

Scope a RAG use case

Bring the questions your users ask and the sources behind them. We outline the pipeline, the access model and the test set that will show whether it works.