This repository provides the materials for the joint Redis/Microsoft blog post here. It contains a Jupyter notebook that demonstrates how to use Redis as a vector database to store and retrieve document vectors. The notebook also shows how to use LlamaIndex to perform semantic search for context within documents and provide a chatbot-like experience using OpenAI.
LlamaIndex-example.mov
The tutorial can run in multiple ways. The first step is to configure the .env
file in this repository. This file contains the following variables:
OPENAI_TEXT_MODEL=text-davinci-003
OPENAI_DEPLOYMENT_TYPE=Text
OPENAI_EMBEDDING_MODEL=text-embedding-ada-002
OPENAI_EMBEDDINGS_ENGINE_QUERY=text-embedding-ada-002
OPENAI_API_KEY=<your key here>
OPENAI_TEMPERATURE=0.7
OPENAI_MAX_TOKENS=50
CHUNK_SIZE=500
CHUNK_OVERLAP=100
AZURE_EMBED_MODEL_DEPLOYMENT_NAME=<your deployment name here>
AZURE_TEXT_MODEL_DEPLOYMENT_NAME=<your deployment name here>
AZURE_OPENAI_API_BASE=https://<your deployment name>.openai.azure.com/
OPENAI_API_BASE=https://api.openai.com/v1/
REDIS_ADDRESS=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
To use Azure OpenAI, you will need to follow these instructions
- Create an Azure OpenAI resource
- Create model deployments for the text and embedding models
- Configure the
.env
file adding the specific values for your deployments
AZURE_EMBED_MODEL_DEPLOYMENT_NAME=<your deployment name here>
AZURE_TEXT_MODEL_DEPLOYMENT_NAME=<your deployment name here>
AZURE_OPENAI_API_BASE=https://<your deployment name>.openai.azure.com/
To use OpenAI, you will need to follow these instructions
- Create an OpenAI account
- Create an OpenAI API key
- Configure the
.env
file adding the specific values for your deployments
OPENAI_API_KEY=<your key here>
The tutorial will require the usage of the Redis-stack container because of the use of RediSearch and RedisJSON. There are three options for Redis
- Redis Enterprise Cloud
- Azure Redis Enterprise (ACRE)
- Redis Stack (docker)
- Redis Stack (local)
For each, the following options are required
REDIS_PASSWORD=<your password here>
REDIS_ADDRESS=<your redis address here>
REDIS_PORT=<your redis port here>
There are some docker-compose.yml
files in the docker
directory that will help spin up
redis-stack locally and redisinsight in the case where a remote Redis is being used (like ACRE).
To run the script, follow these steps:
- Clone this repository to your local machine.
- copy the
.env.template
to.env
and configure the values as outlined above. - If using a local Python environment, just run the notebook
- Otherwise, select a docker-compose file to run and execute
docker-compose up
to start the environment.