Files
task-6a1864f78a94f887e50d46da/README.md
T
2026-06-02 07:19:06 +00:00

78 lines
2.3 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.
# RAGAgent with ChromaDB and Web Search
This repository implements a simple RAG (RetrievalAugmented 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 uptodate 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 `exit` to quit.
## Setup
```bash
# 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
```text
Запрос: Какие последние новости про 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 `@tool` and add them to the `tools` list.
* **Change LLM** Swap `ChatOllama` for another provider (e.g., OpenAI) by adjusting the import and model name.
* **Custom prompt** Edit `agent_prompt` in `agent.py` to modify the agents instruction.
---
Happy querying!