An intelligent, hybrid ML + LLM diagnostic system that classifies automated end-to-end test failures (e.g., Playwright or CI pipelines) and automatically generates plain-English explanations using Retrieval-Augmented Generation (RAG) when classification confidence is low.
+------------------------------------+
| Failing Test Log (error, trace) |
+-----------------+------------------+
|
v
+------------------------------------+
| Machine Learning Model |
| (TF-IDF + Logistic Reg) |
+-----------------+------------------+
|
+----------------+----------------+
| Is Classifier Confidence |
| >= Threshold (e.g., 0.85)? |
+-------/------------------\-------+
/ \
(Yes) / \ (No)
v v
+-------------------------+ +-------------------+
| Return Label Directly | | RAG Query |
| (Flaky, Bug, Env) | +---------+---------+
+-------------------------+ |
v
+-------------------+
| Local Vector Store|
| (ChromaDB / TFIDF)|
+---------+---------+
| (Retrieve)
v
+-------------------+
| Relevant Context |
+---------+---------+
|
v
+-------------------+
| Local LLM (Ollama)| (qwen3:8b)
| + Prompt Guard |
+---------+---------+
|
v
+-----------------------+
| Predicted Label + |
| Detailed Explanation |
+-----------------------+
- Cost Efficiency: Routing every single CI test failure to an LLM API would quickly accumulate massive costs. The local machine learning classifier runs in milliseconds at zero cost.
- Low Latency: High-volume CI environments need sub-second triage. The ML classifier provides fast results for standard, predictable failures.
- Intelligent Explanations for Ambiguous Cases: If a database is intermittently refusing connections, or there's a novel race condition, the ML model's confidence drops below the threshold (e.g., 85%). Only then do we trigger the LLM to search our internal RAG knowledge base (docs, past resolved incidents) and generate a rich, actionable root-cause description.
data/: Contains raw and generated datasets.src/: Core Python pipeline source code.data_gen.py: Script to generate synthetic Playwright/CI test failure records.features.py: Preprocessing text logic and numeric feature scaling.train.py: Preprocessing and model training script.
rag/: Vector database and semantic search components.knowledge_base/: Structured knowledge notes (markdown) about timeouts, environment issues, etc.ingest.py: Parses the knowledge base and inserts it into the local store.retrieve.py: Cosine similarity-based retrieval script.
api/: FastAPI web backend.main.py: Main app featuring classification, rate limiting, and Claude generation.schemas.py: Pydantic payload models.
dashboard/: Single-page visual user interface.eval/: Evaluates the pipeline's classification using hand-picked samples.
-
Clone & Environment Setup: Ensure Python 3.8+ is installed. Create and activate a virtual environment, then install the dependencies:
python -m venv venv .\venv\Scripts\activate # On Windows # source venv/bin/activate # On Unix/macOS pip install -r requirements.txt
-
Install & Start Ollama: Install Ollama on your local machine (from ollama.com). Pull and run the specified local LLM model:
ollama pull qwen3:8b ollama run qwen3:8b
-
Configure Environment Variables: Copy
.env.exampleto.env:cp .env.example .env
Note: No API key or internet connection is required for the LLM step since the model runs entirely locally via Ollama.
Generate synthetic, realistic failure logs:
python src/data_gen.py --count 150This generates data/labeled/failures.csv.
Process features and train the Logistic Regression pipeline:
python src/train.pyThis evaluates the model metrics and saves the model pipeline to src/model/classifier.pkl.
Index files under rag/knowledge_base/ into the local vector database:
python rag/ingest.pyRun the FastAPI server:
python -m uvicorn api.main:app --reload --host 127.0.0.1 --port 8000The API documentation is accessible at http://127.0.0.1:8000/docs, and the UI dashboard is available at http://127.0.0.1:8000/static/index.html (or open the dashboard/index.html directly).
- Prompt Injection Defense: Before forwarding logs to the LLM, the API verifies that the log contents do not contain instructions meant to hijack the LLM prompt.
- Rate Limiting: Built-in simple rate-limiting on the
/classifyendpoint prevents API key depletion and brute forcing. - RAG Robustness: If ChromaDB installation issues occur on Windows systems, the ingestion and retrieval systems automatically fall back to an internal TF-IDF-based cosine-similarity system, making the app highly portable.