Files
task-6a1864f78a94f887e50d46da/README.md
T
2026-06-01 17:40:41 +00:00

66 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RAG Agent with ChromaDB and Tavily
## Overview
This repository implements a **RAG (RetrievalAugmented Generation) agent** that can answer questions by searching a local knowledge base stored in **ChromaDB** or by fetching uptodate 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 realtime web queries.
- **Automatic Routing** The agent decides whether to use the local KB or the web search.
- **CLI** Simple commandline interface for interactive queries.
- **Persistence** The ChromaDB store is persisted between runs.
## Setup
1. **Install Ollama** and pull the required models:
```bash
ollama pull llama3
ollama pull nomic-embed-text
```
2. **Install Python dependencies**:
```bash
pip install -r requirements.txt
```
3. **Set up the Tavily API key**. Create a `.env` file in the project root with:
```env
TAVILY_API_KEY=your_api_key_here
```
4. **Add documents** you want to index into the `documents/` folder. The script will automatically load `.txt` and `.md` files.
## Usage
```bash
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 **ZeroShot 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 reindex.
- Ensure the Ollama server is running locally when executing the agent.