ccf74a120f966e9715b409ca599fe0808115513f
RAG Agent with ChromaDB and Tavily
Overview
This repository implements a RAG (Retrieval‑Augmented Generation) agent that can answer questions by searching a local knowledge base stored in ChromaDB or by fetching up‑to‑date information from the web using Tavily. The agent automatically chooses the most appropriate source based on the query and returns the answer together with the source identifier.
Features
- Local Knowledge Base – Vector store backed by ChromaDB with embeddings from Ollama (
nomic-embed-text). - Web Search – Uses Tavily API for real‑time web queries.
- Automatic Routing – The agent decides whether to use the local KB or the web search.
- CLI – Simple command‑line interface for interactive queries.
- Persistence – The ChromaDB store is persisted between runs.
Setup
-
Install Ollama and pull the required models:
ollama pull llama3 ollama pull nomic-embed-text -
Install Python dependencies:
pip install -r requirements.txt -
Set up the Tavily API key. Create a
.envfile in the project root with:TAVILY_API_KEY=your_api_key_here -
Add documents you want to index into the
documents/folder. The script will automatically load.txtand.mdfiles.
Usage
python main.py
You will be prompted for a query. Type exit to quit.
Example:
Query: Какие последние новости про AI-агентов?
Answer:
[Web Search]
1. AI Agents are ...
https://example.com
...
Source: tavily
Project Structure
vectorstore.py– Helper functions for creating and populating the ChromaDB vector store.agent.py– Defines the tools and initializes the LangChain agent.main.py– CLI entry point.requirements.txt– Python dependencies.README.md– Documentation.
Notes
- The agent uses the Zero‑Shot React strategy. It may call both tools if the query is ambiguous. You can tweak the prompt or the routing logic if needed.
- The ChromaDB store is persisted in
./chroma_db. Delete this folder to re‑index. - Ensure the Ollama server is running locally when executing the agent.
Description
Languages
Python
100%