AWS Builder Center

Your LLM Is Answering the Same Question Hundreds of Times a Day — Here's How Semantic Caching Helps

Learn how to reduce GenAI inference costs by up to 86% and latency by up to 88% using semantic caching with Amazon ElastiCache for Valkey. Covers architecture, AWS benchmarks, use cases, and practical implementation guidance.

120XSAP 12XAWS 15xAZURE 12xORACLE 10XSCRUM 11XOCI 12XMS 5XSECURITY 2XSOLARIS 2XDB2
The Repeated-Query Cost Problem
Here's a scenario most GenAI teams encounter in production: your chatbot is spending inference budget answering the same questions — just worded differently.
"How do I install the VPN app on my laptop?" "Can you guide me through setting up the company VPN?" "Steps to get VPN working on my computer?"
Three different strings. One answer. Three LLM invocations. Three charges on your bill.
Multiply that across thousands of users hitting your RAG-based assistant daily, and costs add up quickly. In AWS benchmarks, a baseline workload handling 63,796 queries cost $49.50/day in inference — not because the questions were complex, but because many were semantically equivalent.
The fix isn't throttling users or downgrading models. It's semantic caching.
What Semantic Caching Actually Does (And Why Exact-Match Caching Falls Short)
Traditional caching fails GenAI workloads because natural language doesn't repeat itself exactly. Users ask the same thing a hundred different ways. An exact-match cache sees each variation as unique and misses every time.
A semantic cache works differently. Instead of comparing strings character-by-character, it converts each query into a vector embedding — a mathematical representation of meaning — and searches for previously answered queries that are semantically similar. If a match exceeds your configured similarity threshold, the cached response is returned instantly. No LLM call. No inference cost. Millisecond latency.
The architecture is straightforward:
  1. User submits a query → the system generates a vector embedding (e.g., using Amazon Titan Text Embeddings V2)
  1. Vector similarity search against the cache store (Amazon ElastiCache for Valkey)
  1. Cache hit (similarity above threshold) → return cached response in milliseconds
  1. Cache miss → invoke the LLM, return the response, and cache the new query-response pair for future reuse
That's it. One additional hop in the request path that pays for itself on the first cache hit.
The Numbers That Got Our Attention
AWS evaluated this approach against 63,796 real user chatbot queries from the SemBenchmarkLmArena dataset — actual user interactions across question answering, writing, and analysis tasks. The configuration: ElastiCache cache.r7g.large, Amazon Titan Text Embeddings V2, Claude 3 Haiku for inference.
Here's what the benchmarks showed:
Similarity Threshold | Cache Hit Ratio | Accuracy | Cost Savings | Latency Reduction 0.99 (very strict) | 23.5% | 92.1% | 15.8% | 17.1% 0.95 (strict) | 56.0% | 92.6% | 51.9% | 57.7% 0.90 (moderate) | 74.5% | 92.3% | 72.5% | 72.2% 0.80 (balanced) | 87.6% | 91.8% | 84.6% | 86.1% 0.75 (relaxed) | 90.3% | 91.2% | 86.3% | 88.3%
At a 0.75 threshold: 86% cost reduction. 88% latency improvement. 91% answer accuracy maintained.
Individual query latency dropped from 6.51 seconds to 0.11 seconds on cache hits — a 59x improvement, as documented by AWS. That's the difference between a user waiting and a user getting an instant response.
At the 0.75 threshold, daily cost dropped from $49.50 to $6.80 in this benchmark configuration.
Where This Hits Hardest
Semantic caching isn't applicable to every GenAI pattern, but it's particularly effective for three categories:
  1. RAG-Based Assistants and Copilots Enterprise knowledge bots, IT help desks, product FAQ systems, documentation assistants — anywhere multiple users query a shared knowledge base. The overlap in questions is enormous, and most teams underestimate how much inference budget goes to redundant answers.
  1. Agentic AI Applications Agents decompose tasks into steps. Those steps often involve repeated lookups against the same tools and knowledge sources. A compliance agent checking the same policy paragraph across multiple user requests, a research agent re-retrieving the same findings — these are cache-hit goldmines.
  1. Multimodal Applications Automated phone systems, audio-based assistants — matching similar audio segments to reuse guidance for repeated requests (store hours, account balance queries, password resets).
Why ElastiCache for Valkey as the Cache Store
The cache sits in the hot path of every query. It needs to be fast, support real-time vector updates, and efficiently manage ephemeral entries that are written, read, and evicted constantly.
ElastiCache for Valkey delivers: • Microsecond-level vector search latency with up to 99% recall • Real-time vector updates — new query-response pairs are immediately searchable • Built-in TTL and eviction policies — stale entries expire automatically, keeping the cache fresh • Multithreaded architecture — high write throughput without sacrificing search performance • Native integration with Amazon Bedrock AgentCore via LangGraph — deploy a Valkey-backed semantic cache for your agents with minimal orchestration code
Getting Started: The 5-Minute Mental Model
Before you write a single line of code, here are the decisions that matter:
  1. Choose your similarity threshold carefully. Start at 0.90 (moderate) and tune based on your use case. Higher thresholds mean fewer false positives but lower cache hit rates. Lower thresholds give you more cost savings but risk returning answers that don't quite fit. Monitor accuracy and adjust.
  1. Set appropriate TTLs. Cached responses go stale. If your underlying knowledge base changes weekly, your cache TTL should reflect that. For static FAQs, longer TTLs work. For dynamic data, keep it short.
  1. Scope your cache per context. A multi-tenant application needs cache isolation between tenants. A user-specific assistant might benefit from per-user cache segments. Design your key structure accordingly.
  1. Monitor cache hit rates. A cache with a 5% hit rate isn't saving you anything — it's adding latency. Track hit rates by query category and optimize where the density is highest.
Summary
If your GenAI application handles repeated or similar queries at scale, semantic caching with Amazon ElastiCache for Valkey offers meaningful cost and latency improvements. The implementation is straightforward, the savings are measurable from day one, and the user experience improvement — sub-second responses vs. multi-second waits — is immediately noticeable.
Let the cache handle what the LLM has already answered.
References: • Overview of Semantic Caching — Amazon ElastiCache Documentation:  https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/semantic-caching-overview.html  • Impact and Benchmarks — Amazon ElastiCache Documentation:  https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/semantic-caching-benchmarks.html  • Lower Cost and Latency for AI Using Amazon ElastiCache as a Semantic Cache with Amazon Bedrock:  https://aws.amazon.com/blogs/database/lower-cost-and-latency-for-ai-using-amazon-elasticache-as-a-semantic-cache-with-amazon-bedrock/  • Guidance for Semantic Caching for Generative AI Applications Using Amazon ElastiCache for Valkey:  https://aws.amazon.com/solutions/guidance/semantic-caching-for-generative-ai-applications-using-amazon-elasticache-for-valkey/  • Implementing a Semantic Cache with ElastiCache for Valkey:  https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/semantic-caching-implementation.html 
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article