Ten-Million-Token Context Windows: Indexing Is the New Bottleneck

    As LLM context windows scale toward ten million tokens, the bottleneck in sparse attention is shifting from attention computation to index scoring. This article explains why index overhead grows with sequence length, how latent-space sparse selection with block-level compression works, what complexity gains it actually delivers, the trade-off between block size and recall, and a practical checklist for evaluating and adopting such schemes in production.

    1. The Bottleneck Has Shifted from Attention Computation to Indexing

    Over the past year, LLM context windows have grown from hundreds of thousands of tokens to the million-token range, with several vendors treating a million tokens as a standard spec. One of the key techniques behind this expansion is sparse attention: instead of attending to the full history, each query selects only a small set of relevant tokens to compute attention over. The effectiveness of this approach at the million-token scale is well established.

    As the length pushes toward ten million tokens, a new cost becomes prominent. In long-sequence prefilling, some tests show that the indexing step—the part that decides “which tokens to look at”—consumes a substantial share of total latency. The exact proportion depends on model architecture, hardware, and implementation, so this article deliberately avoids quoting a single number. Readers should rely on their own profiling results.

    The core issue is this: sparsification reduces the cost of attention itself, but finding the small relevant subset still requires scanning the entire history. The computation is sparsified; the retrieval is not.

    2. Why Indexing Cost Grows with Sequence Length

    A typical sparse attention pipeline has three steps:

    1. Scoring: compute relevance scores between the current query and all historical key vectors, producing a score sequence of length N.
    2. Selection: pick the Top-K positions from the scores as candidates.
    3. Computation: run standard attention (weighted sum) only over the K candidates.

    When K is much smaller than N, the third step costs O(K) and is cheap. The first step, however, requires comparing the query against all N keys. If scoring itself goes through an additional small network—commonly called an indexer—that network must also project the historical tokens, and its cost scales with N as well. At long sequence lengths, the indexer’s overhead can exceed the actual attention computation.

    When discussing complexity, the phase matters. For a single query, scoring N keys costs O(N). In the prefill phase, all N queries must be processed, so the total cost is O(N²). In the decoding phase, each generated token introduces only one new query, so the per-step cost is O(N), and generating T tokens accumulates to roughly O(N·T). Any claim about whether a method is “quadratic” must first specify whether it refers to prefill or decoding.

    This creates a contradiction: the very sparsity mechanism introduced to save computation has its own decision cost becoming the dominant term.

    3. The Basic Idea of Sparse Selection in Latent Space

    One family of methods starts by compressing historical tokens into a smaller latent space, then performs selection within that space.

    Think of it as a library card catalog. Conventional sparse attention is like flipping through every book before deciding which few to borrow. The latent-space approach builds condensed catalog cards first; the query only flips through the cards to locate the relevant books.

    The pipeline breaks down into three steps:

    1. Block compression: split the length-N history into blocks of size B, and compress each block via pooling or projection into one or a few summary vectors. The N tokens become roughly N/B summaries.
    2. Coarse block selection: the query computes relevance against the summary vectors and selects the top-scoring blocks.
    3. Fine token selection: fine-grained attention is performed only on the original tokens inside the selected blocks.

    In pseudocode:

    1. summaries = compress_blocks(keys, block_size=B) # roughly N/B summaries
    2. top_blocks = topk(score(q, summaries), k_blocks) # coarse block selection
    3. candidates = tokens_in(top_blocks) # fine-grained scope
    4. out = attention(q, keys[candidates], values[candidates])

    This approach can be embedded into existing models as a pluggable selection layer, without rewriting the attention implementation. During training, differentiable Top-K approximations or auxiliary losses can be used so that selection is optimized jointly with the downstream task, reducing the accuracy loss caused by selecting the wrong tokens.

    4. Complexity: Block-Level Selection Reduces the Constant Factor

    This is the point most easily misread. The two-level structure reduces the number of scoring targets from N to N/B. During prefill, each of the N queries scores against roughly N/B summaries, giving a total cost of about O(N²/B). It is still quadratic—only the coefficient is reduced by B.

    Therefore, to credibly claim near-linear complexity, a scheme needs additional premises, such as:

    • Sharing block selection results across queries to avoid repeated scoring;
    • Hierarchical retrieval, where block-level selection itself is further layered;
    • Restricting to a local window so each query only considers nearby blocks.

    These premises must be derived and empirically validated within the specific scheme; they cannot be inferred from the “two-level structure” alone.

    5. The Trade-off Between Block Size and Recall

    The block size B controls the balance between compression rate and recall. A larger B means fewer summaries and faster scoring, but each summary must represent more tokens, raising the risk that an important token is missed along with its entire block. A smaller B gives more stable recall, at the cost of more summary vectors to store and score. The summary dimension also affects discriminability: when it is too low, summaries of different blocks tend to blur together.

    In short-context scenarios, the extra compression step may not be worth it. In practice, systems often switch between a dense path and a sparse path based on sequence length, with the switching threshold determined empirically.

    6. How to Evaluate a Sparse Selection Scheme

    When you see speedup numbers from a paper or framework, first confirm the following:

    • Model architecture: dense attention or hybrid attention;
    • Sequence length and phase: prefill, decoding, or both;
    • Hardware and implementation: GPU model, memory size, whether fused kernels are used;
    • Baseline: which dense or sparse implementation it is compared against;
    • Tasks and metrics: on long-context retrieval, multi-hop reasoning, code understanding, etc., how large is the metric gap.

    A speedup figure missing this information can only serve as a directional reference.

    7. A Practical Checklist for Developers

    Teams building ultra-long-context applications can proceed in this order:

    • Profile the latency of each stage first, separating indexing, attention computation, cache movement, and memory access. Often the bottleneck is not computation itself.
    • Record parameters such as block size B, summary dimension, and recall@K in a comparable experiment table.
    • Build an accuracy regression suite covering retrieval, multi-hop reasoning, and code tasks, and run it after every change.
    • Monitor peak memory usage and throughput, paying special attention to prefill-phase peaks.
    • Validate accuracy at smaller lengths first, then scale up gradually to the target length. Cloud GPU instances, object storage, and log monitoring can reduce the setup cost at this stage.
    • In architecture reviews, evaluate the selection mechanism’s own complexity together with the attention computation.

    8. Conclusion

    The competitive focus of ultra-long context is shifting from “can the full input fit” to “can the relevant parts be found quickly.” Latent-space sparse selection shows that the target of sparsification is not only attention computation—selection itself should also be sparsified. Block-level selection has engineering potential in specific scenarios, but what it reduces first is the constant factor. Escaping quadratic growth requires stronger structural assumptions, backed by empirical validation at the target sequence lengths.