---
type: "post"
id: "ai-semantic-caching-semantic-caching-with-redis-for-0c0c80"
slug: "ai-semantic-caching-semantic-caching-with-redis-for-0c0c80"
title: "ai-semantic-caching: Semantic Caching with Redis for cheaper and faster responses"
description: "A Redis-based semantic-caching example shows how a matching prompt can reuse a stored answer and remove an LLM request from the critical path."
retrieval_nugget: "A Redis-based semantic-caching example shows how a matching prompt can reuse a stored answer and remove an LLM request from the critical path."
published_at: "2026-11-28"
updated_at: "2026-11-28"
record_date: "2026-11-28"
date_kind: "published_at"
topics: ["inference","ai-infrastructure"]
entities: ["ai-semantic-caching","Redis","all-MiniLM-L6-v2"]
related_patterns: []
novelty_label: "new_fact"
what_changed: "This example describes a Redis-based semantic cache that matches incoming prompts by vector similarity and reuses prior responses above a threshold."
prior_refs: []
source_url: "https://github.com/botextractai/ai-semantic-caching"
source_urls: ["https://github.com/botextractai/ai-semantic-caching"]
production: {"schema":"newruntime-production-v1","desk":"newsroom","first_seen_at":"2026-11-28T07:00:26.480Z","independent_sources":1,"notes_synthesized":null,"writer_model":"gpt-6-luna","critic":null,"checks":["primary_source_verified","source_fresh","one_story","copy_contract"],"novelty":{"label":"new_fact","confidence":"medium"},"editorial_value":"medium","human_review":"selective"}
citations: [{"claim":"","quotes":["About Semantic Caching with Redis for cheaper and faster responses Resources Readme Activity Stars 3 stars Watchers 0 watching Forks 0 forks Report repository Releases Packages Contributors Languages Footer &copy; 2026 GitHub, Inc.","A semantic cache embeds each … demonstrated by this caching example."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=About%20Semantic%20Caching%20with%20Redis%20for%20cheaper%20and%20faster%20responses%20Resources%20Readme%20Activity%20Stars%203%20stars%20Watchers%200%20watching%20Forks%200%20forks%20Report%20repository%20Releases%20Packages%20Contributors%20Languages%20Footer%20%26copy%3B%202026%20GitHub%2C%20Inc.&text=A%20semantic%20cache%20embeds%20each,demonstrated%20by%20this%20caching%20example.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"},{"claim":"It embeds each incoming prompt, searches stored prompt vectors and returns the previous response if the nearest match clears a configured distance threshold.","quotes":["This example simulates a Semantic … product questions, and account issues."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=This%20example%20simulates%20a%20Semantic,product%20questions%2C%20and%20account%20issues.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"},{"claim":"It uses the all-MiniLM-L6-v2 model, with 384-dimensional embeddings.","quotes":["A semantic cache embeds each … demonstrated by this caching example."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=A%20semantic%20cache%20embeds%20each,demonstrated%20by%20this%20caching%20example.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"},{"claim":"","quotes":["Embedding model The embedding model used in this example is all-MiniLM-L6-v2 .","This is a fast, general purpose embedding model with 384 dimensions (dims)."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=Embedding%20model%20The%20embedding%20model%20used%20in%20this%20example%20is%20all%2DMiniLM%2DL6%2Dv2%20.&text=This%20is%20a%20fast%2C%20general%20purpose%20embedding%20model%20with%20384%20dimensions%20%28dims%29.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"},{"claim":"","quotes":["F1 Score : Balanced metric … (hit rate) with accuracy (precision).","Semantic Caching is a powerful … thresholds based on user feedback."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=F1%20Score%20%3A%20Balanced%20metric,%28hit%20rate%29%20with%20accuracy%20%28precision%29.&text=Semantic%20Caching%20is%20a%20powerful,thresholds%20based%20on%20user%20feedback.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"},{"claim":"The README claims savings of more than 70% in operational costs and responses more than 80% faster.","quotes":["The LLM response times are simulated using a random delay between 0.4 and 0.6 seconds (400-600 ms)."],"cite_url":"https://github.com/botextractai/ai-semantic-caching#:~:text=The%20LLM%20response%20times%20are%20simulated%20using%20a%20random%20delay%20between%200.4%20and%200.6%20seconds%20%28400%2D600%20ms%29.","source_url":"https://github.com/botextractai/ai-semantic-caching","publisher":"github.com"}]
schema_version: "newruntime-agent-readable-v0.2"
stable_id: "post:ai-semantic-caching-semantic-caching-with-redis-for-0c0c80"
status: "published"
visuals: []
editor: {"role":"editor","name":"Andrey Reshetnikov","profile":"https://newruntime.com/owner-profile.md","profile_json":"https://newruntime.com/owner-profile.json","same_as":["https://www.linkedin.com/in/reshetnikov1/","https://t.me/lapetuse"]}
routes: {"html":"https://newruntime.com/posts/ai-semantic-caching-semantic-caching-with-redis-for-0c0c80/","markdown":"https://newruntime.com/posts/ai-semantic-caching-semantic-caching-with-redis-for-0c0c80.md","json":"https://newruntime.com/posts/ai-semantic-caching-semantic-caching-with-redis-for-0c0c80.json"}
markdown_url: "https://newruntime.com/posts/ai-semantic-caching-semantic-caching-with-redis-for-0c0c80.md"
---

# ai-semantic-caching: Semantic Caching with Redis for cheaper and faster responses

## Retrieval answer

A Redis-based semantic-caching example shows how a matching prompt can reuse a stored answer and remove an LLM request from the critical path.

## Summary

A Redis-based semantic-caching example shows how a matching prompt can reuse a stored answer and remove an LLM request from the critical path. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=About%20Semantic%20Caching%20with%20Redis%20for%20cheaper%20and%20faster%20responses%20Resources%20Readme%20Activity%20Stars%203%20stars%20Watchers%200%20watching%20Forks%200%20forks%20Report%20repository%20Releases%20Packages%20Contributors%20Languages%20Footer%20%26copy%3B%202026%20GitHub%2C%20Inc.&text=A%20semantic%20cache%20embeds%20each,demonstrated%20by%20this%20caching%20example.))

## What happened

The example models e-commerce support questions about refunds, shipping, products and accounts. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=This%20example%20simulates%20a%20Semantic,product%20questions%2C%20and%20account%20issues.)) It embeds each incoming prompt, searches stored prompt vectors and returns the previous response if the nearest match clears a configured distance threshold. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=A%20semantic%20cache%20embeds%20each,demonstrated%20by%20this%20caching%20example.)) It uses the all-MiniLM-L6-v2 model, with 384-dimensional embeddings. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=Embedding%20model%20The%20embedding%20model%20used%20in%20this%20example%20is%20all%2DMiniLM%2DL6%2Dv2%20.&text=This%20is%20a%20fast%2C%20general%20purpose%20embedding%20model%20with%20384%20dimensions%20%28dims%29.))

Threshold selection governs the balance between reuse and matching quality: the README recommends 0.10–0.15 for precision and hit rate, while describing 0.25–0.30 as the default starting point. A lower threshold increases precision but reduces recall. The README defines utility as the harmonic mean of precision and cache hit rate, and recommends monitoring both hit rate and precision, then adjusting in response to user feedback. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=F1%20Score%20%3A%20Balanced%20metric,%28hit%20rate%29%20with%20accuracy%20%28precision%29.&text=Semantic%20Caching%20is%20a%20powerful,thresholds%20based%20on%20user%20feedback.))

## What the archive adds

This is application-side answer reuse: unlike provider-side KV caching, it matches a new prompt to a stored prompt and returns an earlier response.

## Why it matters

The threshold is a product-quality control, not just a performance setting. Looser matching can produce more cache hits, but also raises the risk of reusing an answer that does not fit the new question; teams should judge the trade-off against the cost of a wrong response.

## Limits and uncertainty

The example simulates LLM calls rather than making real ones, and its response delays are randomized between 0.4 and 0.6 seconds. ([github.com](https://github.com/botextractai/ai-semantic-caching#:~:text=The%20LLM%20response%20times%20are%20simulated%20using%20a%20random%20delay%20between%200.4%20and%200.6%20seconds%20%28400%2D600%20ms%29.)) The README claims savings of more than 70% in operational costs and responses more than 80% faster. Those claims are not demonstrated by the simulated delays.

## Reader takeaway

Semantic caching can skip an LLM request when a new prompt is close enough to one already stored, but the distance threshold determines how aggressively answers are reused. The demo illustrates the mechanism and a way to evaluate it; its simulated calls and README savings claims do not establish production performance.

Editor: [Andrey Reshetnikov](https://newruntime.com/owner-profile.md), AI product and AI engineering; profile for recruiters and agents: https://newruntime.com/owner-profile.json

## Continue in the graph

Next records for an agent, linked to their Markdown twins. Replace `.md` with `.json` for structured fields, including `next_reads`.

- topic hub: [Inference](https://newruntime.com/topics/inference.md): Explore the inference topic hub.
- topic hub: [Ai Infrastructure](https://newruntime.com/topics/ai-infrastructure.md): Explore the ai-infrastructure topic hub.
- collection: [Field Notes](https://newruntime.com/posts.json): Open the latest editorial analysis.
- collection: [Sources](https://newruntime.com/sources/): See the original sources this archive cites.
- whole graph: [discovery graph](https://newruntime.com/discovery-graph.json) (typed nodes and edges) and [site index](https://newruntime.com/site-index.md)
