Predictive Maintenance RAG System
Author: Syeda Arisha Hassan
Domain: FMCG & Industrial Manufacturing
Stack: XGBoost Β· Random Forest Β· PyTorch LSTM Β· 1D-CNN-LSTM Β· FAISS Β· SmolLM2-135M
Overview
An end-to-end, closed-loop predictive maintenance platform built for FMCG and continuous industrial manufacturing. The system integrates four ML/DL pipelines with a Retrieval-Augmented Generation (RAG) layer to deliver actionable, plain-language diagnostics and automated production rescheduling.
Unexpected machine breakdowns in FMCG plants cost $10,000 to $36,000 per hour (McKinsey). This system addresses that by predicting failures before they happen and automatically reallocating production jobs to healthy machines.
Repository Contents
models/
βββ classification/
β βββ ai4i_ensemble_model.pkl # XGBoost + RF soft-voting ensemble (AI4I 2020)
β βββ pump_ensemble_model.pkl # XGBoost + RF soft-voting ensemble (Pump Sensor)
βββ regression/
β βββ best_cmapss_lstm_checkpoint.pt # 2-Layer PyTorch LSTM (NASA CMAPSS FD001)
β βββ best_cmapss_cnn-lstm_checkpoint.pt # 1D-CNN-LSTM Regressor (NASA CMAPSS FD001)
βββ rag/
βββ faiss_index.bin # FAISS IndexFlatL2 β 7,966 vectors Γ 384-d
βββ faiss_texts.pkl # Synthesized maintenance log corpus
System Architecture
[ Sensor Telemetry ] β [ ML Classifiers ] β [ Risk Score ]
β [ DL RUL Regressor ] β [ Hours Remaining ]
β [ FAISS Retrieval ] β [ Historical Context ]
β [ LLM Explainer (SmolLM2) ] β [ Diagnostic Report ]
β [ Production Scheduler ] β [ Adjusted Job Schedule ]
Pipelines & Datasets
1. AI4I 2020 β Milling Machine Classification
- Dataset: 10,000 records, 14 features (UCI Machine Learning Repository)
- Task: Binary failure classification (3.4% class imbalance)
- Approach: Optuna-tuned XGBoost + Random Forest, Soft Voting Ensemble, SMOTE oversampling
- Results:
- ROC-AUC: 0.9726
- Recall: 0.87 (87% of true failures detected)
- Confusion Matrix:
[[1892, 40], [9, 59]]
2. Pump Sensor β Temporal Early Warning
- Dataset: 220,320 minute-interval readings, 52 sensors (AprilβAugust 2018)
- Task: 60-minute lookahead pre-failure warning classification
- Approach: Strict temporal 50/50 train/test split, TimeSeriesSplit Optuna tuning,
RECOVERINGrows dropped to eliminate target leakage - Model:
models/classification/pump_ensemble_model.pkl
3. NASA CMAPSS FD001 β Turbofan Engine RUL Regression
- Dataset: 100 training engines, 100 test engines, 26 sensor channels
- Task: Remaining Useful Life (RUL) regression in cycles
- Approach: 3D sliding window sequences (N Γ 30 Γ 24), MinMaxScaler, piecewise RUL capping at 125 cycles
- Architectures:
- 2-Layer LSTM: Hidden sizes 64β32, LayerNorm, early stopping (patience=10)
- 1D-CNN-LSTM: Conv1D spatial extraction + LSTM temporal recurrence
- Results: MAE ~14.2β16.8 cycles, RMSE ~18.9β22.4 cycles
- Checkpoints:
models/regression/
4. Microsoft Azure PdM β Fleet RAG Database
- Dataset: 876k hourly telemetry rows across 100 machines + error/maintenance/failure logs
- Approach: 7,966 natural language maintenance records synthesized, embedded with
all-MiniLM-L6-v2(384-d), indexed in FAISS - Index:
models/rag/faiss_index.bin(12.2 MB, exact L2 search) - LLM Explainer:
HuggingFaceTB/SmolLM2-135M-Instructrunning on CPU with deterministic anti-parroting post-processor
Risk Status Thresholds
| Range | Status |
|---|---|
| 0% β 15% | Healthy |
| 16% β 40% | At Risk |
| 41%+ | Critical |
How to Load the Models
import joblib
import torch
# Load classification ensemble
ensemble = joblib.load("models/classification/ai4i_ensemble_model.pkl")
scaler = joblib.load("data/processed/ai4i_scaler.pkl")
# Load LSTM checkpoint
checkpoint = torch.load("models/regression/best_cmapss_lstm_checkpoint.pt",
map_location="cpu")
# Load FAISS index
import faiss, pickle
index = faiss.read_index("models/rag/faiss_index.bin")
with open("models/rag/faiss_texts.pkl", "rb") as f:
texts = pickle.load(f)
Serving Dashboard
The full system is served via a FastAPI backend with an interactive web dashboard featuring:
- Real-time failure probability gauge and RUL countdown per machine
- Fleet health overview across all 100 machines
- LLM-generated Markdown diagnostic reports (RAG + SmolLM2)
- Automated production rescheduling with job reallocation audit log
pip install -r requirements.txt
python -m uvicorn app:app --host 127.0.0.1 --port 8000
Citation
If you use these models or datasets in your research, please credit the original dataset sources:
- AI4I 2020: UCI Machine Learning Repository
- NASA CMAPSS: NASA Prognostics Center of Excellence
- Microsoft Azure PdM: Microsoft Azure AI Gallery