Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Kr-Yogsa/ECE-BOT/llms.txt

Use this file to discover all available pages before exploring further.

ECE-BOT provides three dedicated hardware assistants — MELFA, PLC, and CNC — each trained on a curated set of question-and-answer patterns specific to that machine type. When a question closely matches known patterns, the chatbot replies instantly from its trained data. When it does not, Google Gemini generates a contextual response using the hardware’s description as a system prompt.

Hardware assistants

Each assistant is defined in data/hardware_config.json and backed by its own JSON data file in the data/ directory.
AssistantHardware typeData file
MELFAMitsubishi MELFA industrial robotsdata/melfa.json
PLCProgrammable logic controllersdata/plc.json
CNCCNC machining centresdata/cnc.json
Users switch between assistants using the hardware dropdown in the chat interface. Switching assistants changes the active intent model and the Gemini prompt context for all subsequent messages.

How the intent model works

ECE-BOT trains one model per hardware assistant at startup. Each model is a scikit-learn pipeline composed of a TF-IDF vectorizer followed by a Random Forest classifier with 100 estimators.
1

Load training data

ECE-BOT reads the JSON data file for each hardware assistant (for example, data/melfa.json). Each file contains a list of intents. Every intent has a tag, a list of patterns (example questions), and a list of responses.
melfa.json (excerpt)
{
  "intents": [
    {
      "tag": "melfa_startup",
      "patterns": [
        "how do i start melfa robot",
        "melfa startup steps",
        "how to power on melfa",
        "start robot sequence"
      ],
      "responses": [
        "For a basic MELFA startup, check safety conditions, power on the controller, release emergency stop, and then enable the robot from the teach pendant."
      ]
    }
  ]
}
2

Train TF-IDF + Random Forest pipeline

All patterns for a hardware assistant are fed into a TfidfVectorizer and a RandomForestClassifier inside a single scikit-learn Pipeline. The classifier maps each pattern to its intent tag. A minimum of two distinct intent classes is required; hardware data files with fewer classes are skipped.
3

Classify incoming messages

When a user sends a message, the trained model returns a probability distribution across all known intent tags. The tag with the highest probability is selected as the predicted intent, along with its confidence score.Before the classifier runs, the message is checked against an exact-pattern lookup. If the normalized message matches a stored pattern exactly, the corresponding response is returned immediately with a confidence of 1.0, bypassing the classifier.
4

Apply the confidence threshold

The predicted confidence is compared against the threshold of 0.75.
  • Confidence ≥ 0.75 — the predefined response for that intent is returned directly.
  • Confidence < 0.75 — the message is forwarded to Gemini for a generated response.
Every bot reply is stored in PostgreSQL with its response_source (intent_model or LLM) and the raw confidence score, so you can audit the model’s performance over time.

Gemini fallback

When the intent model’s confidence falls below 0.75, ECE-BOT calls Google Gemini with the hardware’s name and context description as a system prompt. For CNC questions, a dedicated CNC-specific handler is tried first; if it returns a transient error, the generic handler is used as a backup. The Gemini response is generated with the full conversation history so multi-turn follow-up questions work correctly.
The Gemini fallback requires a valid GEMINI_API_KEY in your environment. If the key is missing or the API is temporarily unavailable, ECE-BOT returns a user-facing error message rather than an empty reply.

Chat sessions

Every conversation is saved to PostgreSQL and tied to both a user and a hardware assistant.
  • Session title — automatically generated from the first user message by stripping stop words and picking up to three meaningful words. For example, “How do I reset a MELFA alarm?” becomes “MELFA Reset Alarm”.
  • Session history — the sidebar lists all previous sessions for the current user. Clicking a session restores the full conversation.
  • Hardware ID — each session stores the hardware_id (melfa, plc, or cnc) so the correct model is loaded when the session is resumed.
  • Messages — each message row stores the role (user or assistant), the content, the response_source, and the confidence score.
Pass session_id: null in the chat API request to start a new session. The API returns the new session_id in the response, which you can pass in subsequent requests to continue the same thread.

API reference

# Send a message
POST /chat
Authorization: Bearer <token>
Content-Type: application/json

{
  "message": "How do I clear a MELFA alarm?",
  "session_id": null
}
# List sessions for the sidebar
GET /chat/sessions
Authorization: Bearer <token>
# Retrieve messages in a session
GET /chat/session/<session_id>
Authorization: Bearer <token>

Build docs developers (and LLMs) love