This project implements a Retrieval-Augmented Generation (RAG) agent using Langgraph, Ollama, and Llama3.2. The agent can perform document retrieval, web searches, and generate answers based on the retrieved information.
- Python 3.8+
- Ollama (for running Llama3.2 locally)
- Pinecone (for vector storage and retrieval)
- Tavily API key (for web search functionality)
-
Clone this repository:
git clone https://github.com/yourusername/langgraph_rag_agent.git cd langgraph_rag_agent -
Create a virtual environment and activate it:
python -m venv .venv source .venv/bin/activate # On Windows, use `.venv\Scripts\activate` -
Install the required packages:
pip install -r requirements.txt -
Install Ollama:
curl -fsSL https://ollama.com/install.sh | sh -
Pull the Llama3.2 model:
ollama pull llama3.2:3b
-
Create a
.envfile in the project root directory. -
Set the following environment variables in the
.envfile:PINECONE_API_KEY: Your Pinecone API keyOLLAMA_MODEL: llama3.2:3bPINECONE_INDEX_NAME: Name of your Pinecone indexCOHERE_API_KEY: Your Cohere API key for embeddingsTAVILY_API_KEY: Your Tavily API key for web search functionalityEMBEDDING_MODEL: embed-multilingual-v3.0RETRIEVER_K: set the amount of docs u want to retrieve per queryWEB_SEARCH_K: set the amount of web searches for one query
To run the Langgraph RAG agent, execute the following command:
python main.py
The agent will prompt you to enter a question and a namespace for the Pinecone index.
main.py: Entry point of the applicationagent.py: Implements the Langgraph agent logicutils/:config.py: Configuration managementllm.py: Ollama LLM integrationretriever.py: Document retrieval using Pineconetools.py: Web search tool implementationstate.py: State management for Langgraph
- Retriever: Uses Pinecone for vector storage and retrieval, with Cohere embeddings.
- Web Search: Utilizes Tavily for web search functionality.
- LLM: Integrates Ollama to run Llama3.2 locally for answer generation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.