AI Drift

AI Drift

32 files AI/ML

Abstract

AI Drift provides continuous monitoring and detection of AI decision drift within the Prismatic Platform, identifying when machine learning models begin producing outputs that deviate from their expected behavioral baselines. The engine leverages Elixir's concurrency model and OTP supervision trees to deliver robust, fault-tolerant drift detection pipelines that operate continuously without downtime. Built as app_ai_drift within the umbrella architecture, the application implements a complete AI governance framework (HRAiME-compliant) with 20+ modules, 9 database tables, and 3,120 lines of test code. Each monitored model runs in its own isolated process, ensuring that a failure in one detection pipeline cannot cascade to others.

1. Introduction

1.1 Problem Statement

AI systems deployed in production environments gradually change their behavior over time due to concept drift, data distribution shifts, and model degradation. In regulated domains such as HR decision-making, credit scoring, and compliance screening, these behavioral changes can violate regulatory requirements and introduce unintended bias. Without continuous monitoring, organizations cannot demonstrate that their AI systems operate within acceptable parameters -- a requirement under emerging AI governance frameworks including the EU AI Act and HR-specific AI monitoring mandates.

AI Drift addresses this by providing continuous statistical monitoring of model outputs against established baselines, with multi-algorithm detection, risk scoring, and governance-compliant reporting.

1.2 Design Goals

  1. Multi-algorithm detection -- simultaneous application of KS test, PSI, Jensen-Shannon divergence, Wasserstein distance, and Anderson-Darling test for comprehensive drift coverage.
  2. Process-per-model isolation -- each monitored model runs in a supervised process preventing cascading failures.
  3. HRAiME governance compliance -- intent classification, risk accumulation, narrative generation, and stakeholder-specific alert routing.
  4. Multi-tenant security -- full tenant isolation with encrypted data separation and RBAC access control.
  5. NABLA epistemic integration -- all findings carry confidence scores with provenance chains validated by the Trinity Gate.
  6. Real-time and batch -- both streaming event ingestion and historical batch analysis capabilities.

1.3 Scope

AI Drift covers drift detection, risk scoring, and governance reporting. It does not implement the ML models themselves (which are external) or the visualization dashboard (handled by AI Drift Web). The REST API layer is pending Phase 4 integration.

2. Architecture

2.1 System Design

Model Output Stream ──> Ingestion Pipeline ──> Baseline Comparator ──> Drift Scorer
        │                      │                       │                    │
   Raw Predictions        Normalization           Statistical Tests    PSI / KS / JSD
   Feature Vectors        Windowing               Threshold Check      Confidence Score
        │                      │                       │                    │
        └──────────────────────┴───────────────────────┴────────────────────┘
                                        │
                                  Alert Dispatcher ──> PubSub ──> Dashboard / API
                                        │
                                  Governance Engine ──> Narrative + Compliance
                                        │
                                  Trend Analyzer ──> Storage ──> Historical Archive

2.2 Core Components

ModuleResponsibility
AppAiDrift.ApplicationOTP application with supervised GenServer components
AppAiDrift.Detection.DriftDetectorGenServer: multi-algorithm drift detection on event streams
AppAiDrift.Detection.BaselineManagerGenServer: initial, rolling, and seasonal baseline management
AppAiDrift.Detection.DriftAlgorithmsStatistical algorithms: KS, PSI, JS, Wasserstein, Anderson-Darling
AppAiDrift.Detection.WindowManagerSliding window management for temporal drift analysis
AppAiDrift.Ingestion.EventProcessorGenServer: high-throughput batch event ingestion
AppAiDrift.Risk.RiskScorerGenServer: multi-dimensional risk scoring with decay
AppAiDrift.Risk.ImpactAnalyzerBusiness impact assessment for detected drift
AppAiDrift.Risk.ThresholdManagerDynamic threshold management based on model characteristics
AppAiDrift.Features.ExtractorStatistical, content, confidence, and temporal feature extraction
AppAiDrift.GovernanceUnified HRAiME governance interface
AppAiDrift.Governance.DecisionRegistrySystem identity and lifecycle management
AppAiDrift.Governance.IntentClassifierDrift intent classification (routine, optimization, emergency, etc.)
AppAiDrift.Governance.RiskAccumulationCumulative risk tracking with configurable decay
AppAiDrift.Governance.NarrativeGeneratorHuman-readable governance reports for stakeholders
AppAiDrift.Governance.AlertRouterRole-based alert routing (executive, compliance, technical)
AppAiDrift.Security.MultiTenantGenServer: tenant isolation with encrypted separation
AppAiDrift.Statistics.AndersonDarlingAnderson-Darling tail-sensitive statistical test
AppAiDrift.Statistics.CramerVonMisesCramer-von-Mises distributional test
AppAiDrift.Utils.HyperLogLogProbabilistic cardinality estimation (4-16 bit precision)

2.3 Process Topology

AppAiDrift.Application (Supervisor, :one_for_one)
+-- AppAiDrift.Security.MultiTenant (GenServer, priority: 110)
|     Tenant context isolation, encrypted data separation
+-- AppAiDrift.Ingestion.EventProcessor (GenServer, priority: 100)
|     High-throughput batch event ingestion with configurable batch size
+-- AppAiDrift.Detection.DriftDetector (GenServer, priority: 100)
|     Multi-algorithm drift detection with baseline comparison
+-- AppAiDrift.Detection.BaselineManager (GenServer, priority: 90)
|     Baseline lifecycle: initial (30-day), rolling (7-day), seasonal (52-week)
+-- AppAiDrift.Risk.RiskScorer (GenServer, priority: 80)
|     Risk calculation with weighted components and temporal decay
+-- AppAiDrift.WebhookNotifier (GenServer, priority: 60)
      Alert dispatch via webhooks and PubSub

2.4 Data Flow

Events enter through the EventProcessor GenServer, which buffers them in configurable batches (default 1,000 events, 100ms timeout). The DriftDetector applies multiple statistical tests against baselines managed by BaselineManager. Detected drift is scored by RiskScorer using weighted multi-dimensional assessment (drift magnitude 30%, confidence impact 25%, temporal risk 20%, business impact 15%, data quality 10%). The Governance module classifies drift intent, generates stakeholder narratives, and routes alerts to appropriate roles. All results persist to PostgreSQL through 9 dedicated tables with 20+ indexes including GIN indexes on JSONB features.

3. Implementation

3.1 Detection Algorithms

AlgorithmPurposeComplexitySensitivity
Kolmogorov-SmirnovDistribution comparisonO(n log n)General
PSI (Population Stability Index)Categorical driftO(n)Categorical features
Jensen-Shannon DivergenceSymmetric KL divergenceO(n)Probability distributions
Wasserstein DistanceOptimal transportO(n log n)Distribution shape
Anderson-DarlingTail-sensitive testingO(n log n)Distribution tails
Cramer-von-MisesGoodness of fitO(n log n)Distribution differences

3.2 Risk Components

ComponentWeightDescription
Drift Magnitude30%Size of detected statistical drift
Confidence Impact25%Effect on model prediction confidence
Temporal Risk20%Time-based risk factors and trend acceleration
Business Impact15%Financial and operational impact assessment
Data Quality10%Input data quality degradation signals

3.3 API Surface

# Ingest events for drift monitoring
{:ok, _} = AppAiDrift.Ingestion.EventProcessor.process_event(%{
  event_type: :inference,
  system_id: "credit_scoring_v3",
  tenant_id: "tenant-123",
  timestamp: DateTime.utc_now(),
  payload: %{prediction: 0.85, input_hash: "abc123"},
  confidence: 0.92
})

# Detect drift on event batch
{:ok, drift} = AppAiDrift.Detection.DriftDetector.detect(events)
# => %{detected: true, magnitude: 0.45, confidence: 0.97, algorithm: :ks_test}

# Score risk with multi-dimensional assessment
{:ok, risk} = AppAiDrift.Risk.RiskScorer.score(drift)
# => %{score: 0.72, severity: :high, components: %{...}, recommendations: [...]}

# Run complete governance pipeline
{:ok, result} = AppAiDrift.Governance.process_drift_event(drift_event, system_context)
# => %{classification: :performance_optimization, risk_level: :medium,
#      narrative_id: "narr_abc123", alerts_sent: [:risk_manager, :technical_lead]}

3.4 Configuration

config :app_ai_drift,
  detection_threshold: 0.95,
  min_samples: 100,
  window_size: 1000,
  max_batch_size: 1000,
  batch_timeout_ms: 100,
  risk_decay_factor: 0.95,
  accumulation_window: 3_600_000,
  baseline_initial_days: 30,
  rolling_window_days: 7,
  seasonal_lookback_weeks: 52

4. Integration

4.1 Dependencies

ApplicationRelationship
Prismatic KernelCore runtime services and process supervision
Prismatic CoreShared protocols, types, and utilities
Prismatic Storage CoreStorage abstraction behaviors
Prismatic Storage EctoPostgreSQL persistence for drift data
Prismatic TelemetryPerformance metrics and distributed tracing

4.2 Dependents

ApplicationRelationship
AI Drift WebLiveView dashboard for drift visualization

4.3 External Dependencies

Ecto SQL with Postgrex for PostgreSQL, Oban for background job processing, NimbleCSV for data import, Timex for datetime utilities, Decimal for numeric precision, LibGraph for graph structures, and StreamData for property-based testing.

5. Testing Strategy

5.1 Test Structure (3,120 LOC)

test/app_ai_drift/
+-- core/          -- Schema validation tests
+-- detection/     -- Algorithm correctness tests
+-- features/      -- Feature extraction accuracy tests
+-- risk/          -- Risk scoring tests
+-- security/      -- Multi-tenant isolation tests
+-- statistics/    -- Statistical test validation
+-- governance/    -- Governance pipeline tests
+-- utils/         -- Utility function tests

5.2 Property-Based Testing

StreamData generators produce random event sequences, baseline distributions, and risk parameters to verify that drift detection algorithms maintain statistical correctness and that risk scores remain within valid bounds under all valid inputs.

6. Performance

6.1 Benchmarks

OperationLatencyNotes
Event ingestion (batch of 1,000)< 100msBuffered batch processing
KS test (1,000 samples)< 10msO(n log n) comparison
PSI calculation< 5msO(n) categorical drift
Full risk scoring< 50msMulti-dimensional weighted assessment
Governance pipeline< 200msClassification + narrative + routing

6.2 Database Schema

9 tables with monthly time-based partitioning: ai_drift_events, ai_drift_baselines, ai_drift_detections, ai_drift_risk_scores, ai_drift_alerts, ai_drift_audit_trail, ai_drift_lineage. 20+ indexes on tenant_id, system_id, timestamp, and severity with GIN indexes on JSONB features.

7. NABLA Compliance

Every drift assessment is annotated with confidence scores derived from the platform's NABLA epistemic framework. The signal plurality axiom is enforced by requiring multiple statistical tests to agree before a drift finding is reported. The provenance axiom is satisfied through complete derivation chains linking every finding to its source events and algorithms. The Trinity Gate validation ensures structural, logical, and formal consistency of all reported findings.

8. Governance Framework (HRAiME Compliant)

8.1 Intent Classification

CategoryDescriptionExample
routine_maintenanceRegular updates, retrainingScheduled model refresh
performance_optimizationAccuracy improvementsFeature engineering changes
policy_changeBusiness rule updatesThreshold adjustments
emergency_responseCritical fixesBias correction
regulatory_complianceCompliance changesNew regulatory requirement
data_distribution_shiftNatural driftSeasonal market changes

8.2 Non-Conclusion Boundaries

The system explicitly does NOT: analyze individual behavior, evaluate personal performance, infer intent or motivation, make predictions about individuals, establish causal relationships, or make value judgments about people.

9. Security

9.1 Multi-Tenant Isolation

AppAiDrift.Security.MultiTenant.with_tenant(tenant_id, fn ->
  # All operations scoped to tenant with encrypted data separation
  AppAiDrift.Detection.DriftDetector.detect(events)
end)

9.2 RBAC Roles

RolePermissions
AdminFull access to all drift data and configuration
AnalystRead + analyze drift data, acknowledge alerts
ViewerRead-only access to dashboards and reports
AuditorAudit trail access for compliance review

10. Future Work

Phase 4 integration pending: REST API endpoints, webhook HTTP dispatch, dashboard connection, and database persistence completion. Planned enhancements include real-time streaming transcription, cross-model drift correlation, and automated remediation recommendations.

References


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL