langchain/templates/rag-redis
David Duong d39b4b61b6
Batch apply poetry lock --no-update for all templates (#12531)
Ran the following bash script for all templates

```bash
#!/bin/bash

set -e
current_dir="$(pwd)"
for directory in */; do
    if [ -d "$directory" ]; then
        (cd "$directory" && poetry lock --no-update)
    fi
done

cd "$current_dir"
```

Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-10-30 15:18:53 -07:00
..
data Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00
rag_redis notebook fmt (#12498) 2023-10-29 15:50:09 -07:00
tests Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00
ingest.py notebook fmt (#12498) 2023-10-29 15:50:09 -07:00
LICENSE Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00
poetry.lock Batch apply poetry lock --no-update for all templates (#12531) 2023-10-30 15:18:53 -07:00
pyproject.toml Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00
rag_redis.ipynb notebook fmt (#12498) 2023-10-29 15:50:09 -07:00
README.md Redis langserve template (#12443) 2023-10-28 08:31:12 -07:00

Redis RAG Example

Using Langserve and Redis to build a RAG search example for answering questions on financial 10k filings docs (for Nike).

Relies on the sentence transformer all-MiniLM-L6-v2 for embedding chunks of the pdf and user questions.

Running Redis

There are a number of ways to run Redis depending on your use case and scenario.

Easiest? Redis Cloud

Create a free database on Redis Cloud. No credit card information is required. Simply fill out the info form and select the cloud vendor of your choice and region.

Once you have created an account and database, you can find the connection credentials by clicking on the database and finding the "Connect" button which will provide a few options. Below are the environment variables you need to configure to run this RAG app.

export REDIS_HOST = <YOUR REDIS HOST>
export REDIS_PORT = <YOUR REDIS PORT>
export REDIS_USER = <YOUR REDIS USER NAME>
export REDIS_PASSWORD = <YOUR REDIS PASSWORD>

For larger use cases (greater than 30mb of data), you can certainly created a Fixed or Flexible billing subscription which can scale with your dataset size.

Redis Stack -- Local Docker

For local development, you can use Docker:

docker run -p 6397:6397 -p 8001:8001 redis/redis-stack:latest

This will run Redis on port 6379. You can then check that it is running by visiting the RedisInsight GUI at http://localhost:8001.

This is the connection that the application will try to use by default -- local dockerized Redis.

Data

To load the financial 10k pdf (for Nike) into the vectorstore, run the following command from the root of this repository:

poetry shell
python ingest.py

Supported Settings

We use a variety of environment variables to configure this application

Environment Variable Description Default Value
DEBUG Enable or disable Langchain debugging logs True
REDIS_HOST Hostname for the Redis server "localhost"
REDIS_PORT Port for the Redis server 6379
REDIS_USER User for the Redis server ""
REDIS_PASSWORD Password for the Redis server ""
REDIS_URL Full URL for connecting to Redis None, Constructed from user, password, host, and port if not provided
INDEX_NAME Name of the vector index "rag-redis"

Installation

To create a langserve application using this template, run the following:

langchain serve new my-langserve-app
cd my-langserve-app

Add this template:

langchain serve add rag-redis

Start the server:

langchain start