TL;DR
TierCache is a new multi-granularity semantic caching framework that significantly cuts the cost and latency of using LLMs for database tasks (Text-to-SQL/Cypher). By introducing a two-tier system that reuses both exact responses and underlying query structures, it achieves up to a 3x end-to-end speedup while maintaining over 95% of the original model's accuracy.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly used to translate natural language into structured queries like SQL or Cypher. However, running these models for every single user request is expensive and slow.
Existing "semantic caches" try to solve this by storing previous query-response pairs. If a new question is semantically identical to a cached one, the system simply returns the stored answer. The problem is that these caches are verbatim: they only work for near-perfect matches. In data applications, users often ask questions that share the same structure but have different values (e.g., "What is the revenue in West for Q2?" vs. "What is the revenue in East for Q1?").
Standard caches either miss these opportunities entirely or, worse, return a "false hit"—an incorrect answer that looks plausible but uses the wrong data values. TierCache addresses this by enabling partial reuse, allowing the system to recycle the "template" of a query even when the specific details change.
Methods
TierCache introduces a two-tier caching architecture and a two-stage retrieval process:
- Tier 1 (Verbatim Reuse): The "fast path." It uses a standard semantic encoder to find exact matches. If a match is found with high confidence, the cached query is returned immediately.
- Tier 2 (Partial Reuse): If Tier 1 misses, the system looks for a structural match. It uses a specialized structure-aware encoder (trained via contrastive learning) to find queries that share the same underlying logic.
- Lightweight Slot Filling: When a Tier 2 hit occurs, TierCache retrieves a "masked" version of the query (e.g.,
SELECT ... WHERE region = [MASK]). Instead of calling a massive LLM, it uses a tiny, specialized model (like T5) to quickly fill in the masks based on the new user input. - Conditional Write-Back: To keep the cache clean, TierCache only saves queries that successfully execute on the database, preventing "cache pollution" from hallucinated or broken queries.
Datasets
The authors argue that existing Text-to-SQL benchmarks don't reflect how real-world caches are used (which involve streams of recurring queries). To fix this, they introduced SQStream:
- Composition: 10 workloads (6 for SQL, 4 for Cypher).
- Sources: Derived from BIRD, EHRSQL, ScienceBenchmark, and CypherBench.
- Design: Unlike static datasets, SQStream organizes queries into sequential streams using a power-law distribution to simulate realistic recurrence and "skewed" query frequencies.
Key Insights and Ideas
- Structure as a First-Class Citizen: The core "aha" moment is that in structured query generation, the syntax is often more reusable than the semantics. By decoupling the query template from the specific data values (literals), you can massively expand cache coverage.
- The Reliability Trade-off: Traditional caches have to be very conservative with their similarity thresholds to avoid giving wrong answers. TierCache's two-tier design allows it to be conservative on verbatim hits while being more "adventurous" on structural hits, because the slot-filling step acts as a corrective mechanism.
- Efficiency Gains from Specialization: Using a small T5 model for slot-filling is orders of magnitude faster and cheaper than re-generating a 50-token SQL query using a 32B or 70B parameter LLM.
Key Results
TierCache consistently outperformed state-of-the-art baselines like GPTCache and vCache across all tested workloads:
- Hit Rates: Achieved 1.28x to 4.44x higher cache hit rates than baselines under strict quality constraints.
- Speedups: Delivered 1.48x to 2.99x end-to-end speedups.
- Pareto Frontier: As shown in the charts below, TierCache (the dark blue line) consistently stays in the "sweet spot" of high execution accuracy (EX) and low latency.
Limitations and Future Work
- Abstraction Depth: Currently, the "partial reuse" focuses mainly on literals (strings and numbers). The authors note that future versions could extend this to aggregate functions (e.g., swapping
SUMforAVG) or operators. - Cache Pollution: While the conditional write-back helps, the majority of Tier 2 failures still stem from the base LLM generating an incorrect query in the first place, which then gets cached.
- Verification: The authors suggest that integrating stronger verification methods or auxiliary re-rankers could further improve the reliability of partial reuse in complex scenarios.
Summary updated