RAG (retrieval-augmented generation)

Reviewed : How we review entriesLast updated

In brief

RAG means retrieving relevant documents from a knowledge base, then giving them to a language model so that it bases its answer on them.

Sources[1]

Definition

RAG (Retrieval-Augmented Generation) is a technique that combines a search engine with a language model. Before answering, the system retrieves relevant passages from a document base, then inserts them into the prompt given to the model, which generates its answer based on them.

The steps

  1. Preparation: documents are split into passages, turned into embeddings and stored in an index (often a vector database).
  2. Retrieval: the user’s question is converted the same way, and the closest passages are found.
  3. Generation: the selected passages are added to the model’s prompt, which writes the answer, ideally citing its sources.

Benefits

  • Access recent or private information the model has not learned.
  • Reduce (without eliminating) hallucinations by anchoring the answer in documents.
  • Cite sources, which makes checking easier.
  • Update knowledge without retraining the model.

Limits

The quality of the answer depends on the quality of retrieval: poor splitting or irrelevant passages degrade the result. The model may also ignore or misread the documents it is given.

Sources

  1. Lewis et al., “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks” (2020)