MATIH Platform is in active MVP development. Documentation reflects current implementation status.
12. AI Service
Integrations
AI Copilot

AI Copilot

The AI Copilot provides contextual, proactive assistance throughout the MATIH platform. Unlike the reactive chat interface that responds to user questions, the copilot anticipates user needs, offers suggestions, explains data anomalies, and guides users through complex analytical workflows. It operates as a supplementary integration within the AI Service.


Copilot Capabilities

CapabilityDescriptionTrigger
Query suggestionsRecommends next questions based on current contextAfter query results are displayed
Anomaly alertsHighlights unusual data patterns in resultsWhen statistical outliers are detected
Schema guidanceSuggests relevant tables and columnsDuring query composition
Workflow assistanceGuides multi-step analytical workflowsWhen complex questions are decomposed
Error recoverySuggests fixes for failed queriesOn SQL validation or execution error
Dashboard buildingRecommends widgets based on query patternsDuring dashboard creation

Copilot Modes

The copilot operates in three modes, configurable per user or tenant:

ModeBehaviorUse Case
passiveOnly responds when explicitly invokedPower users who prefer control
balancedOffers suggestions at key decision pointsDefault for most users
proactiveContinuously provides contextual assistanceNew users and onboarding

Suggestion API

The copilot exposes endpoints for frontend consumption:

GET  /api/v1/copilot/suggestions?session_id=...&context=dashboard
POST /api/v1/copilot/explain
POST /api/v1/copilot/guide

Suggestion Response

{
  "suggestions": [
    {
      "type": "follow_up_query",
      "content": "Would you like to see this data broken down by month?",
      "confidence": 0.87,
      "action": {
        "type": "send_message",
        "payload": "Show monthly breakdown of revenue by region"
      }
    },
    {
      "type": "anomaly_alert",
      "content": "Revenue in APAC dropped 23% compared to last quarter",
      "confidence": 0.92,
      "severity": "warning"
    }
  ]
}

Context Sources

The copilot assembles context from multiple sources to generate relevant suggestions:

SourceDataWeight
Current sessionRecent messages and resultsHigh
User profilePersonalization preferencesMedium
Schema metadataTable relationships and descriptionsMedium
Organization patternsCommon queries by other usersLow
Historical anomaliesPreviously detected data patternsLow

Anomaly Detection

The copilot runs lightweight statistical checks on query results:

class AnomalyDetector:
    def detect(self, data: DataFrame, context: QueryContext) -> list[Anomaly]:
        anomalies = []
        # Check for significant deviations from historical averages
        for column in data.numeric_columns:
            if self._is_outlier(data[column], method="iqr"):
                anomalies.append(Anomaly(
                    column=column,
                    type="outlier",
                    description=f"{column} contains values outside expected range",
                ))
        return anomalies

Workflow Guidance

For complex multi-step analyses, the copilot provides a guided workflow:

  1. Decomposition: Breaks the question into manageable steps
  2. Navigation: Guides the user through each step with suggestions
  3. Validation: Confirms intermediate results before proceeding
  4. Synthesis: Combines results into a final summary

Configuration

Environment VariableDefaultDescription
COPILOT_ENABLEDtrueEnable copilot features
COPILOT_DEFAULT_MODEbalancedDefault copilot mode
COPILOT_SUGGESTION_LIMIT5Maximum suggestions per context
COPILOT_ANOMALY_THRESHOLD2.0Standard deviations for outlier detection
COPILOT_MIN_CONFIDENCE0.7Minimum confidence to surface a suggestion