Caching is commonly used to reduce latency, lower infrastructure costs, and avoid repeating expensive operations. In traditional applications, a cache might store database query results or frequently accessed objects. AI systems introduce additional opportunities because a single user request can involve several expensive operations, including embedding generation, vector search, prompt construction, and model inference.
Consider an AI assistant that receives thousands of requests every minute. Many requests may contain repeated questions, similar prompts, shared instructions, or references to the same documents. Repeating every operation for each request wastes compute resources and increases response time.
Caching can help, but AI systems introduce challenges that are less common in traditional applications. Two prompts can have different wording but similar meaning. A previously generated answer may become outdated when its source documents change. A cached result may also contain information that one user is authorized to access but another is not.
The design must therefore determine what to cache, how to identify reusable results, when cached data becomes stale, and which users are allowed to access it.
1. Cache Frequently Requested Responses
Suppose an e-commerce company operates a customer support assistant. Customers frequently ask questions about return policies, shipping estimates, order status, and product availability. Each request is processed by an application that retrieves relevant information and sends a prompt to an LLM.