Skip to content

About

A hybrid ML + LLM system that classifies automated test failures and auto-generates plain-English root cause explanations using RAG when confidence is low.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Triage Assistant

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.

System Architecture

                    +------------------------------------+
                    |  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  |
                                      +-----------------------+

Why a Hybrid ML + LLM Approach?

  • 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.

Directory Structure

  • 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.

Setup Instructions

  1. 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
  2. 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
  3. Configure Environment Variables: Copy .env.example to .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.


Step-by-Step Execution Guide

1. Generate Labeled Data

Generate synthetic, realistic failure logs:

python src/data_gen.py --count 150

This generates data/labeled/failures.csv.

2. Train the Classifier

Process features and train the Logistic Regression pipeline:

python src/train.py

This evaluates the model metrics and saves the model pipeline to src/model/classifier.pkl.

3. Ingest Knowledge Base

Index files under rag/knowledge_base/ into the local vector database:

python rag/ingest.py

4. Launch the API & Web Dashboard

Run the FastAPI server:

python -m uvicorn api.main:app --reload --host 127.0.0.1 --port 8000

The 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).


Security & Reliability Design

  • 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 /classify endpoint 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.

About

A hybrid ML + LLM system that classifies automated test failures and auto-generates plain-English root cause explanations using RAG when confidence is low.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages