Index Bottlenecks and Latent-Space Filtering in Ten-Million-Token Contexts

    Long-context language models have moved from 128K to 1M and now toward 10M token windows. At the ten-million scale, the main bottleneck is no longer attention computation itself but the cost of the indexer that selects which tokens each query should attend to. This article breaks down the three stages of context length evolution, explains why indexing overhead grows quadratically during prefill, and walks through the core idea of Latent Sparse Attention (LSA): performing token selection in a low-dimensional latent space, with a simplified code example and complexity analysis.

    1. Three Stages of Context Length

    The context window of large language models has expanded rapidly in recent years. The industry has roughly gone through three stages, each with a different primary bottleneck.

    Stage Typical Use Cases Mainstream Approach Primary Bottleneck
    128K Long-document QA, single multi-turn conversations Full attention GPU memory and attention compute
    1M Large code repositories, long-form document analysis Hybrid architectures combining sparse and linear attention Compute still grows with length; sparsity can suppress it
    10M Very large codebases, long-term agent memory, massive log auditing Hierarchical and index-based schemes Index overhead of picking relevant tokens

    The hybrid architecture works as follows: instead of computing attention between each query and every historical token, an indexer first selects a small set of the most relevant tokens, and full attention is computed only over those. At the 1M scale, this typically reduces compute significantly with minimal accuracy loss.

    2. Why Indexing Overhead Explodes at Ten Million Tokens

    A sparse attention prefill can be split into two steps. The first is the indexing stage, which decides “which tokens to look at” for each query. The second is the attention stage, which computes attention only over the selected tokens.

    Most indexers need to compute relevance scores between each query and all historical tokens in some representation. Even if that representation is smaller than the full KV cache, the scoring cost per query is still proportional to the context length N. The number of queries in prefill also grows on the order of N, so the total indexing cost scales as N² multiplied by the indexing dimension d.

    This means that once sparsity reduces the cost of the attention stage, the indexing stage can become the dominant expense. On very long sequences, indexing may account for a large share of prefill time—the exact ratio depends on model architecture, implementation, and hardware. The core problem therefore shifts from “looking at fewer tokens” to “finding those tokens at low cost.”

    3. The Core Idea of Latent-Space Filtering

    Latent Sparse Attention (LSA) is a family of methods that target indexing overhead. It moves token selection into a low-dimensional latent space, allowing only a small set of candidates to return to the original high-dimensional space for exact computation.

    Note: the specific papers and experimental details behind the LSA name used here should be referenced from the original literature. This article discusses the design philosophy of this class of methods and does not endorse any specific paper’s numbers.

    3.1 Why Low-Dimensional Representations Work for Selection

    Selection does not require exact attention scores—only a reliable ranking signal, i.e., determining which tokens are likely to fall in the top-k. Attention scores come from high-dimensional inner products, but their ranking structure is often concentrated in a few directions. Projection can therefore map queries and keys into a lower-dimensional space while preserving the top-ranked candidates.

    This intuition has limits. Dimensionality reduction is not lossless. When the attention distribution is flat and many tokens have nearly identical scores, no low-dimensional approximation can reliably pick out the truly important ones. Such cases require compensation through a larger candidate set or a higher latent-space dimension.

    3.2 Block-Based Indexing and Complexity

    The following code is a simplified illustration of the block-based selection structure.

    1. def lsa_attention(Q, K, V, proj, block_size, top_blocks, top_tokens):
    2. # 1. Project into the low-dimensional latent space
    3. Qh = proj.q(Q) # [n_q, d_s]
    4. Kh = proj.k(K) # [n_kv, d_s]
    5. # 2. Block-level coarse selection: use each block's mean vector as its representative
    6. n_blocks = Kh.shape[0] // block_size
    7. Kb = Kh.reshape(n_blocks, block_size, -1).mean(axis=1) # [n_blocks, d_s]
    8. block_scores = Qh @ Kb.T # [n_q, n_blocks]
    9. blocks = topk(block_scores, top_blocks) # [n_q, top_blocks]
    10. # 3. Fine selection within blocks: score only inside selected blocks
    11. cand = gather_block_indices(blocks, block_size) # [n_q, top_blocks * block_size]
    12. fine = batched_dot(Qh, Kh[cand]) # [n_q, top_blocks * block_size]
    13. idx = gather(cand, topk(fine, top_tokens)) # [n_q, top_tokens]
    14. # 4. Run full attention only on the selected tokens (batched per query)
    15. K_sel, V_sel = K[idx], V[idx]
    16. return attention(Q, K_sel, V_sel)

    For complexity analysis, the block-level coarse selection costs roughly n_q × (N/B) × d_s, where B is the block size. Fine selection within blocks costs roughly n_q × top_blocks × B × d_s. For prefill, n_q is on the order of N, so this simple block-based design does not change the asymptotic complexity—it only reduces the constant factors: dimensionality compression yields a d_s/d reduction, and blocking reduces