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

Personalization Engine

The Personalization Engine learns user preferences over time and adapts AI responses to match individual interaction patterns, preferred visualization types, query complexity levels, and domain focus areas. It operates as an internal integration within the AI Service, feeding into the agent orchestrator and response generation pipeline.


Architecture

The personalization system is implemented in src/personalization/ with four components:

ComponentFilePurpose
Engineengine.pyCore personalization logic and preference computation
Modelsmodels.pyUser profile and preference data models
Feedback Collectorfeedback.pyIntegrates with the feedback system for implicit signals
Routerrouter.pyPersonalized routing decisions for agent selection

User Profile Model

Each user builds a profile over time through interactions:

class UserProfile:
    user_id: str
    tenant_id: str
    preferences: UserPreferences
    interaction_history: InteractionSummary
    skill_level: SkillLevel  # beginner, intermediate, advanced
    domain_expertise: dict[str, float]  # domain -> confidence
    created_at: datetime
    last_active: datetime

Preference Categories

CategoryTracked SignalsAdaptation
VisualizationChart types clicked, modified, or exportedDefault chart type selection
ComplexitySQL complexity of accepted queriesAdjust explanation detail level
DomainTables and metrics frequently queriedPrioritize relevant schema context
Response styleLength of preferred responsesAdjust verbosity
Time patternsActive hours, query frequencyProactive suggestion timing
Interaction modeChat vs. dashboard vs. direct SQLAdapt interface suggestions

Personalization Signals

The engine collects signals from multiple sources:

Explicit Signals

  • User sets preferred chart types in settings
  • User selects a persona during onboarding
  • User bookmarks specific dashboards or queries

Implicit Signals

  • Query topics and tables accessed
  • Visualization types accepted vs. modified
  • Response ratings and corrections
  • Session duration and engagement patterns
  • SQL complexity of accepted queries

Response Adaptation

The personalization engine influences responses at three points:

1. Agent Routing

class PersonalizedRouter:
    async def select_agent(self, query: str, profile: UserProfile) -> str:
        if profile.skill_level == SkillLevel.BEGINNER:
            return "guided_sql_agent"  # More explanatory
        return "standard_sql_agent"  # Concise responses

2. Context Assembly

The schema context retrieval is biased toward tables and columns the user frequently queries:

async def get_personalized_context(query: str, profile: UserProfile):
    base_context = await get_schema_context(query)
    # Boost relevance of frequently-used tables
    for table in profile.preferences.frequent_tables:
        base_context.boost(table, weight=1.5)
    return base_context

3. Response Formatting

Response detail level is adjusted based on user expertise:

Skill LevelSQL ExplanationVisualizationInsights
BeginnerFull step-by-stepSimple charts with annotationsDetailed business context
IntermediateKey highlightsStandard chartsRelevant comparisons
AdvancedMinimal (SQL only on request)Advanced chartsStatistical significance

Configuration

Environment VariableDefaultDescription
PERSONALIZATION_ENABLEDtrueEnable personalization engine
PERSONALIZATION_MIN_INTERACTIONS10Minimum interactions before personalizing
PERSONALIZATION_DECAY_DAYS30Days before old signals lose weight
PERSONALIZATION_PROFILE_TTL86400Profile cache TTL in seconds

Privacy

Personalization profiles respect user privacy settings:

  • Users can opt out of personalization entirely
  • Profiles are tenant-isolated and never shared across tenants
  • PII is stripped from interaction history before profile computation
  • Users can request profile deletion through the Privacy Center