---
title: 'Retrieval-augmented generation (RAG)'
description: 'Generating a response after retrieving relevant material from an external knowledge source and adding it to model context.'
canonical_url: 'https://darkfactory.dev/glossary/retrieval-augmented-generation'
markdown_url: 'https://darkfactory.dev/glossary/retrieval-augmented-generation.md'
collection: glossary
date_published: '2026-08-03T00:00:00-04:00'
date_modified: '2026-08-26T00:00:00-04:00'
---

# Retrieval-augmented generation (RAG)


## Definition

Retrieval-augmented generation retrieves material from an external knowledge source and conditions generation on the selected results. The external source may be a document collection, database, search service, or knowledge graph. Retrieval changes the evidence available at runtime without changing the generator's weights.

A production RAG path usually has two sides. Ingestion creates source records, chunks or structures them, attaches provenance and permissions, and builds indexes. Query processing searches those indexes, may rerank and filter candidates, assembles context, and invokes the generator. A reliable system also records which sources were retrieved and whether they support the answer.

Patrick Lewis and colleagues introduced the term "retrieval-augmented generation" and the RAG acronym in their 2020 paper. Their system combined a pretrained sequence-to-sequence generator with a dense Wikipedia index and a neural retriever. It was a specific trainable architecture. Current usage has broadened to many pipelines in which retrieval results are placed into a model prompt.

RAG keeps some application knowledge in external sources instead of relying only on model parameters, which can make that material easier to update and cite. It does not guarantee grounding. The retriever can miss the needed item, stale or low-quality material can rank highly, chunks can omit necessary context, and the generator can ignore or misstate retrieved evidence. Retrieved text can also contain prompt injection, so source content should not inherit instruction authority.

Evaluation should isolate the stages. Measure corpus coverage, retrieval recall, ranking, context sufficiency, citation support, and answer quality. A single end-to-end score cannot identify which stage failed.

## Distinguish it from nearby terms

Search returns results without necessarily generating an answer. Semantic search is one possible retrieval method. A vector database is one possible index and storage layer. Fine-tuning changes model weights, while RAG changes runtime context. GraphRAG uses graph structure in retrieval and synthesis.

## Check your understanding

The correct policy exists in the corpus, but an older version ranks first and the answer cites it faithfully. Which ingestion, metadata, ranking, and answer checks should catch the failure?

## Also called

RAG

## Related terms

- [GraphRAG](https://darkfactory.dev/glossary/graphrag)
- [Knowledge graph](https://darkfactory.dev/glossary/knowledge-graph)
- [Vector database](https://darkfactory.dev/glossary/vector-database)
- [Semantic search](https://darkfactory.dev/glossary/semantic-search)
- [Reranking](https://darkfactory.dev/glossary/reranking)
- [Prompt injection](https://darkfactory.dev/glossary/prompt-injection)
- [Provenance](https://darkfactory.dev/glossary/provenance)

## Related factory areas

- [Context, memory, knowledge & skills](https://darkfactory.dev/factory/context-memory-skills)

## Evidence and further reading

- [NIST AI 100-2: Adversarial Machine Learning](https://csrc.nist.gov/pubs/ai/100/2/e2025/final)
- [Google Machine Learning Glossary](https://developers.google.com/machine-learning/glossary/)
- [How Claude Code Works in Large Codebases](https://www.claude.com/blog/how-claude-code-works-in-large-codebases-best-practices-and-where-to-start)
- [Microsoft GraphRAG Documentation](https://microsoft.github.io/graphrag/)
- [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/abs/2005.11401)
