AI Topics

What are Recursive Language Models (RLMs)?

Generative AI and LLMs 3 min read Written by the Ailoitte engineering team
On this page
  1. Definition
  2. How it works
  3. Examples
  4. Related terms
  5. Common questions
Definition

Recursive language models (RLMs) are a way of running a large language model so that it can handle inputs far longer than its context window. The long input is stored outside the model in a code environment, and the model writes code to inspect it, split it and call itself on the pieces.

The term covers a wide range of set-ups, from a single model that calls itself once on each part of a document to deeper chains in which each call can start calls of its own. What they share is that the model manages its own context instead of reading everything in one pass, which is why a recursive language model is an inference method and not a new kind of model.

Recursive language models matter because the accuracy of a language model tends to fall as its input grows, a problem often called context rot. In the paper that introduced the method, researchers at MIT CSAIL reported that it handled inputs up to two orders of magnitude beyond a model’s context window at a comparable cost per query.

How do recursive language models work?

  1. Store the input outside the modelThe full input is saved as a variable in a code environment, usually a Python session. The model receives only the question, so its context window stays almost empty.
  2. Inspect and filter with codeThe model writes short pieces of code to look at the input, for example printing the first lines or searching for a keyword. This shows how the input is structured and which parts matter for the question.
  3. Call itself on the piecesThe model splits the relevant parts into chunks that fit its context window and sends each one to a new call of itself or of another model. Each call returns a partial result, such as a summary or an extracted fact.
  4. Combine and answerThe first model gathers the partial results, checks them against each other and writes the final answer. To the user, the whole process looks like one ordinary call to a language model.

What are examples of recursive language models?

  • LEGALQuestions across a contract archiveA legal team asks which of several thousand contracts contain a change-of-control clause. The model searches the archive with code, reads only the matching sections in separate calls and returns one list.
  • FINANCEYears of filings in one answerAn analyst asks how a company's stated risks changed across 10 years of annual reports. Each report is summarised in its own call, and the first model compares the summaries to describe the change.
  • ENGINEERINGA codebase too large to read at onceA developer asks where a large codebase handles user permissions. The model lists the files, opens only the relevant ones in separate calls and explains how the pieces fit together.

Common questions about recursive language models

How are recursive language models different from RAG?

Recursive language models let the model decide what to read, while retrieval-augmented generation (RAG) uses a separate retriever to pick passages before the model answers. With RAG the model usually answers in one pass from those passages. With an RLM the model explores the input in several steps, which helps when the answer depends on many parts of it.

What are the limits of recursive language models?

Recursive language models are slower than a single call, because one question can trigger many calls that run one after another. Total cost and running time are hard to predict in advance. The model also runs code it has written, so the code environment must be isolated from other systems. Deeper recursion does not always improve accuracy.

Clutch Image
GoodFirms Image
Designrush Image
Reviews Image
Glassdoor Image