Quest1
AI/ML

Redis Semantic Caching & Routing

Cut LLM spend ~5× with vector-based caching and routing.

Redissemantic cachingLLMvector searchcost optimisationGenAI

_Cut LLM Spend by 5× — While Boosting Response Speeds_


✅ TL;DR

Redis’ vector indexing enables semantic caching and routing by meaning, not just exact phrasing. In internal benchmarks (900 variant queries across GPT-4 and Llama-3), semantic caching slashed llm token usage by 80%

▶️ Watch a quick demo

1\. Why Plain-Text Caches Fail for LLMs

Traditional caches rely on exact string matches. But terrible for natural language, where meaning matters more than wording.

Example:

“Bangalore weather today” vs “What’s the forecast for Bangalore?”

Same intent — different strings ⇒ cache miss ⇒ expensive LLM call.

2\. Enter: Semantic Caching

Redis solves this:

  1. Incoming query → embedding vector
  2. Redis performs a vector similarity search
  3. If a result crosses the similarity threshold, return the cached answer; otherwise:
  • Query is routed to the LLM
  • Answer is stored as a new (vector, response) pair

Result: Paraphrased queries now hit the cache; no LLM needed.

3\. Semantic Routing (When the Cache Misses)

When no cached response is found, Redis doesn’t just forward blindly — it routes to the right model based on semantic similarity and configuration

This is all done with vector-based routing, no brittle if-contains("sports") rules.

4\. Test Setup & Design


Metrics Collected:

  • Semantic cache-hit rate
  • Routing accuracy vs ground truth
  • P95 latency
  • Monthly token cost (OpenAI pricing)

5\. Results Summary


6\. Cost-Savings Deep Dive

Scenario: A large scale organization with 5 million LLM queries/month

  • Query size: 20 input + 100 output tokens
  • LLMs Used: GPT-4.1, Llama 3.2(running locally on Ollama)

🟥 Without Redis

5M queries × 20 input tokens × ($2 / 1M tokens) = $200/month 5M queries × 100 output tokens × ($8 / 1M tokens) = $4000/month Total $4,200/month

🟩 With Redis (~80% cache-hit rate)

1M queries × 20 input tokens × ($2 / 1M tokens) = $40/month 1M queries × 100 output tokens × ($8 / 1M tokens) = $800/month Total $840/month

✅ Monthly Savings → $3360 (~5× reduction)

7\. Key Takeaways

  • Semantic Caching boosts hit rates to 80%+
  • Semantic Routing picks the appropriate model

Results:

  • 5× lower cost
  • 99× faster responses

Redis already powers real-time leaderboards and queues; now, with vectors, it powers real-time LLM intelligence.

Got Feedback?

Thanks for reading! Feel free to leave a comment or reach out with suggestions or questions.

R
Rajkumar
Author · Quest1
echo "let's connect"

Have a perspective of your own?

We'd like to hear how you're thinking about AI, data, and the architecture decisions that matter.