Redis is a real-time data platform that supports a variety of use cases for everyday applications as well as AI/ML workloads. Use Redis as a low-latency vector engine by creating a Redis database with the Redis Stack docker container. For a hosted/managed solution, try Redis Cloud. See more helpful examples of Redis as a vector database here.
- The database needs the RediSearch module (>=v2.6) and RedisJSON, which are included in the self-hosted docker compose above.
- Run the App with the Redis docker image:
docker compose up -d
in this dir. - The app automatically creates a Redis vector search index on the first run. Optionally, create a custom index with a specific name and set it as an environment variable (see below).
- To enable more hybrid searching capabilities, adjust the document schema here.
Environment Variables:
Name | Required | Description | Default |
---|---|---|---|
DATASTORE |
Yes | Datastore name, set to redis |
|
BEARER_TOKEN |
Yes | Secret token | |
OPENAI_API_KEY |
Yes | OpenAI API key | |
REDIS_HOST |
Optional | Redis host url | localhost |
REDIS_PORT |
Optional | Redis port | 6379 |
REDIS_PASSWORD |
Optional | Redis password | none |
REDIS_INDEX_NAME |
Optional | Redis vector index name | index |
REDIS_DOC_PREFIX |
Optional | Redis key prefix for the index | doc |
REDIS_DISTANCE_METRIC |
Optional | Vector similarity distance metric | COSINE |
REDIS_INDEX_TYPE |
Optional | Vector index algorithm type | FLAT |
In order to test your changes to the Redis Datastore, you can run the following commands:
# Run the Redis stack docker image
docker run -it --rm -p 6379:6379 redis/redis-stack-server:latest
# Run the Redis datastore tests
poetry run pytest -s ./tests/datastore/providers/redis/test_redis_datastore.py