A modular Retrieval-Augmented Generation (RAG) API built with FastAPI, MongoDB, Qdrant, and LLM/embedding providers.
- Document upload and processing
- Configurable document chunking
- Embedding generation
- Semantic search with Qdrant
- RAG-based question answering
- MongoDB for document metadata and chunks
- Health and readiness endpoints
- Docker Compose infrastructure
The application follows a pipeline-based RAG architecture:
┌──────────────────┐
│ Client │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ FastAPI │
│ Routes │
└────────┬─────────┘
│
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
┌──────────┐ ┌───────────┐ ┌───────────┐
│Documents │ │ RAG │ │ Health │
│ Routes │ │ Routes │ │ Routes │
└────┬─────┘ └─────┬─────┘ └───────────┘
│ │
▼ ▼
┌─────────────────────────┐
│ Controllers │
│ Asset / Process / RAG │
└────────────┬────────────┘
│
┌──────────┴──────────┐
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ MongoDB │ │ Qdrant │
│ │ │ │
│ Projects │ │ Embeddings │
│ Assets │ │ │
│ Chunks │ │ │
└─────────────┘ └─────────────┘
▲
│
┌──────┴──────┐
│ Embedding │
│ Model │
└─────────────┘
│
▼
┌─────────────┐
│ Chat Model │
└─────────────┘
- Python
- FastAPI
- MongoDB
- Qdrant
- OpenAI
- OpenRouter
- LangChain
- Docker
- uv
Mini-RAG/
│
├── Docker/
│ ├── docker-compose.yml # MongoDB and Qdrant services
│ ├── mongodb_data/ # MongoDB persistent data
│ └── qdrant_data/ # Qdrant persistent data
│
├── src/
│ │
│ ├── assets/ # Application assets and uploaded files
│ │
│ ├── controllers/ # Application/business logic
│ │ ├── AssetController.py # Asset and document operations
│ │ ├── BaseController.py # Shared controller functionality
│ │ ├── ProcessController.py # Document processing and chunking
│ │ ├── ProjectController.py # Project-related operations
│ │ └── RagController.py # RAG pipeline operations
│ │
│ ├── helpers/ # Shared utilities and helper functions
│ │
│ ├── models/ # Data models and database operations
│ │
│ ├── routes/ # FastAPI API routes
│ │ ├── documents.py # Document upload and processing endpoints
│ │ ├── rag.py # Embedding, retrieval, and RAG endpoints
│ │ ├── health.py # Liveness and readiness endpoints
│ │ ├── enums/ # API-related enumerations
│ │ └── request_schemes/ # Request and response schemas
│ │
│ ├── stores/ # External service integrations
│ │ ├── llm/ # LLM provider implementations
│ │ └── vectorDB/ # Vector database implementations
│ │
│ ├── .env.example # Example environment configuration
│ ├── main.py # FastAPI application entry point
│ ├── pyproject.toml # Project metadata and dependencies
│ └── uv.lock # Locked Python dependencies
│
├── .gitignore # Git ignore rules
└── README.md # Project documentation
git clone https://github.com/MOH-YAHIA/Mini-RAG.git
cd Mini-RAGcp src/.env.example src/.envUpdate the values in src/.env with your database and LLM configuration.
cd Docker
docker compose up -dCheck the running containers:
docker compose pscd ../src
uv syncuv run uvicorn main:app --host 127.0.0.1 --port 8000 --reloadThe API will be available at:
http://127.0.0.1:8000
Interactive API documentation:
http://127.0.0.1:8000/docs
| Method | Endpoint | Description |
|---|---|---|
POST |
/documents/upload/{project_id} |
Upload a document |
POST |
/documents/process/{project_id} |
Process and chunk documents |
POST |
/rag/embed/{project_id} |
Generate document embeddings |
POST |
/rag/retrieve/{project_id} |
Retrieve relevant chunks |
POST |
/rag/chat/{project_id} |
Generate a RAG answer |
GET |
/rag/collection_info/{project_id} |
Get Qdrant collection information |
GET |
/health/live |
Check API liveness |
GET |
/health/ready |
Check service readiness |
The application follows the standard RAG pipeline:
1. Upload document
↓
2. Process and split into chunks
↓
3. Store chunks in MongoDB
↓
4. Generate embeddings
↓
5. Store vectors in Qdrant
↓
6. Embed user query
↓
7. Retrieve relevant chunks
↓
8. Generate answer using the LLM
MongoDB stores application and document data, including:
- Projects
- Assets Metadata
- Document chunks
Qdrant is used as the vector database for:
- Document embeddings
- Semantic similarity search
- Retrieval of relevant chunks