Update README.md

This commit is contained in:
RK-A committed 2026-06-02 07:11:07 +00:00
1 parent ccf74a120f
commit 6f89ea202a
1 file changed
+38 -42
+38 -42
View File
@@ -1,66 +1,62 @@
# RAG Agent with ChromaDB and Tavily # RAG Agent with ChromaDB and Web Search
## Overview This repository implements a simple RAG (Retrieval‑Augmented Generation) agent that can answer questions using a local knowledge base stored in **ChromaDB** and also perform real‑time web search via **Tavily**. The agent automatically decides which source to use and reports the chosen source in the answer.
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 ## Features
- **Local Knowledge Base** – Vector store backed by ChromaDB with embeddings from Ollama (`nomic-embed-text`). - **Local knowledge base** – Text files (.txt, .md) are loaded, chunked, and stored in a persistent ChromaDB collection.
- **Web Search** – Uses Tavily API for real‑time web queries. - **Semantic search** – Uses Ollama embeddings (`nomic-embed-text`).
- **Automatic Routing** – The agent decides whether to use the local KB or the web search. - **Web search** – Powered by Tavily.
- **CLI** – Simple command‑line interface for interactive queries. - **Automatic source selection** – The agent chooses between local and web search based on the query.
- **Persistence** – The ChromaDB store is persisted between runs. - **CLI** – Simple chat loop with `exit` to quit.
## Setup ## Setup
1. **Install Ollama** and pull the required models: ```bash
```bash # 1. Create a virtual environment (optional but recommended)
ollama pull llama3 python -m venv venv
ollama pull nomic-embed-text source venv/bin/activate # Windows: venv\Scripts\activate
```
2. **Install Python dependencies**: # 2. Install dependencies
```bash pip install -r requirements.txt
pip install -r requirements.txt
```
3. **Set up the Tavily API key**. Create a `.env` file in the project root with: # 3. Pull required Ollama models
```env ollama pull llama3
TAVILY_API_KEY=your_api_key_here ollama pull nomic-embed-text
```
4. **Add documents** you want to index into the `documents/` folder. The script will automatically load `.txt` and `.md` files. # 4. Set your Tavily API key
export TAVILY_API_KEY=YOUR_KEY # Windows: set TAVILY_API_KEY=YOUR_KEY
```
## Usage ## Usage
```bash 1. **Load documents** – Place your `.txt` or `.md` files in the `documents/` folder.
python main.py 2. **Run the agent**
``` ```bash
python agent.py
```
3. **Chat** – Type your question. Type `exit` to quit.
You will be prompted for a query. Type `exit` to quit. ## Example
Example:
``` ```
Query: Какие последние новости про AI-агентов? Query: Какие последние новости про AI-агентов?
Answer: [Web Search] ...
[Web Search] Источник: tavily
1. AI Agents are ...
https://example.com Query: Что в наших конспектах про LangGraph?
... [Local KB] ...
Source: tavily Источник: chromadb
``` ```
## Project Structure ## Project Structure
- `vectorstore.py` – Helper functions for creating and populating the ChromaDB vector store. - `vectorstore.py` – Functions to create and load the ChromaDB vector store.
- `agent.py` – Defines the tools and initializes the LangChain agent. - `rag_tools.py` – Two LangChain tools: `search_local_kb` and `web_search`.
- `main.py` – CLI entry point. - `agent.py` – Main script that sets up the agent and runs the chat loop.
- `requirements.txt` – Python dependencies. - `requirements.txt` – Python dependencies.
- `README.md` – Documentation. - `README.md` – This file.
## Notes ## License
- 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. MIT License.
- 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.