Generated banner for Redis Semantic Cache
Generated logo for Redis Semantic Cache

Redis Semantic Cache

RedisOfficialCreated by Redis, Inc.

  • Skill
  • Tool integration
  • Data and AI
  • MIT
  • No issues found

From the author

Redis LangCache guidance for semantic caching of LLM responses on Redis Cloud — calling search/set via the SDK or REST API, tuning the similarity threshold, separating caches per task type, and filtering with custom attributes. Use when caching LLM completions or RAG answers to cut API cost and latency, building a cache-aside layer in front of OpenAI / Anthropic / etc., tuning hit rate vs precision, or splitting one app's LLM workloads into multiple LangCache caches.
— the description by Redis, Inc.

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

Redis LangCache provides a semantic caching layer for LLM applications, allowing developers to store and retrieve responses based on prompt similarity. By using embeddings to match incoming queries against previously cached results, applications can avoid redundant model calls. This skill covers the integration of LangCache via SDK or REST API, strategies for tuning similarity thresholds to balance precision and hit rates, and best practices for organizing cache instances by task type or using custom attributes for granular filtering.

What it does

  • Implements a cache-aside pattern for LLM completions and RAG workflows.
  • Provides methods to search for semantically similar prompts using embedding-based matching.
  • Allows configuration of similarity thresholds to control match strictness.
  • Supports storage and retrieval of LLM responses via Python SDK or REST API.
  • Enables logical separation of caches for different application tasks.
  • Supports filtering cached entries using custom metadata attributes.

When to use it

  • When you need to reduce LLM API costs and response latency.
  • When building a cache-aside layer for deterministic or repetitive LLM workloads.
  • When you need to manage different LLM tasks within isolated cache instances.
  • When you want to tune the balance between cache hit rates and response accuracy.

Advantages

  • Significantly lowers latency by serving cached responses for similar queries.
  • Reduces operational costs by minimizing redundant calls to external LLM providers.
  • Offers flexible matching through adjustable similarity thresholds.
  • Supports granular data management via custom attributes and multiple cache IDs.

Usage examples

“How do I implement a cache-aside pattern with LangCache in Python?”
The agent provides a code snippet demonstrating the search-then-generate-then-set flow using the LangCache SDK.
“How can I improve the precision of my semantic cache?”
The agent explains how to adjust the similarity_threshold parameter, recommending a higher value for stricter matching.
“Should I use one cache for all my LLM tasks?”
The agent advises against sharing a single cache for unrelated tasks and suggests using separate cache IDs or custom attributes for isolation.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/redis/redis-semantic-cache/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip redis-semantic-cache.zip -d .agents/skills

Documentation by Redis, Inc.

Redis Semantic Cache

Semantic caching for LLM responses with Redis Cloud's LangCache service. Stores prompts as embeddings; subsequent semantically-similar prompts return the cached response without re-calling the model.

LangCache is currently in preview on Redis Cloud. Features and behavior may change.

When to apply

  • Wrapping an LLM call (OpenAI, Anthropic, etc.) with a cache layer to cut cost and latency.

  • Caching RAG answers, classification outputs, or any deterministic LLM workload.

  • Tuning the precision/hit-rate trade-off for a semantic cache.

  • Splitting one application's LLM workloads across multiple cache instances.

1. The cache-aside flow

LangCache fits in front of any LLM call as a standard cache-aside pattern:

  1. Send the user's prompt to LangCache's search.

  2. Cache hit — return the stored response directly.

  3. Cache miss — call the LLM, then set the response so future similar prompts hit.

from langcache import LangCache
import os

lang_cache = LangCache(
    server_url=f"https://{os.getenv('HOST')}",
    cache_id=os.getenv("CACHE_ID"),
    api_key=os.getenv("API_KEY"),
)

result = lang_cache.search(prompt="What is Redis?", similarity_threshold=0.9)
if result:
    response = result[0]["response"]
else:
    response = llm.generate("What is Redis?")
    lang_cache.set(prompt="What is Redis?", response=response)

The same operations are available via REST (POST /v1/caches/{cacheId}/entries/search and POST /v1/caches/{cacheId}/entries) when an SDK isn't an option.

See references/langcache-usage.md for full SDK + REST samples and attribute-based storage.

2. Tune the similarity threshold

The threshold controls how close (in embedding cosine distance) a new prompt must be to a cached one to count as a hit. Higher = stricter match, fewer false positives. Lower = more hits, more risk of returning an off-topic answer.

ThresholdBehaviorUse when
0.95+Near-exact match requiredCustomer-facing answers where wrong responses are costly
0.9Balanced defaultMost workloads — start here
0.8Loose semantic matchInternal tools, exploratory queries, FAQ deduplication
# Stricter — fewer false positives
result = lang_cache.search(prompt="What is Redis?", similarity_threshold=0.95)

# Looser — higher hit rate
result = lang_cache.search(prompt="What is Redis?", similarity_threshold=0.8)

Adjust by watching the actual cache-hit rate and spot-checking that returned answers are still relevant.

See references/best-practices.md.

3. Separate caches per task type

Different LLM workloads should not share one cache — a "code question" prompt is semantically close to other code questions but has nothing to do with a password-reset support query, and crossing them returns garbage.

support_cache = LangCache(server_url=..., cache_id="support-cache-id", api_key=...)
code_cache    = LangCache(server_url=..., cache_id="code-cache-id",    api_key=...)

Create distinct cache IDs in Redis Cloud per task, and route each call to the right one. As a finer-grained alternative, store and search with custom attributes (e.g. {"category": "database"}) to keep tasks in the same cache but isolated by attribute filter — useful when the same prompt format spans subtopics.

References

Files

references/best-practices.md

Configure Semantic Cache Properly

Note: LangCache is currently in preview on Redis Cloud. Features and behavior may change.

Tune similarity threshold and cache separation for optimal LangCache results.

Correct: Tune similarity threshold for your use case.

from langcache import LangCache

lang_cache = LangCache(
    server_url=f"https://{os.getenv('HOST')}",
    cache_id=os.getenv("CACHE_ID"),
    api_key=os.getenv("API_KEY")
)

# Stricter matching - fewer false positives (0.95 = very similar)
result = lang_cache.search(
    prompt="What is Redis?",
    similarity_threshold=0.95
)

# Looser matching - higher hit rate (0.8 = somewhat similar)
result = lang_cache.search(
    prompt="What is Redis?",
    similarity_threshold=0.8
)

Correct: Use separate caches for different use cases.

# Create different cache IDs in Redis Cloud for different LLM tasks
support_cache = LangCache(
    server_url=server_url,
    cache_id="support-cache-id",
    api_key=api_key
)

code_cache = LangCache(
    server_url=server_url,
    cache_id="code-cache-id",
    api_key=api_key
)

Incorrect: Using a single cache for all LLM tasks.

# All tasks share one cache - responses may not be relevant
result = lang_cache.search(prompt="How do I reset my password?")
# Could return a code snippet if someone asked a similar coding question

Best practices:

  • Start with threshold 0.9, adjust based on your use case

  • Use custom attributes to filter results within a single cache

  • Monitor cache hit rates to evaluate effectiveness

  • Use separate cache IDs for fundamentally different LLM tasks

Reference: LangCache Best Practices

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an API key, Needs Python

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Redis, Inc.
Publisher
Redis (Official)
Source
redis/agent-skills · skills/redis-semantic-cache · commit 74708da
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
redis/agent-skills

AutoGineer is not affiliated with or endorsed by Redis, Inc. or Redis.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download redis-semantic-cache.zip