RETRO

Also known as: Retrieval-Enhanced Transformer

On this page 7

RETRO, short for Retrieval-Enhanced Transformer, is a language model architecture that conditions text generation on passages retrieved from a very large external database, so that part of its knowledge lives in an index rather than in its weights. Introduced by DeepMind in late 2021, it is a landmark design in the Retrieval & knowledge area of artificial intelligence because it showed that a 7.5-billion-parameter model with retrieval could match the language modeling quality of models roughly 25 times larger on several benchmarks.

Unlike RAG pipelines that paste retrieved text into a prompt, RETRO builds retrieval into the network itself. A dedicated mechanism called chunked cross-attention lets each segment of the input attend to its own retrieved neighbors during both training and inference.

How RETRO retrieves and integrates text

RETRO splits every input sequence into fixed chunks of 64 tokens. For each chunk, it looks up the nearest neighbors in a retrieval database using embeddings from a frozen, pretrained BERT model, averaged over the chunk. Because the embedding model is frozen, the database index can be computed once and never needs to be rebuilt during training.

Each retrieved neighbor consists of the matching database chunk plus its continuation, giving about 128 tokens of context per neighbor. The neighbors pass through a bidirectional transformer encoder that is itself conditioned on the activations of the query chunk. The main decoder then reads these encoded neighbors through chunked cross-attention layers inserted at regular intervals, for example every third layer.

A strict causality constraint shapes the design. Neighbors retrieved for chunk n may influence only the tokens of chunk n and later, never earlier tokens, so the model remains a valid autoregressive language model. In practice, the attention is shifted so the last token of a chunk and the following chunk use that chunk’s neighbors.

The table below lists the main components and the values reported for the original configuration.

ComponentOriginal settingPurpose
Chunk size64 tokensUnit of retrieval and attention
Neighbors per chunkUsually 2Supplies supporting text
Retriever embeddingsFrozen BERT, averagedFixed keys for the index
Nearest neighbor searchApproximate, via SCaNNSublinear lookup over trillions of tokens
Retrieval databaseAbout 2 trillion tokensExternal, updatable knowledge store
Decoder size172M to 7.5B parametersModel family evaluated
Core components of the original RETRO design

Chunked cross-attention explained

Chunked cross-attention (CCA) is the operation that makes RETRO efficient. Instead of letting every token attend to every retrieved passage for the whole sequence, each chunk attends only to its own neighbors. The cost therefore grows linearly with the number of retrieved chunks, rather than quadratically as it would if all passages were concatenated into one long context.

This locality also explains a key property: the model can use many more retrieved tokens than its own context window would allow. A 2,048-token input with 32 chunks and two 128-token neighbors each effectively consults 8,192 retrieved tokens without placing them in the self-attention context.

The comparison below shows how CCA differs from the main alternatives for feeding retrieved text into a model.

Integration methodWhere retrieval entersCost profile
Prompt concatenation (RAG)Input context of the decoderQuadratic in total context length
Fusion-in-decoderDecoder attends to encoded passagesLinear in passages, encoder per passage
Chunked cross-attention (RETRO)Dedicated layers per chunkLinear in retrieved chunks
kNN-LM interpolationOutput distribution onlyLookup at every generated token
Ways of integrating retrieved passages

RETRO belongs to a family of retrieval-augmented language models that differ in when retrieval happens, whether the retriever is trained and how large the database can be. Its distinctive choices are a frozen retriever and a database measured in trillions of tokens, far larger than the document collections used by earlier systems.

ModelRetriever trainingMain use
RETROFrozen BERT embeddingsLanguage modeling at scale
REALMTrained jointly with the readerOpen-domain question answering
RAG (original)Dense retriever fine-tuned end to endKnowledge-intensive generation
kNN-LMUses the model’s own hidden statesPerplexity reduction, domain adaptation
AtlasTrained jointly, few-shot orientedQuestion answering with few examples
RETRO and neighboring retrieval architectures

The original paper also introduced RETROfitting: adding and training only the retrieval layers on top of an existing frozen transformer. This retrofit recovered much of the benefit at a small fraction of full training cost, which suggested that retrieval can be bolted onto pretrained models rather than requiring training from scratch.

Strengths and practical use

RETRO’s central argument is that memorization can be outsourced to a database. This brings several practical benefits that matter when choosing an architecture.

  • Parameter efficiency: smaller decoders reach the quality of much larger dense models.
  • Updatable knowledge: the database can be edited or extended without retraining, at least in principle.
  • Inspectability: retrieved neighbors show which text influenced a prediction, aiding attribution.
  • Scaling with data: quality keeps improving as the database grows into the trillions of tokens.

In practice, RETRO-style models suit settings with a large, relatively stable corpus and heavy inference volume, where a smaller decoder saves compute. For rapidly changing enterprise documents, prompt-level RAG is usually simpler because it works with any off-the-shelf model.

Limitations and open questions

Part of RETRO’s reported gain came from overlap between evaluation data and the retrieval database, a form of test leakage that the authors measured and discussed openly. When overlap was filtered out, the improvement shrank but did not disappear, so the true benefit depends on how related the database is to the task.

LimitationCauseConsequence
Test set leakageEvaluation text present in databaseOverstated perplexity gains
Infrastructure costTrillion-token index in memoryComplex serving and storage
Frozen retrieverEmbeddings never adapt to the taskImperfect neighbor relevance
Fixed chunk boundaries64-token segmentationRetrieval may split related ideas
Limited downstream adoptionInstruction-tuned RAG proved simplerFew production deployments
Known limitations and their consequences

Follow-up studies found that RETRO’s advantage on question answering was smaller than on perplexity, and that the model sometimes copied retrieved text rather than reasoning over it. These findings keep the balance between parametric and retrieved knowledge an active research topic.

The idea in brief

RETRO is a language model that looks things up while it writes. Most models must store everything they know inside their own settings. RETRO keeps a huge library of text on the side. As it writes each short piece, it fetches a few similar passages from that library and reads them.

This works like an open-book exam. A student with good notes does not need to memorize every fact. A smaller model with a large library can do as well as a much larger model that memorized everything.

A practical scenario

A research group builds a language model for scientific literature search across tens of millions of papers. A dense model large enough to memorize the field would be too expensive to serve. The group trains a 1.5-billion-parameter RETRO-style decoder and indexes about 200 billion tokens of abstracts and full texts with frozen embeddings.

When a researcher drafts a summary of protein folding methods, each 64-token chunk retrieves two closely related passages, and chunked cross-attention lets the decoder ground its wording in them. The team carefully removes evaluation papers from the database, since leakage would otherwise inflate their results.

The outcome is a model with noticeably lower perplexity on new papers than a dense baseline of similar size, and the index can be refreshed monthly as new articles appear without any retraining.