Breaking the Index Bottleneck of Sparse Attention at 10M Tokens

    As context windows scale to tens of millions of tokens, sparse attention helps reduce the cost of attention computation itself, but the indexing stage—finding which tokens matter—emerges as the new bottleneck. This article examines why conventional sparse attention still relies on near-full-length comparison during indexing, and explores how latent-space sparse attention (LSA) addresses the issue. By projecting queries and keys into a low-dimensional space, using block-level coarse filtering, and applying candidate refinement in the original space, LSA reduces the indexing cost from near-quadratic to near-linear or sub-quadratic complexity. The article also covers precision safeguards, engineering best practices, and practical selection criteria for applying LSA in 10M-token production scenarios.

    1. At 10M Tokens, the Bottleneck Shifts

    In the past year, million-token context windows have gradually evolved from a demonstration capability to a standard service specification. Sparse attention has become a common choice for ultra-long-context models. The underlying assumption is straightforward: each query does not need to attend to all historical tokens; it only needs to focus on a few most relevant ones. The system first uses a lightweight indexer to select candidate keys for each query, and then lets the actual attention computation happen only on the selected candidate set.

    At the million-token scale, this approach has been repeatedly validated: keeping only a small subset of key tokens still allows the model to maintain near-full-attention accuracy on long-context tasks. But as context windows move toward ten million tokens, a previously negligible overhead starts to spiral out of control—the indexer itself.

    At the 10M-token scale, in the prefill phase, the numeric computation of attention may account for only a small fraction of the total time. More time is spent on “deciding which tokens to look at.” Some analyses indicate that in single-layer global attention, the indexing and routing stage can consume the majority of prefill time. The nature of the problem has therefore changed: sparse attention has long proven that “looking at only a small subset” is sufficient to preserve accuracy. What truly throttles ultra-long context is that “finding that small subset” still scales quadratically with context length.

    2. Re-examining the Cost Structure: Attention Is Sparsified, Indexing Is Not

    The cost structure of standard full attention is well understood. Given context length T and hidden dimension d, during prefill, every query must compute relevance with all previous keys, yielding an overall complexity of O(T²d). During decoding, each generated token requires attention over historical keys, costing O(Td). When context grows from one million to ten million tokens, the attention computation in prefill should theoretically increase by 100x.

    Sparse attention improves this by splitting the work into two steps:

    1. An indexer selects the k most relevant keys for each query;
    2. Actual attention is computed only over these k keys.

    If k is much smaller than T, the attention cost itself can be reduced to O(Tkd). This step is effective. However, the indexer must still score a large number of keys to determine which ones are relevant. Even with optimizations such as low precision, low dimensionality, or block-level compression, as long as every query must compare against all keys or all blocks, the indexing stage retains a quadratic growth pattern. Block sparsity compresses four keys into one block, reducing the constant factor; low-dimensional projection lowers per-comparison cost; quantization reduces memory bandwidth pressure. But these optimizations are mostly “making the quadratic curve less steep”—they do not fundamentally change the trend of the indexing stage expanding rapidly with sequence length.

    This is the “hidden bill” of sparse attention: attention computation has been sparsified, but the indexing process has not been truly sparsified. The longer the context, the more the indexer resembles a new global bottleneck.

    3. Core Idea of Latent-Space Sparse Attention: Move Indexing to a Low-Dimensional Space with Multi-Stage Candidate Generation

    Recent research has proposed Latent Sparse Attention (LSA) to address this issue. The core idea can be summarized as follows: instead of traversing all keys in the original high-dimensional token space for every query, perform coarse-grained routing in a compressed latent space, then send a small set of candidate blocks back to the original space for precise attention.

    A typical design can be understood as three stages.

    3.1 Low-Dimensional Latent Projection

    Queries and keys are projected into a lower-dimensional latent space to obtain latent query representations and latent key representations. The low-dimensional representation is not meant to replace the final attention; it is for fast coarse filtering. Since the latent dimension r is much smaller than the original dimension d, each similarity comparison is cheaper and memory access is more friendly.

    3.2 Block-Level Coarse Filtering and Candidate Generation

    In the latent space, keys are organized into blocks or clusters. The model first computes coarse correlations between queries and block summaries, cluster centers, or low-dimensional key representations, and selects a small number of candidate blocks. The key point: the query does not need to compare against every token one-by-one with full precision. Instead, it first compares against coarser-grained candidate units, then performs fine-ranking within those candidate units. This transforms the indexing workload from full pairwise comparison into “coarse candidate filtering + small-set fine-ranking,” offering the theoretical possibility of sub-quadratic or even near-linear complexity.

    3.3 Fine-Grained Ranking in the Original Space and Sparse Attention

    Once candidate blocks are mapped back to the original key space, precise correlation scores are computed using the original queries and keys. Top-k keys are selected and standard attention is performed. The final output is still a weighted sum, and the model architecture does not need to be completely rewritten, making it easier to integrate with existing long-context models.

    A schematic pseudo-code example is shown below. It only illustrates the flow, not a production implementation:

    1. def latent_sparse_attention(Q, K, V, k, block_size):
    2. # Q/K/V: [T, d]
    3. Q_lat = project_q_lowrank(Q) # [T, r]
    4. K_lat = project_k_lowrank(K) # [T, r]
    5. # Block-level coarse filtering in latent space,
    6. # avoiding full per-token traversal for every query
    7. block_scores = blockwise_dot(Q_lat, K_lat, block_size)
    8. candidate_blocks = topk(block_scores, k_blocks)
    9. # Only refine candidate blocks in the original space
    10. key_idx = gather_blocks(candidate_blocks)
    11. scores = dot(Q, K[key_idx]) / sqrt(d)
    12. weights = softmax(scores)
    13. return weights @ V[key_idx]

    The engineering significance of this approach lies in the combination: low-dimensional projection reduces per-comparison cost, block-level candidates shrink the search range, and fine-grained ranking in the original space preserves final accuracy. Together, they make it possible to keep indexing overhead within acceptable limits at the 10M-token scale. Some reports indicate that, at 10M-token context, single-layer prefill can achieve speedups of 20x or more; the exact ratio varies depending on model architecture, block granularity, and hardware conditions.

    4. Precision Safeguards: Coarse Filtering Can Be Approximate, But Must Not Miss Critical Tokens

    Latent-space sparse attention is not free of costs. Low-dimensional coarse filtering may miss the truly most relevant keys. The coarser the block granularity, the higher the risk of missing relevant keys. Once the indexer selects the wrong candidates, subsequent attention cannot recover regardless of its precision. Therefore, precision guarantees must be addressed from both the training and inference sides.

    First, the indexer and attention should be jointly optimized. If the indexer is completely frozen and routing relies only on low-dimensional projection, it can become misaligned with the final attention distribution. During training, the indexing loss can be combined with the language modeling loss so that the latent-space representation preserves information useful for relevance selection.

    Second, the candidate set should have margin. The coarse filtering stage does not need to directly select the final k keys. Instead, it can select a larger set of candidate blocks, then perform fine-grained ranking within that set. This trades a modest amount of extra computation for better recall.

    Third, block granularity requires a trade-off. Larger blocks make indexing cheaper, but introduce more irrelevant tokens within each candidate block. Smaller blocks improve recall precision, but increase the number of blocks and raise the comparison count for the indexer. Real-world systems often use multi-level block structures: coarse-grained cluster routing first, then fine-grained block filtering.

    Fourth, indexing recall must be monitored. Offline evaluation can measure the overlap between the sparse selection result and the full-attention Top-k set, along with end-to-end accuracy on long-context tasks. Related validation shows that at the 100K-token scale, keeping less than one percent of key tokens per query can still approach full-attention accuracy. However, this does not mean the candidate set can be compressed indefinitely; recall must be validated against the target data distribution.

    5. Engineering Considerations: The Indexer Must Be Designed Together with Attention

    Ultra-long context is not purely an algorithmic problem. The engineering efficiency of the indexer determines whether theoretical complexity translates into real throughput.

    First, chunked prefill. Split long sequences into chunks, compute block-level latent representations and block summaries in advance, then perform coarse filtering in batches per query block. Batch block-level Top-k is more amenable to accelerator parallelism than per-token selection.

    Second, index caching and incremental updates. During decoding, every generated token requires indexing over history. If all block summaries are recomputed each time, cost accumulates rapidly. Maintaining block-level summary caches, where new tokens only update their own block and historical block summaries are reused, is essential.

    Third, kernel fusion and low-rank projection fusion. If latent projection, block-level similarity scoring, and Top-k selection are implemented as separate operators, memory read/write becomes the new bottleneck. Fusing the low-dimensional projection with block-level scoring to reduce intermediate tensor materialization is often more effective than simply reducing floating-point operations.

    Fourth, mixing with linear attention layers. A global sparse attention layer handles precise recall; linear attention layers handle low-cost long-range modeling. Alternating between the two reduces the number of global layers, thereby reducing the number of indexer invocations.

    Fifth, load balancing. Block-level candidates may concentrate on a few hot blocks, causing uneven utilization among parallel units. Block size, candidate allocation, and batch processing strategies need to be balanced.

    6. Application Scenarios and Selection Criteria

    This class of methods is suitable for general scenarios that require processing tens of millions of tokens, such as large-scale document library retrieval-augmented generation, repository-level code analysis, log auditing, and multi-turn agent memory. On platforms like Baidu AI Cloud, general-purpose categories such as object storage, log services, and container platforms can host the data and compute resources required for ultra-long context; specific implementation still needs to align with the business data distribution, latency requirements, and cost budget.

    When selecting a solution, the following questions should be checked:

    • Does the indexing stage still traverse all keys or all blocks for every query?
    • Is a multi-stage structure adopted, with low-dimensional coarse filtering followed by fine-grained ranking in the original space?
    • Is candidate recall monitored offline, and is long-context task accuracy close to full attention?
    • Are block granularity, candidate block count, and Top-k configurable?
    • Are prefill and decoding optimized separately, and can index caches be reused?
    • Are linear attention layers mixed in to control the proportion of global layers?
    • Is throughput, memory footprint, and tail latency actually measured on the target hardware, rather than relying only on theoretical complexity?

    7. Summary

    Sparse attention solves the “only look at a small subset” problem, but it does not automatically solve “how to find that small subset.” When context scales to tens of millions of tokens, the indexer becomes a new quadratic-growth bottleneck. The value of latent-space sparse attention lies in moving the indexing process from the original high-dimensional space to a low-dimensional latent space. Through block-level coarse filtering, candidate generation, and fine-grained ranking in the original space, it transforms full comparison into multi-stage small-set comparison, achieving sub-quadratic indexing capability while preserving accuracy.

    For system designers, the key takeaway is not memorizing a specific speedup ratio, but understanding this optimization path: first identify whether the indexer has become the dominant cost, then use low-dimensional representations to reduce comparison cost, use hierarchical candidates to shrink the search space, use fine-grained ranking and recall monitoring to protect accuracy, and finally translate complexity advantages into real throughput through chunking, caching, and kernel fusion. Only then can 10M-token context be not merely “storable,” but “efficiently usable.”