93a1cc8a61aca1970ca89b75627a5d291bf45235
RAG‑Agent with ChromaDB and Web Search
This repository implements a simple RAG (Retrieval‑Augmented Generation) agent that can answer questions using a local knowledge base stored in ChromaDB or by searching the web via Tavily. The agent automatically chooses the appropriate source and reports it in the answer.
Features
- Local semantic search – Uses a ChromaDB vector store backed by Ollama embeddings.
- Web search – Uses Tavily to fetch up‑to‑date information.
- Automatic source selection – The agent decides whether to query the local KB or the web.
- Persisted vector store – Data is stored on disk and reused across runs.
- Simple CLI – Chat loop with
exitto quit.
Setup
# 1. Clone the repo
git clone <repo-url>
cd <repo-dir>
# 2. (Optional) Create a virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Pull required Ollama models
ollama pull llama3
ollama pull nomic-embed-text
# 5. Set Tavily API key
export TAVILY_API_KEY=your_api_key # Windows: set TAVILY_API_KEY=your_api_key
# 6. Prepare documents
# Place any .txt or .md files you want to index in the ./documents folder.
# They will be automatically loaded into ChromaDB on first run.
# 7. Run the agent
python main.py
Usage
Запрос: Какие последние новости про AI-агентов?
[Web Search]
1. AI Agents: The Future of Automation: ...
2. ...
Source: tavily
Запрос: Что в наших конспектах про LangGraph?
[Local KB]
1. LangGraph is a ...
2. ...
Source: chromadb
Project Structure
├── agent.py # Core agent logic and tools
├── vectorstore.py # ChromaDB creation and document loading
├── rag_tools.py # Web search tool
├── main.py # CLI entry point
├── requirements.txt
└── README.md
Extending
- Add more tools – Define new functions decorated with
@tooland add them to thetoolslist. - Change LLM – Swap
ChatOllamafor another provider (e.g., OpenAI) by adjusting the import and model name. - Custom prompt – Edit
agent_promptinagent.pyto modify the agent’s instruction.
Happy querying!
Description
Languages
Python
100%