IndexPool: Compressing Sparse Attention Index Caches for Long-Context Inference
IndexPool uses weighted pooling to combine multiple index-cache vectors per token into a single representation, reducing the cache footprint of sparse attention retrieval. This article explains the four-to-one compression approach, its memory and retrieval-compute benefits, and practical considerations for deployment, including pooling timing, weight selection, quality validation, and tiered caching for contexts approaching one million tokens.
1. The Attention Bottleneck in Long-Context Inference
As large language model context windows grow from tens of thousands of tokens to around one million tokens, the central inference challenge shifts from whether a model can process the input to whether it can do so efficiently.
Full attention has O(N²) computational complexity for a sequence of length N. Although KV caching avoids recomputing historical keys and values during decoding, cache memory still grows linearly with context length. At one million tokens, attention latency and memory consumption become practical constraints for inference services.
One approach is a hybrid architecture that combines two attention mechanisms:
- Linear attention: Uses recurrence or compressed states to retain semantic information with computation that scales approximately linearly with sequence length. In the architecture considered here, it handles much of the local and short-range processing.
- Sparse attention: Uses a lightweight indexer to retrieve a small number of relevant positions from the global context, then applies exact attention only to the retrieved tokens.
This division of work—linear attention for much of the sequence processing and sparse attention for selective global access—helps preserve long-range information access while controlling attention costs.
However, at context lengths approaching one million tokens, another bottleneck emerges: the indexer’s own cache.
2. Why the Index Cache Becomes a Bottleneck
In this hybrid architecture, the indexer stores cached vectors for historical tokens. At each retrieval step, it compares the current query against these vectors to identify relevant positions.
To preserve retrieval quality, an implementation may store multiple vectors per token—for example, four representations that capture different aspects of the same token. The indexer combines their matching scores when selecting candidates.
Both memory consumption and matching work grow with the number of cached representations. For a one-million-token context:
- Storing four vectors per token requires four times the index-cache memory of a single-vector design.
- Retrieval must evaluate the additional representations, increasing similarity-computation costs.
Once linear attention has substantially reduced the main attention cache, the index cache can become a major contributor to memory usage and latency.
Compressing the index cache is therefore an important optimization for long-context inference. IndexPool targets this part of the system.
3. The Core Idea: Four-to-One Compression Through Weighted Pooling
3.1 How It Works
IndexPool combines multiple cached index vectors into a single pooled representation. Retrieval then operates on the pooled vector rather than the original set.
For a four-vector-per-token design, this reduces the vector storage requirement to one-quarter of its original size.
The process has three steps:
- Collect the vectors: Obtain the token’s four index-cache vectors, v₁, v₂, v₃, and v₄.
- Apply weighted pooling: Assign each vector a weight and compute their weighted sum. Weights may be based on vector statistics, attention scores, or learned gating coefficients.
- Replace the original entries: Store the pooled representation and use it for subsequent similarity matching.
The aggregation can be expressed as:
v_pool = Σ wᵢ · vᵢ, where Σ wᵢ = 1
The resulting vector serves as a compressed retrieval representation, rather than a guarantee of mathematically identical matching results.
3.2 Why Weighted Pooling Can Work
Compression inevitably discards information. The rationale for pooling rests on two observations:
- Redundancy between representations: Multiple vectors for the same token often encode related information. Pooling merges these views while retaining much of their shared semantic content.
- Tolerance in candidate retrieval: The indexer performs coarse candidate selection. Its primary goal is to include relevant tokens in the retrieved set; exact attention then processes those candidates. Some distortion in the index representation may therefore be tolerable without materially affecting generation quality.
Compared with a simple average, weighted pooling allows more informative representations to contribute more strongly. This can help preserve retrieval quality at the same compression ratio.
The trade-off still needs validation: if compression causes an important token to be excluded from the candidate set, downstream attention cannot recover it from that set.
3.3 Expected Benefits
Lower index-cache memory
Reducing four vectors to one cuts vector storage to one-quarter of the original amount. At very long context lengths, the freed memory can support larger concurrent batches or longer contexts.
Less retrieval computation
When matching cost scales with the number of cached vectors, four-to-one pooling reduces the corresponding similarity-computation workload by approximately 75%.
This reduction applies to vector matching, not necessarily to total retrieval latency or end-to-end inference time.
Higher serving throughput
Lower memory demand and less matching computation can increase the number of concurrent requests a GPU can support, improving overall inference throughput. The realized benefit depends on how much the index cache and retrieval work contribute to the deployment’s bottlenecks.
4. Integrating Pooling into an Inference Pipeline
The following pseudocode illustrates pooling when a token’s index vectors are written to the cache:
# Pseudocode: pool index vectors when writing to the cachedef update_index_cache(cache_group, query_state):# cache_group: four index vectors for the same token [v1, v2, v3, v4]weights = compute_weights(cache_group) # Compute weights, e.g., with softmax scorespooled = sum(w * v for w, v in zip(weights, cache_group))index_cache.append(pooled) # Store only one pooled vectordef retrieve(query, index_cache, top_k):scores = [dot(query, v) for v in index_cache] # One-quarter of the vector-matching workreturn top_k(scores)
This is an integration sketch, not an executable implementation. It shows where pooling occurs and how retrieval uses the compressed cache.
4.1 Choose When to Compress
Two approaches are possible:
- Online compression: Pool vectors as they are written to the cache. This provides the most immediate memory savings.
- Asynchronous compression: Retain multiple representations initially, then pool older, less frequently accessed entries in the background.
Keeping full representations for recent tokens can preserve higher-fidelity retrieval for those positions, while compressing older entries reduces resource consumption. The choice should reflect the workload’s sensitivity to latency and retrieval quality.
4.2 Select a Weighting Strategy
Potential weight sources include:
- Vector norms or other vector statistics
- Historical retrieval-hit frequency
- A learned gating network
Evaluate retrieval-recall curves for different weighting strategies offline before selecting one for deployment. A weighting rule should be judged by its effect on retrieval and downstream task quality, not just by how easily it can be computed.
4.3 Validate Quality Before Deployment
Use long-context evaluation sets to compare the compressed and uncompressed designs. Assess both:
- Retrieval recall: Whether relevant tokens remain in the candidate set
- End-task metrics: Whether compression changes the quality of the final output
The goal is to establish that any quality loss remains within the service’s acceptable range.
4.4 Consider a Tiered Cache
A mixed deployment can retain multiple index vectors for recent tokens while pooling distant tokens:
- Recent, hot entries: Keep multiple representations for higher-fidelity retrieval.
- Older, cold entries: Use pooled representations to reduce memory and matching costs.
This provides a practical way to balance retrieval quality against resource usage rather than applying the same compression policy to every token.
5. Suitable Workloads and Key Takeaways
Index-cache pooling is most relevant to:
- Long-document understanding, repository-scale code analysis, and extended conversations with hundreds of thousands to around one million tokens
- Models that combine linear attention with index-based sparse attention, where the index cache represents a substantial share of memory use
- Inference services that are sensitive to latency and memory costs and can tolerate a small reduction in candidate-retrieval accuracy
IndexPool illustrates a broader pattern in long-context optimization: once the main attention mechanism is compressed, supporting components can become the next bottleneck.
For an indexer that stores four vectors per token, weighted pooling offers a straightforward path to one-quarter of the vector-cache footprint and substantially less similarity-matching work. These savings can improve the resource efficiency of million-token inference, provided retrieval quality remains acceptable.
In practice, pooling is best evaluated alongside cache tiering, asynchronous compression, and retrieval-recall testing. Together, these measures help balance memory cost, latency, and generation quality.
