# RAG Agent with ChromaDB and Web Search This project implements a Retrieval-Augmented Generation (RAG) agent that uses **ChromaDB** as the vector database and performs live web searches to provide up‑to‑date information. ## Features - **Vector store** – Documents are ingested, split into chunks, embedded with OpenAI embeddings, and stored in a persistent ChromaDB collection. - **Web search** – Uses DuckDuckGo scraping to fetch recent web snippets for a query. - **RAG pipeline** – Combines local document context and web results, then generates an answer with OpenAI GPT‑3.5‑Turbo. - **CLI** – Simple command line interface for ingestion and querying. ## Prerequisites - Python 3.10+ - An OpenAI API key with access to `text-embedding-ada-002` and `gpt-3.5-turbo`. ## Setup ```bash # 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 use `.venv\Scripts\activate` # Install dependencies pip install -r requirements.txt ``` ## Configuration Create a `.env` file in the project root (or set environment variables directly): ``` OPENAI_API_KEY=sk-... CHROMA_DB_PATH=./chromadb CHROMA_COLLECTION_NAME=rag_collection ``` > **Note**: Do not commit your `.env` file or API key to version control. ## Usage ### 1. Ingest Documents ```bash python src/main.py ingest path/to/doc1.txt path/to/doc2.txt ``` The script will read each file, split it into chunks, generate embeddings, and store them in ChromaDB. ### 2. Query the Agent ```bash python src/main.py query "What is the capital of France?" ``` The agent will: 1. Retrieve relevant chunks from the local vector store. 2. Perform a DuckDuckGo web search for the query. 3. Combine both sources of information. 4. Generate a response using OpenAI GPT‑3.5‑Turbo. ## Project Structure ``` src/ ├── main.py # CLI entry point ├── vector_store.py # ChromaDB ingestion & retrieval ├── web_search.py # DuckDuckGo web search requirements.txt README.md ``` ## Testing The project can be tested with `pytest` (tests are not included in this minimal example). If you add tests, run: ```bash pytest ``` ## License MIT License --- Feel free to extend the agent with additional features such as custom embeddings, different LLMs, or alternative search APIs.