๐ง RAGenius v2 โ Multi-Provider Retrieval-Augmented Generation System
RAGenius v2 is a next-gen Retrieval-Augmented Generation (RAG) system supporting multiple AI providers:
- ๐ง Azure OpenAI โ enterprise-grade LLMs
- ๐ Google Gemini โ efficient, high-quality embeddings
- โก Groq โ ultra-fast inference
Built with FastAPI, ChromaDB, and LangChain, it enables hybrid document retrieval, intelligent context enrichment, and real-time streaming answers โ across multiple AI providers.
๐ญ Architecture Overview
flowchart TD
subgraph Client["User / Frontend / API Client"]
Q[User Query or File Upload]
end
subgraph API["FastAPI App: multi_provider_rag_api.py"]
A1[/Request Handler/]
A2{{"Engine Registry"}}
A3[[RAG Engine]]
end
subgraph Embedding["Embedding Pipeline"]
E1[Gemini]
E2[Azure OpenAI]
end
subgraph LLM["LLM Provider"]
L1[Azure GPT-4]
L2[Groq GPT-OSS]
end
subgraph Store["Vector Store (ChromaDB)"]
C1[(chroma_gemini)]
C2[(chroma_azure)]
end
Q --> A1
A1 --> A2
A2 -->|Select Combo| A3
A3 -->|Embeddings| Embedding
A3 -->|Retrieval| Store
A3 -->|LLM Query| LLM
Embedding --> Store
LLM --> A1
๐ End-to-End System Flow (Sequence Diagram)
sequenceDiagram
participant U as ๐ง User
participant F as โ๏ธ FastAPI (multi_provider_rag_api)
participant E as ๐งฉ RAG Engine
participant V as ๐พ ChromaDB
participant L as ๐ง LLM (Azure / Groq)
U->>F: POST /rag/basic (query)
F->>E: get_or_create_engine(provider combo)
E->>V: query_db(question, top_k)
V-->>E: relevant chunks (context)
E->>L: generate answer(context + query)
L-->>E: final response
E-->>F: formatted result
F-->>U: JSON / stream response
๐ Key Features
๐งฉ Multi-Provider RAG Engine
- Supports Azure OpenAI, Google Gemini, and Groq
- Dynamic engine creation per provider combination
- Separate Chroma collections for embedding isolation
๐ Document Processing
- Multi-format support: PDF, Excel, JSON, CSV, DOCX, TXT
- Automatic metadata tagging
- Chunking with overlap and semantic boundaries
๐ Query & Retrieval
- Basic Mode: Synchronous query
- Streaming Mode: Real-time token responses
- Vector similarity search with ChromaDB
- Summarization and top-K retrieval
๐๏ธ Vector Store Management
- Persistent ChromaDB storage
- Provider-specific directories (
chroma_azure, chroma_gemini)
- Incremental updates without full reindexing
๐งฑ Project Structure
RAG/
โโโ api/
โ โโโ app.py # Azure-only FastAPI app
โ โโโ multi_provider_rag_api.py # Multi-provider RAG API
โ โโโ config.py # Configuration and defaults
โ โโโ helper_function.py # Engine management helpers
โ โโโ models.py # Pydantic models
โ โโโ src/
โ โโโ __init__.py
โ โโโ data_loader.py # Document ingestion
โ โโโ embedding.py # Embedding pipeline (Gemini & Azure)
โ โโโ vectorstore.py # ChromaDB integration
โ โโโ search.py # RAG engine (basic & streaming)
โโโ chromadb_store/
โโโ data/
โโโ main.py
โโโ requirements.txt
โโโ README.md
๐ Getting Started
1๏ธโฃ Prerequisites
- Python 3.10+
- API keys for Azure OpenAI, Google Gemini, and/or Groq
- Optional: Docker for deployment
2๏ธโฃ Installation
Option 1: Using UV (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/AquibPy/RAGenius.git
cd RAGenius
uv sync
source .venv/bin/activate # or .venv\Scripts\activate on Windows
Option 2: Using pip
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt
3๏ธโฃ Environment Configuration
cp .env.example .env
Example .env:
AZURE_OPENAI_API_KEY=your_key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4
AZURE_OPENAI_EMBEDDING_MODEL=text-embedding-3-large
GOOGLE_API_KEY=your_google_key
GROQ_API_KEY=your_groq_key
4๏ธโฃ Run API Server
Start the Multi-Provider API
uvicorn api.multi_provider_rag_api:app --reload --host 0.0.0.0 --port 8000
For Azure-only API
uv run uvicorn api.multi_provider_rag_api:app --reload
Access:
๐ง CLI Usage
# Basic RAG query
python main.py --query "What is attention mechanism?" --mode basic
# Streaming RAG query
python main.py --query "Explain transformers in NLP" --mode streaming
๐ API Reference (Highlights)
| Endpoint |
Description |
Method |
Output |
/rag/basic |
Non-streaming RAG query |
POST |
JSON |
/rag/stream |
Streaming RAG output |
POST |
SSE |
/rag/upload |
Upload documents |
POST |
JSON |
/rag/engines |
List active RAG engines |
GET |
JSON |
/rag/switch-default |
Switch default providers |
POST |
JSON |
/rag/stats |
Vector store analytics |
GET |
JSON |
/health |
Service health check |
GET |
JSON |
๐งฉ Example Query
curl -X POST "http://localhost:8000/rag/basic" \
-H "Content-Type: application/json" \
-d '{"query": "What is deep learning?", "top_k": 5}'
Response:
{
"query": "What is deep learning?",
"answer": "Deep learning is a subfield of AI using neural networks with many layers...",
"sources": [...],
"providers_used": {"embedding": "gemini", "llm": "groq"}
}
โ๏ธ Configuration Options
| Parameter |
Default |
Description |
DEFAULT_EMBEDDING_PROVIDER |
gemini |
Default embedding provider |
DEFAULT_LLM_PROVIDER |
groq |
Default LLM provider |
MAX_FILE_SIZE |
50 MB |
Maximum upload size |
VECTOR_DIR |
chromadb_store |
Vector database directory |
๐ง Core Components
1. data_loader.py
Loads and preprocesses multiple file formats with LangChain loaders.
2. embedding.py
Handles embeddings via Gemini or Azure OpenAI with batching and retry logic.
3. vectorstore.py
ChromaDB wrapper with provider-specific stores.
4. search.py
RAGEngine for hybrid retrieval and generation (sync and streaming).
โ๏ธ Provider Comparison
| Provider |
Speed |
Cost |
Quality |
| Gemini |
โก Fast |
๐ฐ Low |
๐ง High |
| Azure |
โ๏ธ Medium |
๐ฐ Medium |
๐ Excellent |
| Groq |
๐ Very Fast |
๐ฐ Low |
๐ Good |
๐ Monitoring
curl http://localhost:8000/health
curl http://localhost:8000/rag/engines
curl http://localhost:8000/rag/stats
๐ณ Docker Deployment
docker build -t ragenius:latest .
docker run -p 8000:8000 --env-file .env ragenius:latest
Or with Docker Compose:
docker-compose up -d
๐งฑ Best Practices
| Goal |
Recommendation |
| ๐ฐ Cost Optimization |
Use Gemini + Groq |
| ๐ Accuracy |
Use Azure + Azure |
| โก Speed |
Use Groq for LLM |
| ๐ Isolation |
One embedding provider per dataset |
| ๐ File Size |
Keep <50 MB or adjust MAX_FILE_SIZE |
๐ค Contributing
git clone https://github.com/AquibPy/RAGenius.git
cd RAGenius
uv sync --dev
pre-commit install
๐ License
MIT License ยฉ 2025 Mohd Aquib
๐ Acknowledgments
- FastAPI โ Modern async API framework
- LangChain โ LLM orchestration
- ChromaDB โ Vector store for embeddings
- Azure OpenAI โ GPT-4 model suite
- Google Gemini โ Embedding provider
- Groq โ Low-latency LLM engine
Built with โค๏ธ by MOHD AQUIB
โญ Star the repo if you find it useful!