Abstract
Large Language Models (LLMs) have revolutionized natural language processing but are constrained by high operational costs and significant inference latency. Traditional exact-match caching is insufficient for the semantic variability of human language. This paper introduces GenerativeCache, a sophisticated caching framework that utilizes generative synthesis and adaptive similarity thresholds to optimize performance. Our results show that GenerativeCache is nine times faster than current state-of-the-art solutions like GPTCache, significantly reducing token expenditure while maintaining high-quality responses.
Introduction
As LLMs move from experimental prototypes to production-grade applications, developers face two major hurdles: latency and cost. API-based models often take seconds to respond and charge per token, making high-volume applications expensive and slow. While semantic caching—retrieving answers based on meaning—offers a solution, existing systems are often too rigid. They struggle with complex queries that require synthesizing information from multiple sources and fail to adapt to the varying precision needs of different tasks, such as code generation versus creative writing. GenerativeCache addresses these gaps by treating the cache as a dynamic knowledge repository rather than a static buffer.
Methods
GenerativeCache introduces several architectural innovations designed to maximize hit rates and minimize overhead.
Hierarchical Architecture
To balance speed, privacy, and knowledge reuse, GenerativeCache employs a two-tier hierarchical structure. Local L1 caches are deployed close to the client for maximum speed and data privacy. These connect to shared L2 caches, which allow for broader knowledge reuse across different users and sessions. This hierarchy ensures that frequently used local data is accessed instantly while still benefiting from the collective knowledge stored in the shared tier.
Generative Caching and Synthesis
The core innovation of the system is its ability to perform generative synthesis. Rather than a simple binary hit/miss logic, the system can identify multiple cached entries that partially answer a query and combine them. For example, a query about both the definition and defense mechanisms of a cyberattack can be answered by synthesizing two separate cached responses, bypassing the need for a new LLM call. This effectively turns the cache into a mined knowledge base.
Adaptive Semantic Similarity
GenerativeCache avoids a static similarity threshold ($t_s$), instead adjusting it dynamically based on three primary factors:
- Content Type: Tasks like Python coding require high precision (near-exact matches), while general conversation or creative writing can tolerate lower similarity.
- Cost/Latency Balance: The system can lower thresholds for expensive models like GPT-4 to favor 'good enough' cache hits over high API costs.
- User Feedback: The system tracks hit quality to optimize the 'quality rate' over time, ensuring that lower thresholds do not compromise user satisfaction.
Multi-LLM Client Interface
The system includes a pluggable architecture that manages interactions with multiple providers, such as ChatGPT, Gemini, and Llama 2, through a centralized proxy and manager. This allows developers to switch between models or use them in parallel while maintaining a unified caching policy.
Evaluation and Results
The researchers evaluated GenerativeCache using the Stanford Question Answering Dataset (SQuAD), which contains over 130,000 pairs, providing a rigorous benchmark for semantic retrieval across diverse topics.
Performance and Efficiency
- Speed: GenerativeCache is approximately 9 times faster than GPTCache, the current industry standard.
- Throughput: The system maintained a throughput of 5 lookups per second with an average response time of 0.2 seconds.
- Cost Savings: By intercepting queries before they reach the LLM, the system significantly reduces token costs. This is particularly impactful for premium models where GPT-4 can be up to 120x more expensive than GPT-3.5.
The Embedding Bottleneck
An important finding is that the primary overhead in modern caching is the computation of vector embeddings (~22ms) rather than the database lookup itself, which typically occurs in sub-millisecond timeframes. This highlights the importance of efficient embedding models in the caching pipeline.
Discussion and Limitations
GenerativeCache transforms the cache from a passive buffer into an active knowledge base. However, several areas for future work remain. The synthesis mechanism's algorithmic details, such as the use of local models for merging, require further exploration. Additionally, while the hierarchical model offers privacy controls, automated techniques like differential privacy are needed for shared L2 tiers. Finally, pre-loading caches with historical data is recommended to mitigate 'cold start' issues in new deployments.
Summary updated