Redis Semantic Cache (LangCache)
## what it does
tl;dr: the only one of the eight Redis skills that is specifically an LLM cache, and the most thematic hit on this shelf given the site name. LangCache lives on Redis Cloud (preview), stores prompts as embeddings, returns a cached answer when the new prompt is semantically close. The skill encodes the cache-aside flow, three threshold bands, and the one rule that breaks more demos than anything else — never share one cache across two different task types.
What it actually does
Fetched SKILL.md (~4.4 KB) runs three sections plus a references link, all instruction-only markdown — no executable scripts.
1. The cache-aside flow. Standard pattern in front of any LLM call.
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 search and set operations are exposed via REST (POST /v1/caches/{cacheId}/entries/search and POST /v1/caches/{cacheId}/entries) when the SDK doesn’t fit. Full SDK + REST samples and attribute-based storage live in references/langcache-usage.md.
2. Tune the similarity threshold. Threshold = how close (cosine distance in embedding space) a new prompt must be to count as a hit. Three bands from the skill:
| Threshold | Behavior | Use when |
|---|---|---|
| 0.95+ | Near-exact required | Customer-facing answers where wrong responses are costly |
| 0.9 | Balanced default | Most workloads — start here |
| 0.8 | Loose match | Internal tools, exploratory queries, FAQ deduplication |
Adjust by watching the actual hit rate and spot-checking that returned answers are still relevant. Full table and tuning playbook: references/best-practices.md.
3. Separate caches per task type. The rule that breaks demos: a “code question” prompt is semantically close to other code questions but has nothing to do with a password-reset support query. Sharing one cache across them returns garbage. The skill’s recommended shape:
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, route each call to the right one. Finer-grained alternative when the same prompt format spans subtopics: store and search with custom attributes (e.g. {"category": "database"}) to keep tasks in the same cache but isolated by attribute filter.
Install
# Wizard — installs the bundle, then pick redis-semantic-cache
npx skills add redis/agent-skills
# Manual — clone the repo and copy the single skill folder
git clone https://github.com/redis/agent-skills
cp -r redis/agent-skills/skills/redis-semantic-cache \
your-project/.claude/skills/
The same repo ships plugin manifests for three hosts:
- Claude Code —
.claude-plugin/marketplace.jsonand a per-skill.claude-plugin/plugin.jsonunder each skill. - Cursor —
.cursor-plugin/marketplace.jsonand matchingplugin.json. - ChatGPT / Codex —
.codex-plugin/plugin.jsonwith real (non-symlinked) copies of every skill underplugins/redis-development/, since plugin flows can drop symlinks. Regenerate withnpm run sync:plugins; pre-commit hook keeps them in sync.
Requires Node + npx on PATH for the wizard. Manual install needs the same Git / filesystem access as any other skills-folder drop.
Gotchas
- LangCache is preview. The SKILL.md header says so explicitly: “LangCache is currently in preview on Redis Cloud. Features and behavior may change.” Pricing and SLAs are not in the README — confirm on Redis Cloud before production.
- One cache per task type — non-negotiable. Sharing across two task types is the silent failure mode the skill hammers on. If the demo answers look wrong, that’s the first place to look, not the threshold.
- Threshold is a knob, not a default. Start at 0.9 per the skill, then watch hit rate and spot-check returned answers. Lower threshold = more hits, more off-topic answers. There is no auto-tune in the skill.
- Custom attributes ≠ magic isolation. Custom attributes filter within one cache. They do not turn one cache into many. Use distinct cache IDs when the workloads are genuinely different.
- SDK vs REST parity. The README points to
references/langcache-usage.mdfor REST when the SDK doesn’t fit — but the threshold tuning and per-task cache rule apply the same way regardless of transport. Don’t let a REST switch become a silent regression. - Three env vars, no defaults.
HOST,CACHE_ID,API_KEYare all required. The Python sample usesos.getenv(...)directly — if any one is unset the call will fail at runtime, not at load. sandbox_testuntested. We readSKILL.mdand the README this session. We did not call LangCache end-to-end from a sandbox.- Static scan verdict: allow. No BLOCK patterns (
curl|sh,subprocess,id_rsa, secret env names, install hooks, C2-style hosts). No REVIEW patterns either (all URLs areredis.io/docsorgithub.com). The skill is instructions + Python samples — no executable scripts.
Related
- Redis Core (redis/agent-skills) — same bundle, the data-type-and-key-naming skill that precedes this one in any realistic Redis modeling job.
- Redis Search (redis/agent-skills) — same bundle, FT.SEARCH / vector / RAG retrieval; what you build the cache in front of when the answer requires a fresh retrieval each call.
- Redis Observability (redis/agent-skills) — same bundle, INFO / SLOWLOG / FT.PROFILE; the skill you pair with this one to see if the cache is actually hitting at the rate the threshold implies.
- Find Skills (vercel-labs/skills) — meta-skill for the discovery CLI that found this one; routes “how do I cache LLM responses” to the right skill instead of guessing.
## compatibility
## embed this badge
