Ten-Million-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 breaks down the quadratic cost of scoring every key, introduces Latent Sparse Attention—which performs relevance scoring in a lower-dimensional latent space—and outlines engineering practices such as layered indexing, chunked caching, and precision regression for production long-context systems.

    Introduction: The Long-Context Race Enters the Ten-Million-Token Era

    Long-context capability has evolved from a differentiating feature into a baseline configuration for large model platforms. Mainstream solutions in the industry commonly treat million-token context as the default service specification, and architecturally they widely adopt a hybrid design that mixes sparse attention with linear attention. The core goal is singular: to avoid having every query vector traverse all historical tokens, and instead let it selectively attend to a small set of the most relevant content.

    This strategy has been repeatedly validated at the million-token scale. But as context length pushes further into the tens of millions, an originally unremarkable overhead begins to balloon rapidly and dominate overall latency. Take one global attention layer in a certain class of hybrid architecture models: when running the prefill phase at ten-million-token scale, roughly 98% of the time is spent not on the matrix operations of attention itself, but on the indexing step that “decides which tokens to attend to.”

    The nature of the problem has therefore changed. Sparse attention has long proven that “looking at only a small portion” is enough to preserve accuracy. What truly constrains the deployment of ultra-long context is that the process of “finding that small portion” still grows quadratically with context length.

    1. Cost Structure Review: Why Sparse Attention Is Still Not “Cheap”

    The Baseline Cost of Full Attention

    In standard full attention, every query computes relevance against all preceding keys. Let the context length be T. The prefill computation complexity is O(T²), and the complexity of decoding each token is O(T). When the context expands from one million to ten million tokens, the prefill computation for the attention portion alone grows by roughly 100x.

    The Division of Labor in Sparse Attention

    The essence of the sparse approach is a division of labor: a lightweight indexer first selects the k most relevant keys for each query, and then the actual attention computes only over those k keys, compressing the main attention overhead to O(Tk).

    This approach rests on one key premise—that the model genuinely needs only a very small number of keys. Relevant validation shows that at 128k tokens, letting each query attend only to its 512 truly most relevant keys (about 0.8% of all keys) still allows the model to retain roughly 98% of full-attention accuracy on long-context benchmarks. This indicates that “looking at less” is not a compromise, but is sufficient.

    The Overlooked “Hidden Bill”

    The paradox is this: for the indexer to determine which 512 keys are most relevant, it must first score every single key. Whether the scoring is dot-product based, compression based, or hierarchical filtering, as long as the scoring action requires pairwise interaction between the query and all historical keys, the indexing stage remains O(T²). The longer the context, the heavier this bill becomes, until it eventually overtakes the main attention computation and becomes the true bottleneck.

    2. Latent Sparse Attention: Moving the “Search” into a Lower-Dimensional Space

    A recent study targeting sub-quadratic attention for ultra-long context proposes a scheme called Latent Sparse Attention. Its core is not to keep optimizing the scoring function, but to change the space in which scoring happens.

    Low-Dimensional Projection Replaces Scoring in the Original Space

    The method projects queries and keys separately into a latent space that is far smaller than the head dimension, performs relevance scoring and Top-k selection in that low-dimensional latent space, and then maps the selected indices back to the original space to execute attention. Because the scoring dimension drops from d to d’ (with d’ far smaller than d), the complexity of the indexing stage falls from O(T²·d) to approximately O(T²·d’). Combined with chunking and approximate retrieval, the overall cost can approach sub-quadratic.

    Illustrative pseudocode:

    1. # Original-space scoring: cost scales linearly with dimension d
    2. # scores = q @ k.T # [T, T], each element costs O(d)
    3. # Latent-space scoring: project first, then low-dimensional inner product
    4. q_lat = proj_q(q) # [T, d']
    5. k_lat = proj_k(k) # [T, d']
    6. scores = q_lat @ k_lat.T # [T, T], each element costs O(d')
    7. idx = topk(scores, k) # take k indices per query
    8. # use idx to perform sparse attention in the original space

    Training and Alignment

    The latent-space projection needs to be jointly trained with the main model or lightly aligned, so that the ranking produced by low-dimensional scoring stays consistent with the true relevance in the original space. In engineering practice, a small number of original-space calibration samples are usually retained to prevent projection drift from causing the wrong keys to be selected.

    Complexity Gains

    At ten-million-token scale, this scheme significantly accelerates the prefill of a single global attention layer. Measured speedups across different model sizes range from just over twentyfold to more than seventyfold, while maintaining accuracy close to the original model across a range of long-context tasks. The key gain is not making attention compute faster, but preventing the hidden bill of “indexing” from spiraling out of control with length.

    3. Engineering Implementation Essentials

    1. Layered indexing: Use latent-space coarse screening for global layers and keep exact scoring for local layers, balancing accuracy and speed.
    2. Chunking and caching: Chunk and pre-project the keys and cache the latent vectors to avoid repeated projection during prefill.
    3. Top-k stability: Monitor the overlap rate of selected keys; an overly low overlap rate signals projection drift and the need for recalibration.
    4. Coordination with linear attention: In a hybrid architecture, let linear layers carry coarse global information, let sparse layers handle precise details, and have the latent-space index serve only the sparse layers.
    5. Accuracy regression: Before launch, run a full-attention comparison regression on long-context benchmarks to ensure the retention rate meets the target.

    4. Conclusion

    The real enemy of ten-million-token context is not attention computation, but the quadratic growth of indexing. By moving “finding relevant keys” into a cheaper space through low-dimensional projection, Latent Sparse Attention drives overall complexity toward sub-quadratic, delivering order-of-magnitude prefill speedups while preserving accuracy. For teams building ultra-long-context capabilities, this offers a reusable, general technical path: first quantify the indexing bill, then reshape the scoring space, and finally use layering and caching to bring the gains into production.