2026-06-02 07:10:56 +00:00
2026-06-01 17:36:32 +00:00
2026-06-02 07:10:50 +00:00
2026-06-01 17:36:32 +00:00
2026-06-01 17:40:35 +00:00
2026-06-01 17:40:41 +00:00
2026-06-01 17:40:47 +00:00
2026-06-01 17:40:52 +00:00

RAG Agent with ChromaDB and Tavily

Overview

This repository implements a RAG (RetrievalAugmented Generation) agent that can answer questions by searching a local knowledge base stored in ChromaDB or by fetching uptodate 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

  • Local Knowledge Base Vector store backed by ChromaDB with embeddings from Ollama (nomic-embed-text).
  • Web Search Uses Tavily API for realtime web queries.
  • Automatic Routing The agent decides whether to use the local KB or the web search.
  • CLI Simple commandline interface for interactive queries.
  • Persistence The ChromaDB store is persisted between runs.

Setup

  1. Install Ollama and pull the required models:

    ollama pull llama3
    ollama pull nomic-embed-text
    
  2. Install Python dependencies:

    pip install -r requirements.txt
    
  3. Set up the Tavily API key. Create a .env file in the project root with:

    TAVILY_API_KEY=your_api_key_here
    
  4. Add documents you want to index into the documents/ folder. The script will automatically load .txt and .md files.

Usage

python main.py

You will be prompted for a query. Type exit to quit.

Example:

Query: Какие последние новости про AI-агентов?
Answer:
[Web Search]
1. AI Agents are ...
   https://example.com
   ...
Source: tavily

Project Structure

  • vectorstore.py Helper functions for creating and populating the ChromaDB vector store.
  • agent.py Defines the tools and initializes the LangChain agent.
  • main.py CLI entry point.
  • requirements.txt Python dependencies.
  • README.md Documentation.

Notes

  • The agent uses the ZeroShot React strategy. It may call both tools if the query is ambiguous. You can tweak the prompt or the routing logic if needed.
  • The ChromaDB store is persisted in ./chroma_db. Delete this folder to reindex.
  • Ensure the Ollama server is running locally when executing the agent.
S
Description
Экзамен: RAG-агент с ChromaDB и веб-поиском
Readme 192 KiB
Languages
Python 100%