langchain-redis
БесплатноБез исполняемых скриптовНе проверенLangChain Redis integration — RedisVectorStore for RAG, RedisCache and RedisSemanticCache for LLM response caching, RedisChatMessageHistory for persistent…
от enuno★ 17 звёзд на GitHubОб этом скилле
LangChain Redis Skill
Expert assistance for langchain-redis: Redis-backed vector store, LLM caching, and chat message history for LangChain applications.
Install:
pip install -U langchain-redis
docker run -p 6379:6379 redis/redis-stack-server:latest
Reference: references/api.md (500 KB — full API reference).
When to Use This Skill
Activate when:
- Building a RAG pipeline — using
RedisVectorStoreto store and search document embeddings - Adding LLM caching — using
RedisCache(exact match) orRedisSemanticCache(similarity-based) - Tuning semantic cache sensitivity — adjusting
distance_thresholdonRedisSemanticCache - Persisting chat history — using
RedisChatMessageHistoryto store multi-turn conversations - Setting session TTL — configuring auto-expiry on chat history or vector store keys
- Filtering vector search — using
redisvl.query.filtertags/ranges withsimilarity_search - Using a pre-existing Redis client — passing
redis_clientinstead ofredis_url - Configuring the Redis connection — using
RedisConfigfor index settings and distance metrics
Quick Reference
RedisVectorStore — vector store for RAG
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
# Create vector store
vector_store = RedisVectorStore(
index_name="my-rag-index",
embeddings=OpenAIEmbeddings(),
redis_url="redis://localhost:6379",
# distance_metric="COSINE", # COSINE | IP | L2
# indexing_algorithm="FLAT", # FLAT | HNSW
# ttl=3600, # optional key expiry in seconds
)
# Add documents
docs = [
Document(page_content="LangChain is an LLM framework.", metadata={"source": "docs"}),
Document(page_content="Redis is an in-memory data store.", metadata={"source": "wiki"}),
]
ids = vector_store.add_documents(docs)
# Similarity search
results = vector_store.similarity_search("What is LangChain?", k=2)
for doc in results:
print(f"* {doc.page_content} [{doc.metadata}]")
# Search with score
results_with_scores = vector_store.similarity_search_with_score("LLM framework", k=1)
# Delete documents
vector_store.delete(ids=["doc-id-to-remove"])
RedisVectorStore — from existing Redis client
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
from redis import Redis
redis_client = Redis.from_url("redis://localhost:6379")
vector_store = RedisVectorStore(
embeddings=OpenAIEmbeddings(),
index_name="my-index",
redis_client=redis_client, # use pre-existing connection
)
RedisVectorStore — filtered search
from redisvl.query.filter import Tag, Num
# Filter by metadata tag
results = vector_store.similarity_search(
"machine learning",
k=5,
filter=Tag("source") == "docs",
)
# Combine filters
results = vector_store.similarity_search(
"neural networks",
k=3,
filter=(Tag("category") == "ai") & (Num("year") >= 2023),
)
RedisCache — exact LLM response cache
from langchain_redis import RedisCache
from langchain_core.globals import set_llm_cache
# Cache exact prompt→response pairs in Redis
cache = RedisCache(redis_url="redis://localhost:6379", ttl=3600)
set_llm_cache(cache)
# All subsequent LLM calls are automatically cached
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini")
response = llm.invoke("What is Redis?") # cached after first call
RedisSemanticCache — similarity-based LLM cache
from langchain_redis import RedisSemanticCache
from langchain_openai import OpenAIEmbeddings
from langchain_core.globals import set_llm_cache
semantic_cache = RedisSemanticCache(
embeddings=OpenAIEmbeddings(),
redis_url="redis://localhost:6379",
distance_threshold=0.15, # 0.0=exact, higher=looser; default 0.2
ttl=7200, # optional expiry in seconds
)
set_llm_cache(semantic_cache)
# "What is Redis?" and "Tell me about Redis" may share a cache entry
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini")
response = llm.invoke("What is Redis?")
similar = llm.invoke("Tell me about Redis") # may hit cache
RedisChatMessageHistory — persistent multi-turn memory
from langchain_redis import RedisChatMessageHistory
from langchain_core.messages import HumanMessage, AIMessage
history = RedisChatMessageHistory(
session_id="user-session-abc123",
redis_url="redis://localhost:6379",
ttl=3600, # auto-expire session after 1 hour
key_prefix="chat:" # Redis key prefix (default: "chat:")
)
# Add messages
history.add_message(HumanMessage(content="Hello!"))
history.add_message(AIMessage(content="Hi! How can I help?"))
# Read history
for msg in history.messages:
print(f"{msg.type}: {msg.content}")
# Clear session
history.clear()
Use RedisChatMessageHistory wi
Установить langchain-redis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл langchain-redis?
LangChain Redis integration — RedisVectorStore for RAG, RedisCache and RedisSemanticCache for LLM response caching, RedisChatMessageHistory for persistent conversation memory, and RedisConfig for connection management. Requires Redis Stack (redis/redis-stack-server).
Как установить скилл langchain-redis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл langchain-redis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic