Retrievit: In-context Retrieval Capabilities of Transformers, State Space Models, and Hybrid Architectures

TL;DR

Retrievit combines Transformers and SSMs for efficient in-context retrieval, enhancing data efficiency.

cs.AI 🔴 Advanced 2026-03-03 34 views
Georgios Pantazopoulos Malvina Nikandrou Ioannis Konstas Alessandro Suglia
Transformer SSM Hybrid Architecture In-context Retrieval Machine Learning

Key Findings

Methodology

The study employs a hybrid architecture combining Transformers and SSMs to evaluate performance on n-gram and position retrieval tasks. Under controlled experimental conditions, data efficiency, length generalization, and robustness to out-of-domain training samples were analyzed. Mamba and Mamba2 were used as baseline SSM models, with Transformer blocks inserted to enhance SSM retrieval capabilities.

Key Results

  • Hybrid models outperform SSMs in n-gram retrieval tasks, improving data efficiency by an order of magnitude, achieving over 95% accuracy.
  • In position retrieval tasks, Transformers still perform best, but hybrid models approach Transformers in data efficiency and generalization.
  • SSM models form interpretable structures via locality-aware embeddings, whereas Transformers acquire positional associations through causal attention.

Significance

The study reveals fundamental differences in how Transformers and SSMs learn positional associations. The proposed hybrid architecture outperforms existing models in data efficiency and generalization, offering significant academic and industrial applications.

Technical Contribution

The hybrid architecture combines global attention of Transformers with the recursive update mechanism of SSMs without increasing computational complexity, offering new engineering possibilities.

Novelty

This is the first to combine Transformers and SSMs for in-context retrieval tasks, significantly improving data efficiency and generalization.

Limitations

  • Hybrid models still underperform pure Transformers in position retrieval tasks.
  • SSMs exhibit positional bias with duplicate queries in input sequences.

Future Work

Future research could explore validating the hybrid architecture on more complex real-world datasets and optimizing its performance in position retrieval tasks.

AI Executive Summary

In the field of machine learning, Transformers are widely acclaimed for their powerful in-context retrieval capabilities, but their complexity scales quadratically with sequence length, limiting their application in long sequences. In contrast, State Space Models (SSMs) are known for their linear-time processing efficiency but have limited retrieval capabilities.

This study proposes a hybrid architecture that combines Transformers with SSMs to achieve the best of both worlds. Through experiments on two synthetic in-context retrieval tasks, the hybrid model demonstrates superior data efficiency and generalization capabilities, particularly in n-gram retrieval tasks, where it significantly outperforms SSMs and, in some cases, exceeds Transformers.

However, in position retrieval tasks, Transformers still maintain a lead. The study finds that SSMs develop locality-aware embeddings forming interpretable structures, while Transformers acquire positional associations through causal attention. This discovery reveals fundamental differences in how these models learn positional associations, providing new directions for future research.

Deep Analysis

Background

Transformers have excelled in fields like NLP, but their complexity limits long-sequence processing. SSMs offer linear-time processing advantages but have limited retrieval capabilities. The hybrid architecture aims to combine the strengths of both.

Core Problem

Existing models face a trade-off between efficiency and capability when processing long sequences, especially in in-context retrieval tasks. How to improve retrieval capabilities without increasing computational complexity is a key issue.

Innovation

The hybrid architecture enhances SSM retrieval capabilities by inserting Transformer blocks, leveraging the global attention of Transformers and the recursive update mechanism of SSMs to improve data efficiency and generalization.

Methodology

  • �� Use Mamba and Mamba2 as baseline SSM models.
  • �� Insert Transformer blocks into SSM to enhance retrieval capabilities.
  • �� Evaluate performance on n-gram and position retrieval tasks.

Experiments

Experiments use synthetic datasets to evaluate models on data efficiency, length generalization, and robustness to out-of-domain training samples. The impact of inserting different numbers of Transformer blocks on model performance is analyzed.

Results

Hybrid models outperform SSMs in n-gram retrieval tasks, improving data efficiency by an order of magnitude. In position retrieval tasks, Transformers still perform best, but hybrid models approach Transformers in data efficiency and generalization.

Applications

The hybrid architecture can be applied in scenarios requiring efficient in-context retrieval, such as NLP and information retrieval.

Limitations & Outlook

Hybrid models still underperform pure Transformers in position retrieval tasks and exhibit positional bias with duplicate queries in input sequences.

Plain Language Accessible to non-experts

Imagine a library where a Transformer is like a librarian who can quickly find books but needs a large space to store the catalog. An SSM is like a staff member with a great memory who can quickly remember where books are but sometimes forgets the exact titles. The hybrid architecture is like a combination of both, having the ability to quickly find books while efficiently using space. This way, the hybrid architecture excels in handling a large number of books, especially when needing to quickly find specific ones.

ELI14 Explained like you're 14

Imagine you're playing a treasure hunt game. A Transformer is like a pro who can quickly find clues but needs a big map to mark each clue. An SSM is like a player with a great memory who can quickly remember where clues are but sometimes forgets the exact clue content. The hybrid architecture is like a combination of both, able to quickly find clues while efficiently using map space. This way, the hybrid architecture excels in handling a large number of clues, especially when needing to quickly find specific ones!

Glossary

Transformer

A neural network architecture for sequence modeling, known for its powerful in-context retrieval capabilities.

Used in this paper to evaluate in-context retrieval capabilities.

State Space Model (SSM)

A model known for linear-time processing, suitable for long-sequence processing.

Used as a baseline model combined with Transformers.

Hybrid Architecture

An architecture combining Transformers and SSMs to achieve the best of both worlds.

The main focus of this study.

N-gram Retrieval

A task requiring the model to retrieve k tokens following a specific n-gram in the input sequence.

Used to evaluate the model's in-context retrieval capability.

Position Retrieval

A task requiring the model to find the position of a query token in the input sequence.

Used to evaluate the model's two-hop association capability.

Open Questions Unanswered questions from this research

  • 1 How to validate the hybrid architecture on real-world datasets.
  • 2 Optimizing hybrid architecture performance in position retrieval tasks.

Applications

Immediate Applications

Natural Language Processing

The hybrid architecture can be used to enhance in-context retrieval efficiency in NLP tasks.

Long-term Vision

Information Retrieval Systems

The hybrid architecture can be used to build more efficient information retrieval systems, improving user experience.

Abstract

Transformers excel at in-context retrieval but suffer from quadratic complexity with sequence length, while State Space Models (SSMs) offer efficient linear-time processing but have limited retrieval capabilities. We investigate whether hybrid architectures combining Transformers and SSMs can achieve the best of both worlds on two synthetic in-context retrieval tasks. The first task, n-gram retrieval, requires the model to reproduce an n-gram that succeeds the query within the input sequence. The second task, position retrieval, presents the model with a query token and requires it to perform a two-hop lookup: first locating the corresponding element in the sequence, and then outputting its positional index. Under controlled conditions, we assess data efficiency, length generalization, robustness to out of domain training examples, and learned representations across Transformers, SSMs, and hybrid architectures. We find that hybrid models outperform SSMs and match or exceed Transformers in terms of data efficiency and extrapolation for tasks that require precise information retrieval from the input context. However, Transformers maintain superiority in position retrieval tasks. Through representation analysis, we discover that SSM-based models develop locality-aware embeddings where tokens representing adjacent positions become neighbors in embedding space, forming interpretable structures. This property is absent in Transformers as causal attention is sufficient for acquiring positional associations, and the introduction of positional encoding amplifies this behavior, leading to improvement in data efficiency. SSMs on the other hand update their internal representations incrementally and without positional encodings, are required to learn these associations. Our findings reveal fundamental differences in how Transformers and SSMs, and hybrid models learn positional associations.

cs.AI