2026-06-02 07:21:51 +00:00
2026-06-02 07:21:45 +00:00
2026-06-02 07:21:51 +00:00
2026-06-01 17:36:32 +00:00
2026-06-02 07:20:26 +00:00
2026-06-02 07:20:32 +00:00
2026-06-02 07:19:06 +00:00
2026-06-02 07:20:43 +00:00
2026-06-02 07:20:49 +00:00

RAGAgent with ChromaDB and Web Search

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.

Features

  • Local semantic search Uses a ChromaDB vector store backed by Ollama embeddings.
  • 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

# 1. Clone the repo
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 nomic-embed-text

# 5. Set Tavily API key
export TAVILY_API_KEY=your_api_key   # Windows: set TAVILY_API_KEY=your_api_key

# 6. Prepare documents
# Place any .txt or .md files you want to index in the ./documents folder.
# They will be automatically loaded into ChromaDB on first run.

# 7. Run the agent
python main.py

Usage

Запрос: Какие последние новости про AI-агентов?
[Web Search]
1. AI Agents: The Future of Automation: ...
2. ...
Source: tavily

Запрос: Что в наших конспектах про LangGraph?
[Local KB]
1. LangGraph is a ...
2. ...
Source: chromadb

Project Structure

├── agent.py          # Core agent logic and tools
├── vectorstore.py    # ChromaDB creation and document loading
├── rag_tools.py      # Web search tool
├── main.py           # CLI entry point
├── requirements.txt
└── README.md

Extending

  • Add more tools Define new functions decorated with @tool and add them to the tools list.
  • Change LLM Swap ChatOllama for another provider (e.g., OpenAI) by adjusting the import and model name.
  • Custom prompt Edit agent_prompt in agent.py to modify the agents instruction.

Happy querying!

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