← RedisCONTENT HISTORY

Update to Redis

Snapshot Sep 30, 2026 · 23:01 UTC · version 1.4.0

Collection source: not recorded for this historical snapshot.

WHAT CHANGED · RULE-BASED ANALYSIS

First saved snapshot

No earlier snapshot is available to establish a change.

Compare saved observations

Download comparison JSON
Full technical diff · 0 changed fields
Full snapshot data
{
  "name": "redis-semantic-cache",
  "description": "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.",
  "included_files": [
    {
      "relative_path": "agents/openai.yaml",
      "size_in_bytes": 225
    },
    {
      "relative_path": "references/best-practices.md",
      "size_in_bytes": 1740
    },
    {
      "relative_path": "references/langcache-usage.md",
      "size_in_bytes": 2118
    }
  ],
  "skill_md_contents": "---\nname: redis-semantic-cache\ndescription: 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.\nlicense: MIT\n---\n\n# Redis Semantic Cache\n\nSemantic 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.\n\n> LangCache is currently in **preview** on Redis Cloud. Features and behavior may change.\n\n## When to apply\n\n- Wrapping an LLM call (OpenAI, Anthropic, etc.) with a cache layer to cut cost and latency.\n- Caching RAG answers, classification outputs, or any deterministic LLM workload.\n- Tuning the precision/hit-rate trade-off for a semantic cache.\n- Splitting one application's LLM workloads across multiple cache instances.\n\n## 1. The cache-aside flow\n\nLangCache fits in front of any LLM call as a standard cache-aside pattern:\n\n1. Send the user's prompt to LangCache's `search`.\n2. **Cache hit** — return the stored response directly.\n3. **Cache miss** — call the LLM, then `set` the response so future similar prompts hit.\n\n```python\nfrom langcache import LangCache\nimport os\n\nlang_cache = LangCache(\n    server_url=f\"https://{os.getenv('HOST')}\",\n    cache_id=os.getenv(\"CACHE_ID\"),\n    api_key=os.getenv(\"API_KEY\"),\n)\n\nresult = lang_cache.search(prompt=\"What is Redis?\", similarity_threshold=0.9)\nif result:\n    response = result[0][\"response\"]\nelse:\n    response = llm.generate(\"What is Redis?\")\n    lang_cache.set(prompt=\"What is Redis?\", response=response)\n```\n\nThe 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.\n\nSee [references/langcache-usage.md](references/langcache-usage.md) for full SDK + REST samples and attribute-based storage.\n\n## 2. Tune the similarity threshold\n\nThe 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.\n\n| Threshold | Behavior | Use when |\n|---|---|---|\n| 0.95+ | Near-exact match required | Customer-facing answers where wrong responses are costly |\n| 0.9 | Balanced default | Most workloads — start here |\n| 0.8 | Loose semantic match | Internal tools, exploratory queries, FAQ deduplication |\n\n```python\n# Stricter — fewer false positives\nresult = lang_cache.search(prompt=\"What is Redis?\", similarity_threshold=0.95)\n\n# Looser — higher hit rate\nresult = lang_cache.search(prompt=\"What is Redis?\", similarity_threshold=0.8)\n```\n\nAdjust by watching the actual cache-hit rate and spot-checking that returned answers are still relevant.\n\nSee [references/best-practices.md](references/best-practices.md).\n\n## 3. Separate caches per task type\n\nDifferent 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.\n\n```python\nsupport_cache = LangCache(server_url=..., cache_id=\"support-cache-id\", api_key=...)\ncode_cache    = LangCache(server_url=..., cache_id=\"code-cache-id\",    api_key=...)\n```\n\nCreate 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.\n\n## References\n\n- [LangCache documentation](https://redis.io/docs/latest/develop/ai/langcache/)\n"
}

SHA-256: ce31ab11df8a4dc192d087cff7090a41935902e2cfe00bca3ce4c2f2a6ce89b6