Update README.md
This commit is contained in:
@@ -1,83 +1,77 @@
|
|||||||
# RAG Agent with ChromaDB and Web Search
|
# RAG‑Agent with ChromaDB and Web Search
|
||||||
|
|
||||||
This repository implements a simple RAG (Retrieval-Augmented Generation) agent that can:
|
This repository implements a simple RAG (Retrieval‑Augmented 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.
|
||||||
|
|
||||||
1. Search a local knowledge base stored in **ChromaDB** using semantic embeddings from **Ollama**.
|
## Features
|
||||||
2. Perform real‑time web search via **Tavily**.
|
|
||||||
3. Decide automatically which source to use and indicate the source in the final answer.
|
|
||||||
|
|
||||||
## Prerequisites
|
* **Local semantic search** – Uses a ChromaDB vector store backed by Ollama embeddings.
|
||||||
|
* **Web search** – Uses Tavily to fetch up‑to‑date 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.
|
||||||
|
|
||||||
- Python 3.10+ (recommended via `pyenv` or `conda`).
|
## Setup
|
||||||
- Ollama installed locally and the following models pulled:
|
|
||||||
```bash
|
|
||||||
ollama pull llama3
|
|
||||||
ollama pull nomic-embed-text
|
|
||||||
```
|
|
||||||
- A Tavily API key. Create a `.env` file in the project root with:
|
|
||||||
```text
|
|
||||||
TAVILY_API_KEY=YOUR_KEY_HERE
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Optional: create a virtual environment
|
# 1. Clone the repo
|
||||||
|
git clone <repo-url>
|
||||||
|
cd <repo-dir>
|
||||||
|
|
||||||
|
# 2. (Optional) Create a virtual environment
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
source venv/bin/activate # Windows: venv\Scripts\activate
|
source venv/bin/activate # Windows: venv\Scripts\activate
|
||||||
|
|
||||||
# Install dependencies
|
# 3. Install dependencies
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
|
||||||
|
|
||||||
## Preparing the Knowledge Base
|
# 4. Pull required Ollama models
|
||||||
|
ollama pull llama3
|
||||||
|
ollama pull nomic-embed-text
|
||||||
|
|
||||||
Place any `.txt` or `.md` files you want the agent to know about in the `documents/` folder.
|
# 5. Set Tavily API key
|
||||||
Run the following command once to load them into ChromaDB:
|
export TAVILY_API_KEY=your_api_key # Windows: set TAVILY_API_KEY=your_api_key
|
||||||
|
|
||||||
```bash
|
# 6. Prepare documents
|
||||||
python -c "from vectorstore import create_vectorstore, load_documents; store=create_vectorstore(); load_documents('./documents', store)"
|
# Place any .txt or .md files you want to index in the ./documents folder.
|
||||||
```
|
# They will be automatically loaded into ChromaDB on first run.
|
||||||
|
|
||||||
The vector store is persisted in the `chroma_db/` directory, so the data will be available for subsequent runs.
|
# 7. Run the agent
|
||||||
|
|
||||||
## Running the Agent
|
|
||||||
|
|
||||||
```bash
|
|
||||||
python main.py
|
python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
You will see a simple chat loop. Type your questions and the agent will answer.
|
## Usage
|
||||||
|
|
||||||
```
|
```text
|
||||||
Welcome to the RAG agent. Type 'exit' to quit.
|
Запрос: Какие последние новости про AI-агентов?
|
||||||
|
[Web Search]
|
||||||
|
1. AI Agents: The Future of Automation: ...
|
||||||
|
2. ...
|
||||||
|
Source: tavily
|
||||||
|
|
||||||
User: What is LangGraph?
|
Запрос: Что в наших конспектах про LangGraph?
|
||||||
|
[Local KB]
|
||||||
Assistant: LangGraph is a framework for building ...
|
1. LangGraph is a ...
|
||||||
|
2. ...
|
||||||
Source: chromadb
|
Source: chromadb
|
||||||
```
|
```
|
||||||
|
|
||||||
If the information is not present locally, the agent will automatically perform a web search and label the answer with `Source: tavily`.
|
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
├── agent.py # Core agent logic
|
├── agent.py # Core agent logic and tools
|
||||||
├── rag_tools.py # Tool implementations
|
├── vectorstore.py # ChromaDB creation and document loading
|
||||||
├── vectorstore.py # ChromaDB utilities
|
├── rag_tools.py # Web search tool
|
||||||
├── main.py # Entry point
|
├── main.py # CLI entry point
|
||||||
├── requirements.txt
|
├── requirements.txt
|
||||||
├── .gitignore
|
|
||||||
└── README.md
|
└── README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
## Extending
|
## Extending
|
||||||
|
|
||||||
- Add more tools by creating new functions decorated with `@tool`.
|
* **Add more tools** – Define new functions decorated with `@tool` and add them to the `tools` list.
|
||||||
- Replace the LLM or embeddings with other Ollama models.
|
* **Change LLM** – Swap `ChatOllama` for another provider (e.g., OpenAI) by adjusting the import and model name.
|
||||||
- Switch to a different vector store (e.g., Qdrant) by updating `vectorstore.py`.
|
* **Custom prompt** – Edit `agent_prompt` in `agent.py` to modify the agent’s instruction.
|
||||||
|
|
||||||
## License
|
---
|
||||||
|
|
||||||
MIT License.
|
Happy querying!
|
||||||
|
|||||||
Reference in New Issue
Block a user