langchain-redis
CLAUDE.md67 starsChanged 12 days agoMITView on GitHub
The project is structured as a monorepo with the main library at libs/redis/. All development commands should be run from libs/redis/: Poetry manages dependencies; some users also use it to automatically manage Python virtual environments. In this repository you may encounter a project virtual environment already created locally. Common locations: - The repository root - libs/redis/env/ Common directory names: - .venv - env - venv Recommended workflow: 1) If a virtual environment exists in the repo, activate it first, then…
- Reads credentials
The file
We split this CLAUDE.md into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
If a virtual environment exists in the repo, activate it first, then run Python or make commands:
- Very specific: line 33
If poetry is available on your PATH without activating a venv, you can try to use it directly:
- Very specific: line 41
If you run poetry or make and see poetry: command not found, Poetry is not on your PATH.
- Very specific: line 83
All components use the centralized RedisConfig class (config.py) which provides:
- Distinctive: line 107
Document storage in either hash or JSON format
- Distinctive: line 116
All three integrate with LangChain's caching interface and support async operations.
- Distinctive: line 143
All major classes (RedisVectorStore, RedisConfig, RedisCache, etc.) should be imported from the top-level package.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development Commands
The project is structured as a monorepo with the main library at libs/redis/. All development commands should be run from libs/redis/:
cd libs/redisVirtual Environments
Poetry manages dependencies; some users also use it to automatically manage Python virtual environments.
In this repository you may encounter a project virtual environment already created locally. Common locations:
- The repository root
libs/redis/env/
Common directory names:
.venvenvvenv
Recommended workflow:
- If a virtual environment exists in the repo, activate it first, then run Python or
makecommands:
source .venv/bin/activate # or: source libs/redis/env/bin/activate
make test # or any other Make target- If
poetryis available on your PATH without activating a venv, you can try to use it directly:
# From libs/redis/
make test
# or explicitly
poetry run pytest tests/unit_tests/test_specific.py- If you run
poetryormakeand seepoetry: command not found, Poetry is not on your PATH. Try to activate the project's virtual environment to see if it already contains Poetry (e.g.,source libs/redis/env/bin/activate). If it doesn't, ask the user if you should install it.
Notes:
- Makefile targets call
poetry run .... When a venv is activated and contains Poetry,makewill use that Poetry and run inside that venv. When Poetry is on PATH globally, it will use its managed venv and you do not need to activate one manually. - Quick checks:
which poetryTEST_FILE=tests/unit_tests/test_specific.py make test
Testing
make test- Run unit testsmake integration_tests- Run integration tests (requires OPENAI_API_KEY)TEST_FILE=tests/unit_tests/test_specific.py make test- Run specific test file
Linting and Formatting
make lint- Run linters (ruff + mypy)make format- Auto-format codemake check_imports- Validate import structuremake spell_check- Check spelling with codespell
Dependencies
poetry install --with test- Install unit test dependenciespoetry install --with test,test_integration- Install all test dependenciespoetry install --with lint,typing,codespell,test,test_integration- Install all development dependencies
Architecture
Core Components
The library provides three main integrations with Redis:
- RedisVectorStore (
vectorstores.py) - Vector storage and similarity search - RedisCache/RedisSemanticCache/LangCacheSemanticCache (
cache.py) - LLM response caching - RedisChatMessageHistory (
chat_message_history.py) - Chat message persistence (deprecated since 0.2.6, removal planned for 1.0.0)
Configuration System
All components use the centralized RedisConfig class (config.py) which provides:
- Multiple initialization patterns (from_kwargs, from_schema, from_yaml, etc.)
- Pydantic-based validation with smart defaults
- Schema management for Redis index structures
- Connection handling (redis_client or redis_url)
Key design patterns:
- Config validates that only one of
index_schema,schema_path, ormetadata_schemais specified key_prefixdefaults toindex_nameif not provided- ULID-based default index names for uniqueness
vector_attrspasses algorithm-specific tuning (HNSW, SVS-VAMANA) into the vector fieldkey_prefixmay be a list: searches span all prefixes, writes use the first (primary_prefix)stopwordssets index-level stopwords (None= Redis default,[]= disabled)
Vector Store Implementation
RedisVectorStore uses RedisVL (Redis Vector Library) underneath:
- Supports FLAT, HNSW, and SVS-VAMANA indexing algorithms
- Multiple distance metrics (COSINE, L2, IP)
- Metadata filtering via RedisVL FilterExpression
- Hybrid (full-text + vector) search and full-text-only search
- Filter-based deletion via
delete_by_filter(supportsdry_run);delete()is id-only - Reads and deletes are scoped to the index via an internal
_index_nameownership marker - Custom cosine similarity implementation with optional simsimd acceleration
- Document storage in either hash or JSON format
Cache Implementation
Three cache types:
RedisCache- Standard key-value caching with TTLRedisSemanticCache- Uses embeddings for similarity-based cache hitsLangCacheSemanticCache- Uses the managed LangCache service; embeddings are computed server-side
All three integrate with LangChain's caching interface and support async operations.
Chat History Implementation
RedisChatMessageHistory is deprecated (since 0.2.6, removal in 1.0.0); LangChain recommends short-term memory instead. Maintain it, but don't extend it.
RedisChatMessageHistory provides:
- JSON-based message storage with Redis search indexing
- Message type handling (Human, AI, System, Tool)
- TTL support for automatic expiration
- Full-text search capabilities via Redis FT module
Testing Patterns
- Unit tests in
tests/unit_tests/- no external dependencies - Integration tests in
tests/integration_tests/- require Redis and OpenAI - Uses pytest with async support
conftest.pyprovides shared fixtures- Integration tests use testcontainers for Redis instances
Import Structure
The library follows a clean import pattern:
- Main exports in
__init__.py - Version info in
version.pywith both__version__and__lib_name__ - Core functionality split by concern (config, vectorstores, cache, chat_history)
All major classes (RedisVectorStore, RedisConfig, RedisCache, etc.) should be imported from the top-level package.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

