In Search of Needles in a 11M Haystack: Recurrent Memory Finds What LLMs Miss

Yuri Kuratov, Aydar Bulatov, Petr Anokhin, Dmitry Sorokin, Artyom Y. Sorokin, Mikhail BurtsevarXiv 2024 · DOI

Introduction

Large Language Models (LLMs) are increasingly marketed based on the size of their context windows, with industry leaders like GPT-4 Turbo boasting capacities up to 128,000 tokens. However, a model's theoretical capacity often diverges from its practical utility. Standard Transformer architectures suffer from a "quadratic bottleneck," where computational costs grow with the square of the input length. Furthermore, models frequently exhibit the "lost in the middle" phenomenon, failing to retrieve or reason with facts buried deep within long documents.

To address these limitations, researchers have introduced BABILong, a benchmark designed to test reasoning across millions of tokens, and demonstrated that a Recurrent Memory Transformer (RMT) can successfully process a record-breaking 11 million tokens—far exceeding the capabilities of current frontier models.

The BABILong Benchmark

Existing long-context benchmarks typically cap at approximately 40,000 tokens, which fails to represent the complexity of processing entire libraries or massive codebases. BABILong is designed to be algorithmically scalable and "leak-proof."

The BABILong benchmark hides simple reasoning facts (needles) within massive amounts of background text (haystack) from the PG19 corpus.

As shown in the figure above, the benchmark constructs tasks by taking facts from the classic bAbI dataset (e.g., "Mary moved to the office") and distributing them randomly within background text from PG19 (Project Gutenberg books). This allows for the creation of "haystacks" ranging from a few thousand to over 11 million tokens, testing whether a model can maintain a coherent chain of reasoning despite massive amounts of irrelevant noise.

Methodology: Recurrent Memory Transformer (RMT)

The proposed solution utilizes the Recurrent Memory Transformer (RMT) architecture. Unlike standard Transformers that attempt to attend to the entire context at once, RMT processes input in segments. It maintains a fixed-size "memory state"—represented as special tokens—that is passed sequentially from one segment to the next.

Key technical advantages include:

  • Linear Scaling: By processing segments sequentially and using a fixed-size memory, RMT’s computational complexity scales linearly with input size, avoiding the quadratic explosion of standard self-attention.
  • Self-Retrieval (RMT-R): To prevent the memory state from becoming a bottleneck, the authors implemented a mechanism allowing the model to look back at all previous memory states, facilitating better multi-hop reasoning.
  • Efficiency: Remarkably, the researchers used a relatively small GPT-2 (137M parameters) backbone. Despite its size, the recurrent mechanism allowed it to outperform models with orders of magnitude more parameters on long-context tasks.

Key Results and Performance

The evaluation revealed a stark contrast between advertised context windows and effective reasoning capabilities. While GPT-4 performs well on short contexts (4,000 tokens), its accuracy drops precipitously as the haystack grows.

Performance comparison across different context lengths shows RMT maintaining high accuracy at 11 million tokens while GPT-4 and RAG-based systems struggle.

As illustrated in the performance summary, RMT successfully handled 11,111,111 tokens, setting a new record for the longest input processed by a single neural network. On the qa1 task (single fact retrieval), RMT maintained ~90% accuracy at 1 million tokens. In contrast, GPT-4 Turbo’s performance plummeted toward zero when facts were hidden within its full 128k window.

Furthermore, the study highlighted that Retrieval-Augmented Generation (RAG) is not a universal fix. RAG systems often fail on tasks requiring temporal reasoning because they retrieve chunks based on semantic similarity but ignore the chronological order of events (e.g., tracking Mary’s latest location across multiple moves).

Discussion and Limitations

While RMT demonstrates superior scaling, it introduces a sequential bottleneck during inference; segments must be processed in order to pass the memory state, limiting the parallelization possible in standard Transformers. Additionally, the fixed-size memory state remains a potential bottleneck for tasks requiring the simultaneous storage of thousands of unrelated facts.

Future work aims to apply this recurrent memory approach to larger base models, such as Llama or Mistral, to determine if the combination of high-parameter reasoning and recurrent memory can further push the boundaries of long-context AI.

Summary updated

BibTeX
@misc{kuratov2024search,
  author = {Yuri Kuratov and Aydar Bulatov and Petr Anokhin and Dmitry Sorokin and Artyom Y. Sorokin and Mikhail Burtsev},
  title = {{In Search of Needles in a 11M Haystack: Recurrent Memory Finds What LLMs Miss}},
  year = {2024},
  eprint = {2402.10790},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.10790},
}
Figure