skills/langchain-redis/SKILL.md
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).
npx skillsauth add enuno/claude-command-and-control langchain-redisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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).
Activate when:
RedisVectorStore to store and search document embeddingsRedisCache (exact match) or RedisSemanticCache (similarity-based)distance_threshold on RedisSemanticCacheRedisChatMessageHistory to store multi-turn conversationsredisvl.query.filter tags/ranges with similarity_searchredis_client instead of redis_urlRedisConfig for index settings and distance metricsfrom 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"])
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
)
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),
)
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
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
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()
from langchain_redis import RedisChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini")
def get_session_history(session_id: str) -> RedisChatMessageHistory:
return RedisChatMessageHistory(
session_id=session_id,
redis_url="redis://localhost:6379",
ttl=3600,
)
chain_with_history = RunnableWithMessageHistory(llm, get_session_history)
response = chain_with_history.invoke(
"What is the capital of France?",
config={"configurable": {"session_id": "user-123"}},
)
RedisVectorStore key parameters| Param | Type | Default | Description |
|-------|------|---------|-------------|
| index_name | str | — | Name of the Redis search index |
| embeddings | Embeddings | — | Embedding function |
| redis_url | str | — | Redis connection URL |
| redis_client | Redis \| None | None | Pre-existing Redis client (overrides url) |
| distance_metric | str | "COSINE" | COSINE, IP, or L2 |
| indexing_algorithm | str | "FLAT" | FLAT or HNSW |
| ttl | int \| None | None | Key expiry in seconds |
RedisSemanticCache key parameters| Param | Type | Default | Description |
|-------|------|---------|-------------|
| embeddings | Embeddings | — | Embedding function for prompt encoding |
| redis_url | str | "redis://localhost:6379" | Redis connection URL |
| distance_threshold | float | 0.2 | Max distance for cache hit (lower=stricter) |
| ttl | int \| None | None | Cache entry expiry in seconds |
| redis_client | Redis \| None | None | Pre-existing Redis client |
RedisChatMessageHistory key parameters| Param | Type | Default | Description |
|-------|------|---------|-------------|
| session_id | str | — | Unique conversation identifier |
| redis_url | str | "redis://localhost:6379" | Redis connection URL |
| ttl | int \| None | None | Session expiry in seconds |
| key_prefix | str | "chat:" | Redis key prefix |
| redis_client | Redis \| None | None | Pre-existing Redis client |
| overwrite_index | bool | False | Overwrite existing index if present |
distance_threshold tuning guide| Value | Behavior | Use when |
|-------|----------|----------|
| 0.0–0.05 | Very strict — near-identical prompts only | High precision needed |
| 0.1–0.15 | Strict — same question, different wording | Production default |
| 0.2 | Moderate (default) — semantically similar | General use |
| 0.3+ | Loose — related but different questions may match | High cache hit rate |
| File | Size | Contents |
|------|------|----------|
| references/api.md | 500 KB | Full API reference (all params, methods) |
| references/llms.md | 28 KB | Doc index |
| references/llms-full.md | 500 KB | Complete page content |
Requires: Redis Stack (not plain Redis) — redis/redis-stack-server Docker image or Redis Cloud.
Source: https://reference.langchain.com/python/langchain-redis
GitHub: https://github.com/langchain-ai/langchain-redis
tools
MemPalace local-first AI memory system. Use when setting up persistent memory for Claude Code sessions, mining project files or conversation transcripts, querying past context, configuring MCP tools, managing the knowledge graph, or troubleshooting palace operations.
tools
LangSmith Python SDK — trace, evaluate, and monitor LLM applications. Covers @traceable decorator, trace context manager, Client API, evaluate() / aevaluate(), comparative evaluation, custom evaluators, dataset management, prompt caching, ASGI middleware, and pytest plugin.
development
LangGraph (Python) — build stateful, controllable agent graphs with checkpointing, streaming, persistence, interrupts, fault tolerance, and durable execution. Covers both Graph API (StateGraph) and Functional API (@entrypoint/@task).
development
LangGraph Graph API (Python) — build explicit DAG agent workflows with StateGraph, typed state, nodes, edges, Command routing, Send fan-out, checkpointers, interrupts, and streaming. Use when you need explicit control flow and graph topology.