Skip to main content

Redis vector database adapter for cognee

Project description

Redis

🧠 Cognee Redis Vector Adapter

Blazing fast vector similarity search for Cognee using Redis

License: Apache 2.0 Language

Powered by RedisVL

Cognee    RedisVL Docs    Examples    Support

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:

  1. Redis:

    docker run -d --name redis -p 6379:6379 redis:8.0.2
    
  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: The EmbeddingEngine to 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 missing
  • CollectionNotFoundError: Raised when attempting operations on non-existent collections
  • InvalidValueError: Raised for invalid query parameters
  • Graceful handling of connection failures and embedding errors

Troubleshooting

Common Issues

  1. Connection Errors: Ensure Redis is running and accessible at the specified URL
  2. Search Module Missing: Make sure Redis has the Search module enabled
  3. Embedding Dimension Mismatch: Verify embedding engine dimensions match index configuration
  4. 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:

  1. Clone the repository and cd into the redis folder
  2. Install dependencies: uv sync --all-extras
  3. Make sure a Redis instance is running (see above)
  4. 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

cognee_community_vector_adapter_redis-0.0.1.tar.gz (184.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file cognee_community_vector_adapter_redis-0.0.1.tar.gz.

File metadata

File hashes

Hashes for cognee_community_vector_adapter_redis-0.0.1.tar.gz
Algorithm Hash digest
SHA256 be946d7e8fd11837715f2840639699c413c823c0e3497530ee6907f9b22f82ff
MD5 a58fa2e5f4a27a55715bb19353e6ac39
BLAKE2b-256 b3ac709b9da039f2a64c9939efa45b9c46ab614f754f3baca19497d76251fd87

See more details on using hashes here.

File details

Details for the file cognee_community_vector_adapter_redis-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cognee_community_vector_adapter_redis-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b881b80ffcf5f85e1feeac615769fca1c7a5814dd1947d7a37ce86cd103a585
MD5 41e69641c64d70c2889a776278fceadf
BLAKE2b-256 27f2d85f6be2266e9becf70f7eef522906283ad93cf9fdea7de07f6b2855bc53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page