2.3 KiB
2.3 KiB
RAG Agent with ChromaDB and Web Search
This project implements a simple Retrieval-Augmented Generation (RAG) agent that uses ChromaDB for vector storage and OpenAI embeddings for text representation. The agent exposes two HTTP endpoints:
POST /ingest– ingest documents into the vector store.POST /query– retrieve the most similar documents for a given query.
Features
- Vector Store: ChromaDB collection named
rag_collection. - Embeddings: OpenAI
text-embedding-ada-002(configurable). - API: FastAPI based, can be run locally or in Docker.
- No Qdrant: The implementation uses only ChromaDB as required.
Prerequisites
- Python 3.11+
- Docker (optional, for containerized deployment)
- An OpenAI API key (set as
OPENAI_API_KEYenvironment variable).
Setup
Local
# 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 virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Set OpenAI API key
export OPENAI_API_KEY="sk-..."
# Run the server
uvicorn src.main:app --reload
The API will be available at http://127.0.0.1:8000.
Docker
# Build the image
docker build -t rag-agent .
# Run the container
docker run -d -p 8000:8000 --env OPENAI_API_KEY="sk-..." rag-agent
API Usage
Ingest Documents
curl -X POST http://localhost:8000/ingest \
-H "Content-Type: application/json" \
-d '{
"documents": [
{"content": "The quick brown fox jumps over the lazy dog."},
{"content": "Python is a versatile programming language."}
]
}'
Query
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is Python?",
"k": 3
}'
Notes
- The vector store is persisted in memory by default. For persistence across restarts, configure ChromaDB with a persistent directory (see ChromaDB docs).
- The agent currently only returns the raw similarity search results. Integration with a language model for generation can be added later.
- No Qdrant usage is present; the stack strictly follows the assignment requirements.
License
MIT License