10M Token Context: Breaking the Sparse Attention Indexing Bottleneck

    As context windows scale from millions to tens of millions of tokens, sparse attention shifts the bottleneck from attention computation to index selection. This article explains why naive indexers degrade to O(T²) cost, how latent-space sparse attention decouples indexing from attention to achieve sub-quadratic scaling, why accuracy is preserved, and what engineering practices matter for deployment.

    Introduction: How Scaling Context Reshapes the Cost Structure

    Over the past two years, long context has moved from an experimental feature to a default specification. Million-token context is becoming a standard configuration for many model services, and architectures that mix sparse attention with linear attention are being adopted by more models. These approaches share the same premise: instead of having every query scan the entire token history, each query attends to only a small set of the most relevant tokens.

    This premise has been validated repeatedly at the million-token scale. But as context extends to 10 million tokens, an initially negligible overhead starts to spiral out of control. In a global attention layer at this scale, roughly 98% of prefill time is spent not on attention computation itself, but on the indexing step that decides which tokens to look at.

    The nature of the problem has changed. Sparse attention has already shown that attending to a small subset is enough to preserve accuracy. What blocks ultra-long context is that the cost of finding that subset still grows quadratically with context length.

    1. The Hidden Cost of Sparse Attention

    In standard full attention, every query computes relevance against all previous keys. With context length T, prefill cost is O(T²), and decoding each token costs O(T). Moving from one million to 10 million tokens increases prefill attention computation by roughly 100x.

    Sparse attention divides the work: a lightweight indexer first selects the k most relevant keys for each query, and the actual attention is computed only over those k keys, reducing attention itself to O(Tk).

    This works under one condition: the model genuinely needs only a few keys. Related evaluations show that at 128k tokens, letting each query attend to only its 512 most relevant keys (about 0.8% of all keys) still preserves roughly 98% of full-attention accuracy on long-context benchmarks.

    But this creates a paradox: to know which 512 keys are most relevant, the indexer must first score every key. Common industry approaches include lowering scoring precision, compressing dimensions, or aggregating multiple keys into one, but these only shrink the constant factor. They cannot change the fact that the number of scoring operations grows with T. The indexer therefore degrades to O(T²) and becomes the new dominant cost.

    A schematic cost comparison:

    1. Full attention: O(T^2)
    2. Sparse attention (ideal): O(T*k) + indexing cost
    3. Naive indexer: indexing cost ≈ O(T^2) → dominant term
    4. Latent-space indexing: indexing cost ≈ O(T*d) → d is a fixed latent dimension

    2. The Core Idea of Latent-Space Sparse Attention

    Recently proposed by a startup research team in London and a university in Zurich, latent-space sparse attention moves the lookup from the original token space into a latent space.

    The idea comes down to three points:

    1. Keys and queries are mapped into low-dimensional latent representations, and relevance scoring happens in that latent space with a fixed dimension independent of context length.
    2. Indexing and attention are decoupled: the indexer only produces a candidate set, while the actual attention is still computed exactly over the original representations.
    3. The candidate set size k stays constant, reducing overall complexity from quadratic to near-linear and enabling sub-quadratic attention for ultra-long context.

    Unlike the “compress keys, then score” route, the latent-space approach does not shrink each key. It decouples the scoring process from sequence length. This explains why a single attention layer can achieve tens of times faster prefill at 10 million tokens: what is saved is not attention, but indexing.

    This class of methods is a general technical direction. Its gains depend on the specific model architecture, latent dimension, and candidate set size, so parameters should be determined empirically rather than copied from any single implementation.

    3. Why Accuracy Holds Up

    The biggest concern with sparse approaches is accuracy loss. Its controllability can be understood on three levels:

    • Redundancy: in long context, the keys actually relied upon are highly concentrated, and the large tail of tokens contributes very little to the current query.
    • Recall first: the indexer only needs to guarantee high recall by including the truly relevant keys in the candidate set; ranking precision is left to the subsequent attention.
    • Error isolation: indexing errors do not enter the numerical computation path and only affect the candidate set, preventing approximate scoring from contaminating attention outputs.

    In practice, it is advisable to keep a fallback switch: when indexing confidence is low or candidate hit rates are abnormal, fall back to a larger candidate set or local full attention in exchange for stability.

    4. Engineering Implementation

    1. Layered configuration: enable latent-space indexing only for global attention layers, and leave local and linear layers unchanged for the best benefit-to-risk ratio.
    2. Memory and bandwidth: index state must stay resident, so coordinate it with the KV cache and chunked prefill strategy to avoid extra read/write amplification.
    3. Numerical stability: use lower precision for latent-space scoring storage and higher precision for accumulation to prevent accumulation errors over long sequences.
    4. Observability: monitor three metrics: indexing time share, candidate hit rate, and fallback trigger rate, to locate where the bottleneck shifts.
    5. Progressive rollout: validate accuracy on an offline evaluation set first, then launch to a small traffic share, and finally open it to all traffic.

    5. Evaluation and Conclusion

    Evaluation should cover three dimensions: single-layer and end-to-end latency, long-context accuracy (such as retrieval, aggregation, and multi-hop reasoning tasks), and scaling curves across different context lengths. Pay particular attention to whether the speedup grows with length, which is the key evidence for a sub-quadratic approach.

    The conclusion is clear: the next stage of competition in ultra-long context is not about how much you look at, but how fast you find what to look at. Moving indexing from the original token space to a fixed-dimensional latent space is one of the most engineering-valuable directions today. The practical advice for developers is to first quantify the indexing share, then decide whether to introduce latent-space indexing, and use accuracy guardrail metrics to constrain the rollout pace.