Update README.md

This commit is contained in:
2026-06-02 07:47:05 +00:00
parent 106a713237
commit 52541e5c6a
+50 -48
View File
@@ -1,77 +1,79 @@
# RAGAgent with ChromaDB and Web Search # RAG Agent with ChromaDB and Tavily
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. This repository contains a lightweight RAG (RetrievalAugmented Generation) agent that:
## Features 1. Stores local knowledge in **ChromaDB** using **Ollama** embeddings.
2. Performs semantic search over the local store.
3. Falls back to **Tavily** web search for uptodate information.
4. Decides automatically which source to use and indicates the source in the answer.
* **Local semantic search** Uses a ChromaDB vector store backed by Ollama embeddings. ## Prerequisites
* **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 * Python 3.10+ (recommended via `pyenv` or `conda`).
* [Ollama](https://ollama.ai/) installed locally.
* A Tavily API key set it in a `.env` file.
```bash ```bash
# 1. Clone the repo # Pull the required models
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 llama3
ollama pull nomic-embed-text ollama pull nomic-embed-text
```
# 5. Set Tavily API key ## Installation
export TAVILY_API_KEY=your_api_key # Windows: set TAVILY_API_KEY=your_api_key
# 6. Prepare documents ```bash
# Place any .txt or .md files you want to index in the ./documents folder. pip install -r requirements.txt
# They will be automatically loaded into ChromaDB on first run.
# 7. Run the agent
python main.py
``` ```
## Usage ## Usage
```text ```bash
Запрос: Какие последние новости про AI-агентов? # Create a .env file with your Tavily key
[Web Search] # TAVILY_API_KEY=YOUR_KEY
1. AI Agents: The Future of Automation: ...
2. ...
Source: tavily
Запрос: Что в наших конспектах про LangGraph? # Populate the vector store from the documents folder
[Local KB] python main.py
1. LangGraph is a ...
2. ...
Source: chromadb
``` ```
You will be presented with a prompt. Type your question and press **Enter**.
Type `exit` to quit.
## Project Structure ## Project Structure
``` ```
├── agent.py # Core agent logic and tools ├── agent.py # Agent definition
├── vectorstore.py # ChromaDB creation and document loading
├── rag_tools.py # Web search tool
├── main.py # CLI entry point ├── main.py # CLI entry point
├── tools.py # Local KB and web search tools
├── vectorstore.py # ChromaDB helpers
├── requirements.txt ├── requirements.txt
── README.md ── README.md
└── documents/ # Folder with .txt/.md files to ingest
``` ```
## How It Works
1. **Vector Store** `vectorstore.py` creates a ChromaDB instance backed by
`OllamaEmbeddings`. Documents from `documents/` are chunked with
`RecursiveCharacterTextSplitter` and added to the store.
2. **Tools** `tools.py` exposes two LangChain tools:
* `search_local_kb` semantic search in ChromaDB.
* `web_search` web search via Tavily.
3. **Agent** `agent.py` builds an OpenAIfunctionsstyle agent that
chooses between the two tools based on the users query. The system prompt
instructs the LLM to use `search_local_kb` for knowledgebase queries and
`web_search` for recent facts. The answer always contains a source tag.
4. **CLI** `main.py` ties everything together: it loads the vector store,
creates the agent and runs an interactive chat loop.
## Extending ## Extending
* **Add more tools** Define new functions decorated with `@tool` and add them to the `tools` list. * Replace the LLM with any other LangChaincompatible model.
* **Change LLM** Swap `ChatOllama` for another provider (e.g., OpenAI) by adjusting the import and model name. * Add more tools (e.g., database queries, file system access).
* **Custom prompt** Edit `agent_prompt` in `agent.py` to modify the agents instruction. * Persist the vector store across runs it already does this via `persist_directory`.
--- ---
Happy querying! Happy experimenting!