TL;DR
What if we threw away vector databases and just stuffed an entire library into a language model's prompt, asking it to find the right document directly? The authors test this "in-context retrieval" dream at a million-token scale and find that models eventually drown in distractors—not because they forget how to spot the right answer, but because softmax normalization mathematically washes out the signal. By introducing simple, length-aware attention tweaks, they rescue the model from near-zero accuracy, matching—and sometimes beating—traditional vector search.
What Problem Does This Paper Address?
Modern Retrieval-Augmented Generation (RAG) is a two-step dance: a vector-based "dense retriever" compresses documents into fixed embeddings to find candidates, and a language model (LM) reads them to generate an answer. In-Context Retrieval (ICR) proposes collapsing this into a single step: feed the whole corpus into a long-context LM and let it directly output the ID of the relevant document.
Until now, ICR was mostly tested on proprietary black-box models, small candidate pools (reranking), or synthetic "needle-in-a-haystack" tests. A real-world retriever faces two brutal hurdles: scaling to millions of tokens, and generalizing to corpus sizes far larger than what it saw during training. Can an LM actually pull this off without collapsing?
Methods
The authors first build BLOCKSEARCH (based on Qwen3-0.6B), upgrading standard ICR recipes with:
- Block-sparse attention: Documents attend only to themselves (allowing parallel pre-computation and caching), while the query attends to everything.
- Randomized 4-digit IDs: Instead of numbering documents sequentially (1, 2, 3...), which causes overfitting to training lengths, each document gets a random code (
0000–9999). - On-policy auxiliary loss: Standard training teaches the model to predict the next digit assuming previous digits were right. To fix "exposure bias" when the model makes a mistake at test time, it practices recovering from its own rolled-out digit prefixes.
When BLOCKSEARCH still collapses near a million tokens, the authors add two targeted fixes for attention dispersion:
- Length-Aware Softmax (SSMax): Multiplies pre-softmax attention scores by $s \cdot \log N$ (where $N$ is corpus size), sharpening peaks so the winning document isn't drowned out as the corpus grows. (They also test an additive attention sink, which proves largely ineffective).
- Document-Level Routing: Uses the model's own intermediate attention scores at Layer 16 to shortlist the top 256 documents, pruning the rest from later layers.
Datasets
- Training: A ~100M-token subset of the ReLabeled Hard Negatives (RLHN) version of BEIR (including MS MARCO), using LLM-pruned positives and 15 hard negatives per query (256 documents per training batch).
- Evaluation: Tested on MS MARCO, HotpotQA, and Natural Questions (NQ), scaling from 500 up to 10,000 documents (~1M tokens) packed with challenging hard negatives.
- Out-of-Distribution (OOD): LIMIT, a biography benchmark relying on lexical similarity where fixed dense embeddings notoriously struggle, scaled up to 10,000 documents (~1.7M tokens).
Key Insights and Ideas
- The Two-Stage Brain of ICR: Probing the 28-layer model reveals distinct functional zones: Layers 11–20 act as a "retrieval band" accumulating document relevance, followed by a sharp transition at Layers 18–19 into a "decode band" where the model commits to the first digit of the document ID.
- Heads Know More Than the Model Says: As the corpus scales to thousands of documents, individual attention heads still rank the gold document #1 far more often than the model manages to output its ID.
- The Residual Stream Swap (Attention Dilution): Why does decoding fail if heads find the right document? Because downstream layers don't read rankings; they read softmax-weighted value vectors. As $N$ grows from 500 to 10,000, thousands of irrelevant documents inflate the softmax denominator. At Layer 19, the total output vector magnitude stays roughly the same, but the gold document's share of that vector plummets from 91% to 1%. The signal is quietly replaced by an average of distractors.
- Synthetic Benchmarks Lie: Concurrent long-context models (like the 7$\times$ larger MSA-4B) ace synthetic needle-in-a-haystack tests yet degrade sharply on realistic retrieval corpora packed with hard negatives.
Key Results
- Extrapolation & Collapse: Base BLOCKSEARCH matches a same-backbone dense retriever (
Qwen3-dense) on small corpora (95.8% vs. 95.5% Recall@1 on MS MARCO at ~45k tokens) and generalizes up to 10$\times$ its training length (~500k tokens), but crashes to 0.2% at 10,000 documents (~1M tokens).
- Rescuing Million-Token Retrieval: Adding SSMax and document routing rockets 1M-token MS MARCO Recall@1 from 0.2% to 20.5%, essentially matching the dense retriever gold standard (20.2%). On HotpotQA at $N$=10k, routing hits 78.5% (vs. 79.5% dense).
- Crushing Dense Retrieval OOD: On the lexical LIMIT benchmark at 10,000 documents (~1.7M tokens),
BLOCKSEARCH-SSMax+routingachieves 13.5% Recall@1, outperformingQwen3-dense(2.9%) by more than 4.5$\times$.
Limitations and Future Work
The authors are candid about practical bottlenecks: storing a corpus as an LM key-value (KV) cache consumes roughly three orders of magnitude (1,000$\times$) more memory than a compact vector index. Furthermore, fine-tuning exclusively for retrieval degrades the LM's general reasoning capabilities, and results were evaluated on sub-1B backbones using a single query sample per corpus size. Even with SSMax and routing, performance on LIMIT still trends downward at extreme lengths—meaning attention dilution is mitigated, not cured, leaving attention control at massive scale wide open for future architectures.
Summary updated