Redis vector database adapter for cognee
Project description
🧠 Cognee Redis Vector Adapter
Features
- Full support for vector embeddings storage and retrieval
- Batch / pipeline operations for efficient processing
- Automatic embedding generation via configurable embedding engines
- JSON payload serialization with UUID support
- Comprehensive error handling
Installation
pip install cognee-community-vector-adapter-redis
Prerequisites
You need a Redis instance with the Redis Search module enabled. You can use:
-
Redis:
docker run -d --name redis -p 6379:6379 redis:8.0.2
-
Redis Cloud with the search module enabled: Redis Cloud
Examples
Checkout the examples/ folder!
uv run examples/example.py
You will need an OpenAI API key to run the example script.
Usage
from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
from cognee_community_vector_adapter_redis import RedisAdapter
# Initialize your embedding engine
embedding_engine = EmbeddingEngine(
model="your-model",
# ... other config
)
# Create Redis adapter
redis_adapter = RedisAdapter(
url="redis://localhost:6379", # Redis connection URL
embedding_engine=embedding_engine,
api_key=None # Optional, not used for Redis but part of interface
)
# Create a collection
await redis_adapter.create_collection("my_collection")
# Add data points
from cognee.infrastructure.engine import DataPoint
data_points = [
DataPoint(id="1", text="Hello world", metadata={"index_fields": ["text"]}),
DataPoint(id="2", text="Redis vector search", metadata={"index_fields": ["text"]})
]
await redis_adapter.create_data_points("my_collection", data_points)
# Search for similar vectors
results = await redis_adapter.search(
collection_name="my_collection",
query_text="Hello Redis",
limit=10
)
# Search with pre-computed vector
query_vector = await redis_adapter.embed_data(["Hello Redis"])
results = await redis_adapter.search(
collection_name="my_collection",
query_vector=query_vector[0],
limit=10,
with_vector=True # Include vectors in results
)
# Batch search
results = await redis_adapter.batch_search(
collection_name="my_collection",
query_texts=["query1", "query2"],
limit=5
)
# Retrieve specific data points
retrieved = await redis_adapter.retrieve(
collection_name="my_collection",
data_point_ids=["1", "2"]
)
# Delete data points
await redis_adapter.delete_data_points(
collection_name="my_collection",
data_point_ids=["1"]
)
# Check if collection exists
exists = await redis_adapter.has_collection("my_collection")
Configuration
The Redis adapter supports the following configuration options:
url: Redis connection URL (e.g., "redis://localhost:6379", "redis://user:pass@host:port")embedding_engine: TheEmbeddingEngineto use for text vectorization (required)api_key: Optional API key parameter (not used for Redis but part of the interface)
Connection URL Examples
# Local Redis
redis_adapter = RedisAdapter(url="redis://localhost:6379", embedding_engine=engine)
# Redis with authentication
redis_adapter = RedisAdapter(url="redis://user:password@localhost:6379", embedding_engine=engine)
# Redis with SSL
redis_adapter = RedisAdapter(url="rediss://localhost:6380", embedding_engine=engine)
Error Handling
The adapter includes comprehensive error handling:
VectorEngineInitializationError: Raised when required parameters are missingCollectionNotFoundError: Raised when attempting operations on non-existent collectionsInvalidValueError: Raised for invalid query parameters- Graceful handling of connection failures and embedding errors
Troubleshooting
Common Issues
- Connection Errors: Ensure Redis is running and accessible at the specified URL
- Search Module Missing: Make sure Redis has the Search module enabled
- Embedding Dimension Mismatch: Verify embedding engine dimensions match index configuration
- Collection Not Found: Always create collections before adding data points
Debug Logging
The adapter uses Cognee's logging system. Enable debug logging to see detailed operation logs:
import logging
logging.getLogger("RedisAdapter").setLevel(logging.DEBUG)
Development
To contribute or modify the adapter:
- Clone the repository and
cdinto theredisfolder - Install dependencies:
uv sync --all-extras - Make sure a Redis instance is running (see above)
- Make your changes, test, and submit a PR
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cognee_community_vector_adapter_redis-0.0.1.tar.gz.
File metadata
- Download URL: cognee_community_vector_adapter_redis-0.0.1.tar.gz
- Upload date:
- Size: 184.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be946d7e8fd11837715f2840639699c413c823c0e3497530ee6907f9b22f82ff
|
|
| MD5 |
a58fa2e5f4a27a55715bb19353e6ac39
|
|
| BLAKE2b-256 |
b3ac709b9da039f2a64c9939efa45b9c46ab614f754f3baca19497d76251fd87
|
File details
Details for the file cognee_community_vector_adapter_redis-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cognee_community_vector_adapter_redis-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b881b80ffcf5f85e1feeac615769fca1c7a5814dd1947d7a37ce86cd103a585
|
|
| MD5 |
41e69641c64d70c2889a776278fceadf
|
|
| BLAKE2b-256 |
27f2d85f6be2266e9becf70f7eef522906283ad93cf9fdea7de07f6b2855bc53
|