LangChain RAG integration
LangChain RAG integration example offers a guide to setting up and using RAG (retrieval augmented generation) technology in a uagent. This example shows how to create a RAG application that can answer question based on a document.
- Python (v3.10+ recommended)
- Poetry (A Python packaging and dependency management tool)
Setup
-
For the demo to work, you need to get some API keys:
-
Visit the Cohere website.
-
Sign up or log in.
-
Navigate to
API Keys. -
Copy an existing key or create a new one.
-
Visit the OpenAI website.
-
Sign up or log in.
-
Navigate to the API section to obtain your API key.
Note that if you’ve run out of OpenAI credits, you will not be able to get results for this example.
-
-
In the
langchain-rag/srcdirectory, create a.envfile and set your API keys and the agent seed:export COHERE_API_KEY="{GET THE API KEY}" export OPENAI_API_KEY="{GET THE API KEY}" export LANGCHAIN_RAG_SEED="{random string that determines your agent's address}" -
In the
langchain-ragdirectory install all dependenciespoetry install -
To load the environment variables from `.env:
cd src source .env
Running The Main Script
To run the project, use the command:
poetry run python main.py
After running the command, a request is sent to the agent in every minute. The results can be seen in the console. Look for the following output in the logs:
Adding RAG agent to Bureau: {agent_address}
Copy the {agent_address} value and replace RAG_AGENT_ADDRESS with this value in src/langchain_rag_user.py.
In the src/langchain_rag_user.py file, there are variables QUESTION, URL, DEEP_READ. Change the value of these variables to customize the question you want to get answered. Default values are:
QUESTION = "How to install uagents using pip"
URL = "https://fetch.ai/docs/guides/agents/installing-uagent"
DEEP_READ = "no" # it means nested pages at the URL won't be parsed, just the actual URL
Now you can enjoy answering questions with LangChain RAG agent!