Skip to main content

Personalization

Build deeply personalized experiences by learning user preferences over time.

Overview

Trix enables personalization that goes beyond simple user preferences. By building a rich understanding of each user over time, you can create truly adaptive experiences.

Learning Preferences

async function trackPreference(userId: string, category: string, preference: string) {
  await trix.memories.create({
    content: preference,
    spaceId: userId,
    tags: ['preferences'],
    metadata: {
      category,
      learnedAt: new Date().toISOString(),
      confidence: 0.8
    }
  });
}

// Examples
await trackPreference(userId, 'ui', 'Prefers dark mode');
await trackPreference(userId, 'content', 'Interested in AI and machine learning');
await trackPreference(userId, 'communication', 'Prefers concise responses');

Learning from Implicit Signals

async function trackBehavior(userId: string, action: Action, context: Context) {
  // Don't store every action, analyze patterns
  const insight = await analyzeAction(action, context);

  if (insight.isSignificant) {
    await trix.memories.create({
      content: insight.preference,
      spaceId: userId,
      tags: ['behavioral'],
      metadata: {
        source: 'implicit',
        action: action.type,
        confidence: insight.confidence
      }
    });
  }
}

// Example: User consistently reads long-form content
await trackBehavior(userId, {
  type: 'read',
  contentType: 'article',
  duration: 480 // 8 minutes
}, { articleLength: 'long' });

Analyze patterns before storing to avoid overwhelming the memory with noise.

Personalized Content

async function getPersonalizedContent(userId: string, contentPool: Content[]) {
  // Get user preferences
  const preferences = await trix.memories.list({
    q: 'content interests preferences',
    spaceId: userId,
    tags: ['preferences', 'behavioral'],
    limit: 10
  });

  // Score content based on preference alignment
  const scoredContent = contentPool.map(content => ({
    ...content,
    score: calculatePreferenceScore(content, preferences.data)
  }));

  // Return top matches
  return scoredContent
    .sort((a, b) => b.score - a.score)
    .slice(0, 10);
}

Adaptive UI

async function getUIPreferences(userId: string) {
  const results = await trix.memories.list({
    q: 'UI interface preferences',
    spaceId: userId,
    tags: ['preferences']
  });

  // Extract specific settings from memories
  return {
    theme: extractPreference(results.data, 'theme') || 'auto',
    density: extractPreference(results.data, 'density') || 'comfortable',
    animations: extractPreference(results.data, 'animations') !== false
  };
}

Combine explicit preferences with learned behavior for the best personalization results.