返回顶部
s

semantic-cache

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
142
下载量
0
收藏
概述
安装方式
版本历史

semantic-cache

# Semantic Cache Cache LLM responses by meaning using Redis vector search. Similar questions return cached answers instantly instead of making expensive API calls. ## How It Works 1. User asks a question or makes an LLM request 2. The question is embedded into a vector using OpenAI text-embedding-3-small 3. Redis vector search finds semantically similar cached queries (cosine similarity > 0.80) 4. **Cache hit**: Return the cached response instantly (~100ms) 5. **Cache miss**: Pass through to the LLM, cache the response for future similar queries ## Commands ### Cache a query and response ```bash node scripts/cache.js store "What is the capital of France?" "The capital of France is Paris." ``` ### Check cache for a similar query ```bash node scripts/cache.js lookup "What's France's capital city?" ``` ### Cache stats ```bash node scripts/cache.js stats ``` ### Clear all cached entries ```bash node scripts/cache.js clear ``` ### Interactive mode — wraps any LLM call with caching ```bash node scripts/cache.js query "Your question here" ``` This checks cache first. On miss, calls OpenAI, caches the result, and returns it. ## When to Use This Skill - Before making any LLM API call, check if a semantically similar query was already answered - When building agents that answer repetitive questions (support bots, FAQ systems) - When you want to reduce OpenAI/Anthropic API costs by 40-80% - When you need faster response times for common queries ## Configuration Set these environment variables: - `REDIS_URL` — Redis connection string with vector search support (Redis Cloud or Redis Stack) - `OPENAI_API_KEY` — For generating embeddings - `SEMANTIC_CACHE_THRESHOLD` — Similarity threshold 0-1 (default: 0.80, higher = stricter matching) - `SEMANTIC_CACHE_TTL` — Cache TTL in seconds (default: 86400 = 24 hours) ## Example Workflow ``` User: "How do I reset my password?" -> Embed query -> Search Redis -> MISS -> Call LLM -> Get response -> Cache it -> Return response User: "I forgot my password, how do I change it?" -> Embed query -> Search Redis -> HIT (92.7% similar) -> Return cached response in 8ms (saved ~2 seconds + API cost) ``` ## Performance - Cache lookup: ~5-15ms (vs 1-5 seconds for LLM call) - Embedding generation: ~50-100ms - Storage per entry: ~6KB (1536-dim vector + metadata) - Supports millions of cached entries

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 semantic-cache-1776017955 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 semantic-cache-1776017955 技能

通过命令行安装

skillhub install semantic-cache-1776017955

下载 Zip 包

⬇ 下载 semantic-cache v1.0.0

文件大小: 13.18 KB | 发布时间: 2026-4-13 11:55

v1.0.0 最新 2026-4-13 11:55
Initial release — Redis vector search cache for LLM API calls. Cache by meaning, not exact match. 77x faster responses on cache hits.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部