Update README.md
This commit is contained in:
@@ -1,79 +1,86 @@
|
|||||||
# RAG Agent with Qdrant and Tavily
|
# RAG Agent with ChromaDB and Tavily Web Search
|
||||||
|
|
||||||
This repository implements an AI agent that can answer questions using a local knowledge base stored in **Qdrant** and up‑to‑date information fetched from the web via **Tavily**. The agent is built with **LangChain 1.x** and **Ollama** for local LLM and embeddings.
|
## Overview
|
||||||
|
|
||||||
## Features
|
This repository contains a simple RAG (Retrieval‑Augmented Generation) agent that can answer user questions by searching a local knowledge base stored in **ChromaDB** and by performing live web searches via **Tavily**. The agent automatically selects the appropriate source and reports it in the answer.
|
||||||
|
|
||||||
* **Local RAG** – Semantic search in Qdrant using Ollama embeddings.
|
The project uses the following stack:
|
||||||
* **Web search** – Tavily integration for real‑time information.
|
|
||||||
* **Automatic source selection** – The LLM decides whether to use the local KB or the web.
|
|
||||||
* **Persistent vector store** – Data is saved in `./qdrant_db` and reused across runs.
|
|
||||||
* **Interactive CLI** – Add documents, ask questions, and see the source.
|
|
||||||
|
|
||||||
## Installation
|
- **Python 3.10+**
|
||||||
|
- **LangChain 1.x** – modern agent framework
|
||||||
|
- **ChromaDB** – local vector store
|
||||||
|
- **Ollama** – LLM (`llama3`) and embeddings (`nomic-embed-text`)
|
||||||
|
- **Tavily** – web search API
|
||||||
|
- **LangGraph** – (not used directly, but required by LangChain 1.x)
|
||||||
|
|
||||||
```bash
|
## Folder structure
|
||||||
# 1. Pull required Ollama models
|
|
||||||
ollama pull llama3
|
|
||||||
ollama pull nomic-embed-text
|
|
||||||
|
|
||||||
# 2. Install Python dependencies
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
# 3. Run Qdrant (Docker recommended)
|
|
||||||
# If you prefer a local binary, download from https://qdrant.tech
|
|
||||||
# Docker command:
|
|
||||||
# docker run -p 6333:6333 qdrant/qdrant
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Start the CLI
|
|
||||||
python -m workspace.task-6a1864f78a94f887e50d46da.cli
|
|
||||||
```
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
|
|
||||||
* `/add <directory>` – Load all `.txt` and `.md` files from the directory into Qdrant.
|
|
||||||
* `/search <question>` – Ask the agent a question.
|
|
||||||
* `/quit` – Exit.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
> /add ./documents
|
|
||||||
Loaded 12 chunks into Qdrant.
|
|
||||||
Documents added.
|
|
||||||
> /search What is LangGraph?
|
|
||||||
Answer:
|
|
||||||
LangGraph is a framework for building ...
|
|
||||||
Source: chromadb
|
|
||||||
```
|
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
* `TAVILY_API_KEY` – Your Tavily API key.
|
|
||||||
|
|
||||||
Create a `.env` file in the project root:
|
|
||||||
|
|
||||||
```
|
|
||||||
TAVILY_API_KEY=your_api_key_here
|
|
||||||
```
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
|
|
||||||
```
|
```
|
||||||
workspace/
|
workspace/
|
||||||
├─ task-6a1864f78a94f887e50d46da/
|
├─ documents/ # .txt/.md files that will be loaded into Chroma
|
||||||
│ ├─ vector_store.py # Qdrant vector store helpers
|
├─ chroma_db/ # persistent Chroma data (created on first run)
|
||||||
│ ├─ tools.py # Local KB and web search tools
|
├─ main.py # CLI entry point
|
||||||
│ ├─ agent.py # Agent definition
|
├─ vectorstore.py # Chroma store helpers
|
||||||
│ ├─ cli.py # Interactive command line
|
├─ tools.py # Agent tools
|
||||||
│ ├─ requirements.txt
|
├─ README.md
|
||||||
│ └─ README.md
|
└─ requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. **Install Ollama** and pull the required models:
|
||||||
|
```bash
|
||||||
|
ollama pull llama3
|
||||||
|
ollama pull nomic-embed-text
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Set the Tavily API key** (obtain a free key from https://tavily.com):
|
||||||
|
```bash
|
||||||
|
export TAVILY_API_KEY=your_api_key_here
|
||||||
|
```
|
||||||
|
On Windows use `set` instead of `export`.
|
||||||
|
|
||||||
|
3. **Install Python dependencies**:
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Add documents** you want the agent to know about into the `documents/` folder. Any `.txt` or `.md` files will be automatically loaded.
|
||||||
|
|
||||||
|
## Running the Agent
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
You will see a prompt where you can type questions. Type `exit`, `quit`, or `q` to end the session.
|
||||||
|
|
||||||
|
Example interaction:
|
||||||
|
|
||||||
|
```
|
||||||
|
User: What are the latest developments in AI agents?
|
||||||
|
Assistant: [Web Search] - ...
|
||||||
|
Source: tavily
|
||||||
|
|
||||||
|
User: What does our lab say about LangGraph?
|
||||||
|
Assistant: [Local KB] - ...
|
||||||
|
Source: chromadb
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. **Vector Store** – `vectorstore.py` creates a persistent Chroma collection using `OllamaEmbeddings`. Documents from `documents/` are split with `RecursiveCharacterTextSplitter` and added to the store.
|
||||||
|
2. **Tools** – `tools.py` defines two tools:
|
||||||
|
* `search_local_kb` – semantic search in the local vector store.
|
||||||
|
* `web_search` – live web search via Tavily.
|
||||||
|
3. **Agent** – In `main.py` we create a `ChatOllama` LLM and pass the two tools to `create_agent`. A system prompt instructs the LLM to choose the correct tool. The agent returns the answer along with a source tag.
|
||||||
|
|
||||||
|
## Extending
|
||||||
|
|
||||||
|
- Add more documents to `documents/` and restart the CLI – the store will be updated automatically.
|
||||||
|
- Replace the LLM or embedding model by changing the `ChatOllama` and `OllamaEmbeddings` parameters.
|
||||||
|
- Add additional tools (e.g., file system access, calculator) following the same pattern.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT License.
|
||||||
Reference in New Issue
Block a user