mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 23:41:46 +00:00
Readme rewrite (#12615)
Co-authored-by: Lance Martin <lance@langchain.dev> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
# Redis RAG Example
|
||||
|
||||
Using Langserve and Redis to build a RAG search example for answering questions on financial 10k filings docs (for Nike).
|
||||
# rag-redis
|
||||
|
||||
Relies on the sentence transformer `all-MiniLM-L6-v2` for embedding chunks of the pdf and user questions.
|
||||
This template performs RAG using Redis and OpenAI on financial 10k filings docs (for Nike).
|
||||
|
||||
## Running Redis
|
||||
It relies on the sentence transformer `all-MiniLM-L6-v2` for embedding chunks of the pdf and user questions.
|
||||
|
||||
There are a number of ways to run Redis depending on your use case and scenario.
|
||||
## Environment Setup
|
||||
|
||||
### Easiest? Redis Cloud
|
||||
Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.
|
||||
|
||||
Create a free database on [Redis Cloud](https://redis.com/try-free). *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.
|
||||
The following Redis environment variables need to be set:
|
||||
|
||||
```bash
|
||||
export REDIS_HOST = <YOUR REDIS HOST>
|
||||
@@ -21,29 +18,6 @@ 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:
|
||||
|
||||
```bash
|
||||
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](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:
|
||||
|
||||
```bash
|
||||
poetry shell
|
||||
python ingest.py
|
||||
```
|
||||
|
||||
## Supported Settings
|
||||
We use a variety of environment variables to configure this application
|
||||
|
||||
@@ -57,21 +31,61 @@ We use a variety of environment variables to configure this application
|
||||
| `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" |
|
||||
|
||||
## Usage
|
||||
|
||||
To use this package, you should first have the LangChain CLI installed:
|
||||
|
||||
## Installation
|
||||
To create a langserve application using this template, run the following:
|
||||
```bash
|
||||
langchain app new my-langserve-app
|
||||
cd my-langserve-app
|
||||
```shell
|
||||
pip install -U "langchain-cli[serve]"
|
||||
```
|
||||
|
||||
Add this template:
|
||||
```bash
|
||||
To create a new LangChain project and install this as the only package, you can do:
|
||||
|
||||
```shell
|
||||
langchain app new my-app --package rag-redis
|
||||
```
|
||||
|
||||
If you want to add this to an existing project, you can just run:
|
||||
|
||||
```shell
|
||||
langchain app add rag-redis
|
||||
```
|
||||
|
||||
Start the server:
|
||||
```bash
|
||||
And add the following code to your `server.py` file:
|
||||
```python
|
||||
from rag_redis.chain import chain as rag_redis_chain
|
||||
|
||||
add_routes(app, rag_redis_chain, path="/rag-redis")
|
||||
```
|
||||
|
||||
(Optional) Let's now configure LangSmith.
|
||||
LangSmith will help us trace, monitor and debug LangChain applications.
|
||||
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
|
||||
If you don't have access, you can skip this section
|
||||
|
||||
|
||||
```shell
|
||||
export LANGCHAIN_TRACING_V2=true
|
||||
export LANGCHAIN_API_KEY=<your-api-key>
|
||||
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
|
||||
```
|
||||
|
||||
If you are inside this directory, then you can spin up a LangServe instance directly by:
|
||||
|
||||
```shell
|
||||
langchain serve
|
||||
```
|
||||
|
||||
This will start the FastAPI app with a server is running locally at
|
||||
[http://localhost:8000](http://localhost:8000)
|
||||
|
||||
We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
||||
We can access the playground at [http://127.0.0.1:8000/rag-redis/playground](http://127.0.0.1:8000/rag-redis/playground)
|
||||
|
||||
We can access the template from code with:
|
||||
|
||||
```python
|
||||
from langserve.client import RemoteRunnable
|
||||
|
||||
runnable = RemoteRunnable("http://localhost:8000/rag-redis")
|
||||
```
|
Reference in New Issue
Block a user