Abstract
Standard semantic caches for Large Language Models (LLMs) often fail to handle "long-tail" workloads because they apply one-size-fits-all policies and incur high search latencies. This paper proposes a category-aware hybrid architecture that separates local in-memory search from external storage, slashing cache miss costs from 30ms to 2ms and making caching economically viable for low-hit-rate query categories.
Introduction
Semantic caching—storing LLM responses and retrieving them based on vector similarity rather than exact string matches—is a common way to reduce costs and latency. However, current implementations (often built on top of remote vector databases) suffer from three major flaws:
- Workload Heterogeneity: LLM queries aren't uniform. Code queries are dense and highly repetitive, while conversational queries are sparse and unique. A single similarity threshold might be too loose for code (causing "false positive" matches) but too tight for chat (missing valid paraphrases).
- The "Economic Break-Even" Problem: Vector databases typically incur ~30ms of network and search latency. If a query category has a low hit rate (e.g., 10%), the cumulative cost of these "misses" outweighs the savings from the occasional "hit." Consequently, production systems often exclude 30–40% of their traffic from the cache.
- Static Policies: Fixed Time-to-Live (TTL) settings either serve stale data for volatile topics or waste memory on stable data.
Proposed Methodology
The authors introduce a Category-Aware Semantic Caching framework with two primary innovations: a hybrid architecture and a per-category policy engine.
Hybrid Architecture
Instead of relying solely on a remote vector database, the system keeps a lightweight HNSW (Hierarchical Navigable Small World) index and embedding vectors in local RAM. The actual "heavy" documents (request/response bodies) are stored in an external database or object store. This allows the system to determine a "miss" in just 2ms locally, rather than waiting 30ms for a remote database response.
Per-Category Policy Engine
The system applies different parameters based on the query type:
- Similarity Thresholds: Tight for dense spaces (code) and loose for sparse spaces (chat).
- TTLs: Long for stable content and short for volatile data.
- Adaptive Load-Based Policies: The cache can dynamically "relax" its rules. If a downstream LLM is overloaded, the cache can lower its similarity threshold or extend TTLs to catch more queries, shielding the model from a traffic spike.
Workload Analysis
The paper evaluates its approach using a representative production workload model based on 100,000 queries per hour. It categorizes these into "Head" categories (60% of traffic) and "Tail" categories (40% of traffic).
As shown in the table, while Head categories like code generation are viable for standard vector databases, Tail categories (e.g., medical or financial queries) have hit rates as low as 6–12%. These categories typically fall below the economic break-even point for remote caching but become viable under the proposed hybrid model.
Key Insights and Results
- The 15% Barrier: The authors calculate that with standard vector DB latencies, a category needs at least a 15–20% hit rate to be worth caching. By reducing miss latency to 2ms, they lower this "break-even" point to just 3–5%, enabling coverage for the entire workload.
- Embedding Density Matters: The paper highlights that the 10th nearest neighbor in a code embedding space is much closer (~0.12 distance) than in a conversational space (~0.38), proving that global thresholds are mathematically destined to fail.
- Latency and Efficiency: Average latency for a cache miss dropped from 30ms to 2ms. Furthermore, the local index requires only ~112 bytes of overhead per entry, making it feasible to store millions of entries in standard RAM.
- Traffic Shielding: Theoretical projections show that during model overloads, dynamic policy adjustment can reduce traffic to the LLM by 9–17%.
Limitations and Future Work
The results for adaptive load-based policies are currently based on theoretical models; empirical validation with live production traffic is the next step. Additionally, while the paper suggests using request metadata for zero-latency categorization, using an LLM-based classifier would add its own latency. Finally, extremely large-scale deployments might eventually require sharding the local HNSW index across multiple nodes.
Summary updated