This template performs RAG using Aerospike Vector Search (AVS), HuggingFace embeddings, and an OpenAI LLM. The data set is the AVS architecture overview 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.
Set the OPENAI_API_KEY
environment variable to access the OpenAI 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.
To use this package, you should first have the LangChain CLI installed:
pip install -U langchain-cli
Create a new LangChain project:
langchain app new my-app
Change into your new project directory.
cd my-app
Add the Aerospike RAG langchain template to your new project:
langchain app add --repo="aerospike/rag-aerospike/" --branch="main"
And add the following code to your server.py
file:
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. If you don't have access, you can skip this section
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 the root directory of this repo, then you can spin up a LangServe instance directly by:
langchain serve
This will start the FastAPI app with a server is running locally at http://localhost:8000
We can see all templates at http://127.0.0.1:8000/docs We can access the playground at http://127.0.0.1:8000/rag-aerospike/playground
We can access the template from code with:
from langserve.client import RemoteRunnable
runnable = RemoteRunnable("http://localhost:8000/rag-aerospike")