Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

langchain-redis

БесплатноБез исполняемых скриптовНе проверен

LangChain Redis integration — RedisVectorStore for RAG, RedisCache and RedisSemanticCache for LLM response caching, RedisChatMessageHistory for persistent…

enunoот 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 RedisVectorStore to store and search document embeddings
  • Adding LLM caching — using RedisCache (exact match) or RedisSemanticCache (similarity-based)
  • Tuning semantic cache sensitivity — adjusting distance_threshold on RedisSemanticCache
  • Persisting chat history — using RedisChatMessageHistory to store multi-turn conversations
  • Setting session TTL — configuring auto-expiry on chat history or vector store keys
  • Filtering vector search — using redisvl.query.filter tags/ranges with similarity_search
  • Using a pre-existing Redis client — passing redis_client instead of redis_url
  • Configuring the Redis connection — using RedisConfig for 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

Полный SKILL.md на GitHub

Установить langchain-redis в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/api.mdreferences/index.mdreferences/llms-full.mdreferences/llms.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить langchain-redis с