---
title: Retrieval-augmented generation
kind: concept
id: retrieval-augmented-generation
domain: ai
parent: machine-learning
url: https://gurkanozkan.ai/concepts/retrieval-augmented-generation/
markdown: https://gurkanozkan.ai/concepts/retrieval-augmented-generation.md
---

# Retrieval-augmented generation

Answering with a model that is handed relevant passages, found by search over a document store, together with the question.

An open-book exam instead of a closed-book one: before answering, the model is handed the pages that look relevant. {#p-sf0zfy}

## How it works {#how-it-works}

Documents are cut into passages and indexed, by keywords or by numerical representations of their meaning. When a question arrives, a retriever finds the passages that best match it, they are placed in the prompt next to the question, and the model answers using them. Lewis and colleagues (2020) combined a pre-trained language model, which holds knowledge in its parameters, with an explicit memory, a vector index of Wikipedia read by a trained retriever. They argued that this helps with two open problems: showing where an answer came from, and updating what the system knows without retraining it. {#p-oq2ea3}

## Where it misleads {#where-it-misleads}

The retriever can miss the one passage that matters, and the model can ignore or misread what it is given. Position matters too: Liu and colleagues (2024) found that models often do best when the relevant information is at the beginning or end of a long input and degrade significantly when it sits in the middle, so adding more passages is not always better. The quality of the answer is capped by the quality of the document store. {#p-2xsufu}

## Sources {#sources}

- Lewis, P. et al. (2020). [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/abs/2005.11401). *NeurIPS 2020*.
- Liu, N. F. et al. (2024). [Lost in the Middle: How Language Models Use Long Contexts](https://doi.org/10.1162/tacl_a_00638). *Transactions of the Association for Computational Linguistics* 12, 157–173.

- Domain: [AI](https://gurkanozkan.ai/topics/ai/)
- Broader concept: [Machine learning](https://gurkanozkan.ai/concepts/machine-learning/)

## Relations

- related to: [Large language models](https://gurkanozkan.ai/concepts/large-language-models/)

## Essays

- [Can an AI server learn a new fact for good? Eight of 140 attempts were kept, and a plain prompt beat it](https://gurkanozkan.ai/writing/living-weights-in-serving/) (2026-11-15)
