An end-to-end Retrieval-Augmented Generation (RAG) platform built with Airflow, PostgreSQL + pgvector, MLflow, and Docker, featuring automated evaluation and metric-driven model promotion.
This project is intentionally designed as a production-style Applied AI system, not a demo. It focuses on orchestration, evaluation, governance, and automation.
- Ingests documents into PostgreSQL
- Generates embeddings and stores them using pgvector
- Performs semantic retrieval for RAG
- Evaluates RAG quality using multiple metrics
- Tracks experiments and artifacts with MLflow
- Automatically promotes better models/configurations to Production
- Orchestrates the entire lifecycle using Apache Airflow
- Runs fully containerized using Docker Compose
flowchart LR
subgraph Airflow["Apache Airflow (Orchestration)"]
A1[init_pgvector]
A2[init_schema]
A3[ingest_documents]
A4[generate_embeddings]
A5[evaluate_and_log]
A6[auto_promote]
A1 --> A2 --> A3 --> A4 --> A5 --> A6
end
subgraph DB["PostgreSQL + pgvector"]
D1[(documents table)]
end
subgraph ML["MLflow"]
M1[Experiments]
M2[Model Registry]
end
subgraph API["Optional API Layer"]
S1[Search / RAG API]
end
A3 --> D1
A4 --> D1
A5 --> M1
A6 --> M2
S1 --> D1
S1 --> M1
Why Mermaid?
- Renders directly on GitHub
- Keeps architecture close to code
- Easy to evolve as the system grows
init_pgvector
β
init_schema
β
ingest_documents
β
generate_embeddings
β
evaluate_and_log
β
auto_promote
- Prevents race conditions
- Handles fresh databases and restarts
- Guarantees pgvector exists before table creation
- Makes the pipeline self-healing
- Python 3.8+
- PostgreSQL 15
- pgvector
- MLflow
- Experiment Tracking
- Artifact Logging
- Model Registry
- Stage Transitions
- Apache Airflow
- PythonOperator-based DAG
- Retries and dependency control
- Docker
- Docker Compose
- Windows-safe local setup
Each evaluation run logs:
- avg_retrieval_score β semantic relevance
- avg_generation_score β answer quality
- avg_latency β end-to-end latency
All metrics are logged to MLflow and used for promotion decisions.
Promotion is fully automated using a transparent policy.
A model is promoted to Production if:
- Retrieval score β₯ Production
- Generation score β₯ Production
- Latency β€ Production
- If no Production model exists
- First successful evaluation is promoted automatically
- Registry is initialized safely
This ensures:
- No manual judgment
- No silent regressions
- Fully auditable decisions
An API layer (e.g., FastAPI) is included to expose the RAG system to external consumers.
- Accepts search / question requests
- Generates query embeddings
- Performs vector similarity search via pgvector
- Assembles context and calls the LLM
- Returns final answers to clients
- The core learning goal is MLOps + orchestration
- API logic is intentionally thin
- In production, this layer would scale independently
Including it demonstrates end-to-end system thinking without overengineering.
.
βββ app/
β βββ ml/
β β βββ models.py
β β βββ embedding_service.py
β β βββ auto_promote.py
β β
β βββ pipelines/
β βββ init_pgvector.py
β βββ init_schema.py
β βββ ingest_documents.py
β βββ run_evaluation_task.py
β βββ auto_promote_task.py
β
βββ scripts/
β βββ generate_embeddings.py
β
βββ airflow/
β βββ dags/
β βββ document_pipeline_dag.py
β
βββ docker-compose.yaml
βββ Dockerfile.airflow
βββ README.md
- Docker Desktop
- Docker Compose
- Ports available:
- 8080 (Airflow)
- 5000 (MLflow)
docker compose up- Airflow UI: http://localhost:8080
- MLflow UI: http://localhost:5000
- Open the Airflow UI
- Enable the DAG:
document_ingestion_and_embedding - Trigger the DAG manually
Expected result:
- All tasks succeed
- MLflow shows experiment
rag-evaluation - Model
rag_pipelinepromoted to Production
- Simple and production-ready
- Avoids unnecessary external vector databases
- SQL + vectors are debuggable
- Explicit orchestration and retries
- Clear dependency management
- Separation of orchestration and ML logic
- Strong experiment lineage
- Built-in model registry
- Enables automated governance
- Applied AI system design
- MLOps best practices
- Orchestration-first thinking
- Metric-driven decisions
- Production readiness