Technical Summary: Cache-Aware Prompt Compression (CAPC)
Problem Statement
Modern Large Language Model (LLM) deployments increasingly rely on two distinct cost-reduction primitives: prompt caching (storing KV-states of a prefix to charge discounted rates for subsequent reads) and prompt compression (reducing the token count of the input). Historically, these techniques have been treated as separate optimizations. However, the dominant literature on prompt compression relies on query-aware methods, which generate a unique compressed prefix for every specific query.
This design choice creates a fundamental conflict with prefix-strict caching mechanisms (e.g., Anthropic's cache_control). Because the compressed prefix changes with every query, the cache key is invalidated on every call. Consequently, the system pays the full, non-discounted input rate for every request, effectively erasing the savings from both compression and caching. While existing literature often assumes an ideal cache hit rate (ρ=1.0), this assumption fails to account for the economic reality of real-world APIs, where cache behavior is non-trivial and query-aware compression can result in a net negative return on investment (ROI).
Methodology and Empirical Characterization
The authors address this gap through a combination of empirical measurement, cost modeling, and algorithmic design.
1. Empirical Characterization of Anthropic Sonnet 4.6
The paper first characterizes the caching behavior of Anthropic's Sonnet 4.6 API through controlled experiments (n=3 trials, total cost $1.91). Key findings include:
- Two-Tier Architecture: The cache is not uniform. It exhibits a sharp threshold near 3,500 tokens.
- Hot Tier (< 3.5k tokens): The hit rate (ρ) plateaus at approximately 0.83 (specifically 0.833 for 2k tokens) even after 30 calls. It is not 1.0.
- Persistent Tier (> 3.5k tokens): The hit rate is effectively 1.0 from the second call onward.
- Token-Strict Invalidation: Cache invalidation is strict to the token sequence. Even minor mutations (e.g., a single character change) result in a cache miss, though leading/trailing whitespace is normalized by the tokenizer.
- Pricing Structure: The API charges a premium for cache writes (cw) compared to uncached inputs (pin), and a significant discount for cache reads (cr). On Sonnet 4.6, cw≈1.25×pin and cr≈0.10×pin.
2. Cost Modeling and Crossover Analysis
The authors derive a per-call cost model for four strategies:
- A (Vanilla): No cache, no compression.
- B (Cache-only): Full prefix cached, no compression.
- C (Query-aware Compression): Compressed per query, no cache (cache misses every time).
- D (CAPC): Query-agnostic compression + caching.
The model defines a crossover threshold (ρcross) where the cost of caching (Strategy B) equals the cost of query-aware compression (Strategy C):
ρcross(r)=cw−crcw−pin/r
The analysis reveals that for high compression ratios (r≥6), the required hit rate for caching to beat query-aware compression exceeds the empirical plateau of the Sonnet 4.6 hot tier (ρ≈0.89). Thus, under realistic conditions, query-aware compression is often cheaper than naive caching, contradicting conventional wisdom.
3. The CAPC Algorithm
The proposed solution, Cache-Aware Prompt Compression (CAPC), combines three components:
- Query-Agnostic Compression: A static document is compressed once (e.g., via sentence selection) into a fixed prefix D′, ensuring the cache key remains constant across queries.
- Tier-Preserving Ratio Bound: To prevent over-compression from pushing the prefix into the "hot tier" (where ρ<1), the compression ratio r is bounded by rmax=⌊∣D∣/3500⌋. This ensures the compressed prefix remains in the persistent tier (ρ≈1.0).
- AdaptiveCacheBoundary: For evolving documents, a subroutine classifies sentence positions as STATIC, QUASI, or DYNAMIC based on mutation rates across versions, caching only the stable prefix.
Key Results
1. LongBench-v2 Synthetic Benchmarks
On 16 configurations (4 document sizes × 4 ratios), CAPC was the cheapest strategy in 16/16 cases.
- Savings: Mean savings of 49% over cache-only, 64% over query-aware compression, and 90% over vanilla.
- Quality: CAPC maintained quality within 0.05 of the uncompressed baseline at tier-preserving ratios.
- Crossover Validation: At r=6, query-aware compression was cheaper than cache-only in all 4/4 configurations, validating the crossover model's prediction.
2. Production Validation: Enterprise Tool-Using Assistant
Validated on a 94k-token static prefix (system prompt + 287 MCP tool definitions).
- Cost Reduction: CAPC at r=3 achieved a 51.7% cost reduction over vanilla.
- Quality: Tool-selection quality matched cache-only (0.700 vs 0.703).
- Insight: Query-aware compression at r=3 actually performed worse on tool selection (0.603) because it discarded tool definitions relevant to the query. CAPC's query-agnostic approach preserved the full catalog, proving superior for tool-augmented agents.
- Implicit Caching: The study revealed that Anthropic implicitly caches large
tools= arrays even without explicit markers, reducing the marginal benefit of explicit caching for vanilla strategies but not negating CAPC's compression gains.
3. Knowledge-Graph RAG (Graphify)
Integrated with graphify for codebase indexing (FastAPI and httpx repositories).
- Architecture: Layer 1 (cached, query-agnostic) contains graph metadata; Layer 2 (per-query) fetches source code.
- Performance: CAPC delivered 9.3x cost reduction on FastAPI and 2.4x on httpx compared to "cache-all" (full graph skeleton), while maintaining stable 85%+ cache hit rates.
- Quality: CAPC outperformed native graphify queries and embedding-RAG baselines, particularly on codebases where the model had weaker prior knowledge (httpx), delivering a 142% quality lift over vanilla.
4. Public Benchmark: τ-Bench Retail
Evaluated on 50 deterministic tasks with database-state rewards (no LLM judge).
- Result: CAPC was the cheapest strategy, saving 7.9% over vanilla while achieving exactly the same task completion rate (36/50) as vanilla (z=0.00,p=1.00).
- Negative ROI of Query-Aware: Query-aware compression was 40.1% more expensive than vanilla, providing the first production confirmation that query-aware methods can have negative ROI on public benchmarks.
Significance and Claims
The paper claims to provide the first systematic characterization of prompt caching economics, moving beyond the idealized ρ=1.0 assumption. Its primary contributions are:
- Empirical Reality: Demonstrating that LLM caches have a two-tier architecture with a non-trivial hit rate plateau below a specific token threshold.
- Theoretical Inversion: Proving that at high compression ratios, query-aware compression is often cheaper than naive caching, inverting the conventional design hierarchy.
- Practical Algorithm: Introducing CAPC, which unifies query-agnostic compression with explicit caching and a tier-preserving constraint.
- Production Validation: Validating these findings across synthetic benchmarks, enterprise tool-use agents, knowledge-graph RAG pipelines, and public deterministic benchmarks.
The authors emphasize that CAPC is not a replacement for indexers (like graphify) but a complementary "last-mile delivery" layer that optimizes the economic cost of delivering index-derived context to an LLM. The total cost of all empirical work in the paper was $98.96, demonstrating that these findings are reproducible with modest resources.