arXiv:2610.10135cs.DSOct 2026

Manuscript Offprint

arXiv:2610.10135

Attention via Black-Box Vector Search

Stepan Zharkov, Krish Singal, Ashwin Padaki, Alexandr Andoni

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Sparse attention mechanisms estimate attention over n tokens using a small subset of keys. Many existing approaches use maximum inner product search (MIPS) to retrieve the heaviest keys, which motivates the following question: given black-box access to a MIPS oracle, how many keys must be retrieved to output an ε\varepsilon-accurate attention estimate?

We answer this question by unifying prior approaches through the framework of priority sampling. With a single MIPS index, we show that Θ(n/ε)\Theta(\sqrt{n}/\varepsilon) retrieved keys are both sufficient and necessary. With Θ(log⁡n)\Theta(\log n) indices, we give an algorithm that retrieves only O(log⁡n+1/ε2)O(\log n + 1/\varepsilon^2) keys and prove that this is near-optimal. More generally, we design algorithms that establish a smooth tradeoff between the number of MIPS indices and number of retrieved keys. We then show that if we allow augmentation of keys and queries, we can bypass the above lower bounds: there exists a simple priority-sampling estimator using a single MIPS index and O(1/ε2)O(1/\varepsilon^2) retrieved keys. When integrated into LLM inference, our algorithms outperform top-k and sampling approaches used in prior work and yield attention approximation that scales favorably to long contexts.

1 INTRODUCTION

Transformer-based large language models (LLMs) increasingly rely on long context windows to process documents, codebases, and extended reasoning traces. A major bottleneck to scaling these context windows is the attention mechanism (Vaswani et al., 2017). Given an existing context of nn tokens, computing attention for each new token requires comparing it against all preceding tokens. Formally, given key vectors x1,…,xn∈Rdx_1, \ldots, x_n \in \mathbb{R}^d, value vectors v1,…,vn∈RDv_1, \ldots, v_n \in \mathbb{R}^D, and a query vector q∈Rdq \in \mathbb{R}^d, the attention mechanism computes

Attn(q):=∑i=1nκ(q,xi)∑j=1nκ(q,xj)⋅vi,\mathrm{Attn}(q):=\sum_{i=1}^{n}\frac{\kappa(q,x_{i})}{\sum_{j=1}^{n}\kappa(q,x_{j})}\cdot v_{i},

where κ(q,x)=exp⁡(⟨q,x⟩)\kappa(q, x) = \exp(\langle q, x \rangle) is the softmax kernel. 1^{1}

Recent work circumvents the cost of computing the attention mechanism using the approach of sparse attention (Kitaev et al., 2020; Zaheer et al., 2020). Rather than attending to every token, sparse attention mechanisms identify a small subset of tokens and use them to approximate the true attention vector. The attention weight of token i grows exponentially with ⟨q,xi⟩\langle q, x_i \rangle, suggesting a natural strategy: retrieve the keys that have the largest inner product with the query. This is precisely a maximum inner product search (MIPS) problem, a well-studied primitive in vector search (Shrivastava & Li, 2014; Neyshabur & Srebro, 2015). Indeed, a growing body of work builds sparse attention mechanisms with MIPS as the core subroutine, including RetrievalAttention (Liu et al., 2025), HashAttention (Desai et al., 2025), and vAttention (Desai et al., 2026).

A common feature of MIPS-based sparse attention mechanisms is that they generally treat the underlying MIPS algorithm as a black box: the estimator specifies which keys to retrieve and how to

∗^{*}Equal contribution, random order.

1^{1}More generally, κ(q,x)=exp⁡(⟨q,x⟩/τ)\kappa(q, x) = \exp(\langle q, x \rangle / \tau) for a temperature parameter τ>0\tau > 0.

utilize them, but is agnostic to how those keys are found. 2^{2} Using MIPS as a black box is attractive because vector search is already a highly optimized problem. Decades of algorithmic and engineering progress have produced extremely performant approximate nearest neighbor and MIPS algorithms, as documented in public benchmarks such as ANN-Benchmarks (Aumüller et al., 2020) and VIBE (Jääsaari et al., 2026). Any sparse attention method that is agnostic to the underlying search implementation can immediately benefit from state-of-the-art algorithms and future improvements.

In this paper, we take a theoretical perspective on MIPS-based sparse attention. We assume access to a perfect MIPS oracle and study the retrieval strategy: the algorithm deciding which keys to retrieve and how to use the retrieved keys to estimate attention. We begin with the following question: