An open API service indexing awesome lists of open source software.

https://github.com/aerospike/rag-aerospike

langchain rag template for aerospike
https://github.com/aerospike/rag-aerospike

aerospike langchain nosql rag

Last synced: 7 months ago
JSON representation

langchain rag template for aerospike

Awesome Lists containing this project

README

          

# rag-aerospike

This template performs RAG using Aerospike Vector Search (AVS), HuggingFace embeddings, and an OpenAI LLM. The data set is the [AVS architecture overview]("https://aerospike.com/docs/vector/architecture/components") web page, which is loaded, tokenized, then embedded using the all-MiniLM-L6-v2 sentence transformer. The context and embeddings are stored in the Aerospike Vector Search LangChain vector store.

The chain exposed in this example shows basic usage of the Aerospike Vector Search LangChain vector store as a retriever for RAG applications.

## Environment Setup

Set the `OPENAI_API_KEY` environment variable to access the [OpenAI](https://platform.openai.com) models:
Set `AVS_HOST` (default: localhost) and `AVS_PORT` (default: 5000) to the address for your AVS deployment.
Set `AVS_NAMESPACE` (default: test) to the Aerospike namespace to store vector data and indexes in.
Set `DATASOURCE` (default: "https://aerospike.com/docs/vector/architecture/components") to the URL of a webpage you would like to index. The text from the page will be used as context in the RAG application.

## Usage

To use this package, you should first have the LangChain CLI installed:

```shell
pip install -U langchain-cli
```

Create a new LangChain project:

```shell
langchain app new my-app
```

Change into your new project directory.

```
cd my-app
```

Add the Aerospike RAG langchain template to your new project:

```shell
langchain app add --repo="aerospike/rag-aerospike/" --branch="main"
```

And add the following code to your `server.py` file:
```python
from rag_aerospike import chain as rag_aerospike_chain

add_routes(app, rag_aerospike_chain, path="/rag-aerospike")
```

(Optional) Let's now configure LangSmith.
LangSmith will help us trace, monitor and debug LangChain applications.
You can sign up for LangSmith [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=
export LANGCHAIN_PROJECT= # if not specified, defaults to "default"
```

If you are inside the root directory of this repo, 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-aerospike/playground](http://127.0.0.1:8000/rag-aerospike/playground)

We can access the template from code with:

```python
from langserve.client import RemoteRunnable

runnable = RemoteRunnable("http://localhost:8000/rag-aerospike")
```