Retrieval-augmented generation (RAG)

Also called: RAG

What is Retrieval-augmented generation?

Retrieval-augmented generation is a technique where relevant passages are retrieved from a document store and supplied to a language model, which is then instructed to answer only from them. It is the standard way to make a model answer accurately about a specific business rather than from general training data.

In more detail

A language model on its own knows only what was in its training data, which does not include your prices, your opening hours or last week's change of policy. RAG adds a search step: before the model answers, the system finds the passages of your content most relevant to the question and puts them in front of the model, with instructions to answer from them.

The search step usually uses embeddings and vector search, so a question can match a passage that uses different words. The final answer depends on both halves: if retrieval brings back the wrong passage, even a strong model answers the wrong question.

RAG is cheaper and easier to keep current than retraining a model. Updating an answer means updating the content.

An example

A visitor asks "are you open on bank holidays?". Retrieval finds the paragraph on the opening-hours page that mentions bank holidays, and the model answers from that paragraph instead of from a general idea of how shops behave.

Illustration for "Retrieval-augmented generation (RAG)"GLOSSARYRetrieval-augmentedgeneration (RAG)
Retrieval-augmented generation (RAG), defined in plain English.
Retrieval-augmented generation connected to customers and the tools that serve themRetrieval-augmentedgenerationEmbeddingVector searchGroundingKnowledge base
Related terms in this glossary.

How SpideyChat handles it

SpideyChat splits each page and document into passages of about 1,000 characters with a small overlap, and stores an embedding of each. For every question it retrieves the five closest matches across those passages and the FAQ answers the owner has written, and the model is told to answer only from them.

We make SpideyChat. The rest of this page describes the term in general, not our product.

Questions

Is RAG the same as training a model on my website?
No. The model itself is not changed. Your content is searched when a question arrives and passed to the model, so an edit takes effect as soon as the stored content is updated, with no retraining.
Does RAG stop hallucinations?
It reduces them a great deal when combined with an instruction to answer only from the retrieved text and to say when the answer is not there. It cannot help with questions your content does not cover.

All glossary terms