b4f2282dd3aec6334447c6ec1d2d5773bf8572ac
RAG Agent with ChromaDB and Web Search
This repository contains a lightweight Retrieval‑Augmented Generation (RAG) agent that uses ChromaDB as the vector store and performs a simple web search to augment the retrieved context before generating an answer with OpenAI's GPT model.
Deadline: 31.08.2026
Version: 14
Features
- Vector Store – ChromaDB (local, no external service required)
- Embeddings – OpenAI
text-embedding-ada-002 - LLM – OpenAI
gpt-3.5-turbo - Web Search – DuckDuckGo (no API key needed)
- Command‑line interface for adding documents and asking questions
Prerequisites
- Python 3.9+
- An OpenAI API key
Installation
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-rag-agent-s-chromadb-i-veb-poisk.git
cd ekzamen-rag-agent-s-chromadb-i-veb-poisk
# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
requirements.txt contains:
openai>=1.0.0
chromadb>=0.4.0
requests>=2.31.0
beautifulsoup4>=4.12.0
Configuration
Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY="sk-..."
On Windows:
set OPENAI_API_KEY=sk-...
Usage
1. Add Documents
Add a text file to the vector store. The file will be split into chunks (≈500 tokens each) and embedded.
python -m src.index add path/to/document.txt
Example:
python -m src.index add data/biology.txt
2. Ask a Question
Query the RAG agent. It will:
- Retrieve the top‑5 nearest chunks from ChromaDB.
- Perform a DuckDuckGo web search for the query.
- Combine the retrieved context and web snippets.
- Generate an answer with GPT.
python -m src.index ask "What is the function of mitochondria?"
3. Help
python -m src.index
Example
$ python -m src.index add sample.txt
Added 4 chunks from sample.txt to the collection.
$ python -m src.index ask "Explain the water cycle."
Answer:
The water cycle, also known as the hydrologic cycle, describes the continuous movement of water on, above, and below the surface of the Earth. ...
Project Structure
src/
├── index.py # Main script
README.md
requirements.txt
Notes
- ChromaDB Persistence – The vector store is persisted in
./chromadb. Delete this folder to reset the store. - Token Limits – The embedding model
text-embedding-ada-002supports up to 8191 tokens per request. The chunking logic approximates a 500‑token limit per chunk. - Web Search – DuckDuckGo is used for simplicity. For production use, consider a dedicated search API (e.g., SerpAPI, Bing Search API).
License
MIT License
Description
Languages
Python
82.6%
JavaScript
16.6%
Dockerfile
0.8%