2026-06-02 07:17:32 +00:00
2026-06-02 07:17:10 +00:00
2026-06-02 07:17:15 +00:00
2026-06-01 17:36:32 +00:00
2026-06-02 07:17:21 +00:00
2026-06-02 07:17:26 +00:00
2026-06-02 07:17:32 +00:00
2026-06-02 07:11:12 +00:00
2026-06-02 07:16:08 +00:00

RAG Agent with ChromaDB and Web Search

This repository implements a simple RAG (Retrieval-Augmented Generation) agent that can:

  1. Search a local knowledge base stored in ChromaDB using semantic embeddings from Ollama.
  2. Perform realtime web search via Tavily.
  3. Decide automatically which source to use and indicate the source in the final answer.

Prerequisites

  • Python 3.10+ (recommended via pyenv or conda).
  • Ollama installed locally and the following models pulled:
    ollama pull llama3
    ollama pull nomic-embed-text
    
  • A Tavily API key. Create a .env file in the project root with:
    TAVILY_API_KEY=YOUR_KEY_HERE
    

Installation

# Optional: create a virtual environment
python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Preparing the Knowledge Base

Place any .txt or .md files you want the agent to know about in the documents/ folder. Run the following command once to load them into ChromaDB:

python -c "from vectorstore import create_vectorstore, load_documents; store=create_vectorstore(); load_documents('./documents', store)"

The vector store is persisted in the chroma_db/ directory, so the data will be available for subsequent runs.

Running the Agent

python main.py

You will see a simple chat loop. Type your questions and the agent will answer.

Welcome to the RAG agent. Type 'exit' to quit.

User: What is LangGraph?

Assistant: LangGraph is a framework for building ...
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

├── agent.py          # Core agent logic
├── rag_tools.py      # Tool implementations
├── vectorstore.py    # ChromaDB utilities
├── main.py           # Entry point
├── requirements.txt
├── .gitignore
└── README.md

Extending

  • Add more tools by creating new functions decorated with @tool.
  • Replace the LLM or embeddings with other Ollama models.
  • Switch to a different vector store (e.g., Qdrant) by updating vectorstore.py.

License

MIT License.

S
Description
Экзамен: RAG-агент с ChromaDB и веб-поиском
Readme 192 KiB
Languages
Python 100%