Skip to main content

Overview

Learning commands analyze historical routing data to identify patterns, optimize model selection, and automatically apply improvements based on past successes and failures.
Learning requires the Memory system to be enabled. Run switchAILocal memory init first.

Commands

status

Display learning system status and statistics.
Output:

analyze

Analyze routing history and generate optimization recommendations.
string
Analyze patterns for specific user API key hash (default: all users)
Example:
Output:
Analysis considers success rate, latency, error types, and time-of-day patterns.

apply

Apply learned optimizations to routing configuration.
string
Apply optimizations for specific user (default: all users)
Example:
Output:
Applied optimizations modify your routing configuration. Back up your config before applying.

reset

Remove all learned optimizations and restore original configuration.
Output:

How Learning Works

Analysis Metrics

The learning system considers:
  1. Success Rate - Percentage of successful completions
  2. Latency - Average response time
  3. Error Types - Categorized failure reasons
  4. Time Patterns - Success/failure correlation with time of day
  5. User Patterns - User-specific preferences
  6. Quality Signals - Response quality indicators (if available)

Pattern Recognition

Learning identifies:
  • High-performing routes - Intent + model combinations with >85% success
  • Problematic patterns - Routes with <70% success or high latency
  • Time-of-day effects - Provider performance variations by hour
  • User preferences - Per-user successful model choices
  • Cascading opportunities - When to escalate to better models

Learning Configuration

Configure learning behavior in config.yaml:
config.yaml

Configuration Options

boolean
Enable the learning system (default: true)
integer
Minimum routing decisions required before pattern analysis (default: 50)
number
Minimum confidence score (0-1) for applying optimizations (default: 0.8)
boolean
Automatically apply learned optimizations without manual approval (default: false)
integer
Seconds between automatic analyses (default: 86400 = 24 hours)

Use Cases

The learning system detects when specific providers consistently fail for certain intents and creates steering rules to avoid them:
Learning identifies when cheaper/faster local models perform well and automatically prefers them:
  • Detects ollama:llama3.2 success for simple queries
  • Creates steering rules to prefer local models
  • Reduces cloud API costs by 40-60%
When cascade signals indicate poor quality, learning adjusts the matrix to use better models by default:
  • Detects low quality scores for fast intent
  • Upgrades default model from switchai-fast to switchai-chat
  • Improves overall response quality
Per-user analysis creates personalized routing:
Generates user-specific steering rules based on their usage patterns.

Best Practices

Run analysis weekly - Execute learning analyze every 7 days to identify new patterns.
Review before applying - Always review recommendations with learning analyze before running learning apply.
Start with manual mode - Keep auto_apply: false until you’re confident in the learning patterns.

Troubleshooting

  • Ensure memory system is initialized: memory status
  • Verify sufficient routing decisions: memory history --limit 100
  • Check min_samples threshold in config
  • Wait for more diverse usage patterns
  • Increase sample size (more routing decisions)
  • Check for inconsistent success patterns
  • Verify providers are stable (not flapping)
  • Review error distribution in memory logs
  • Check file permissions on steering directory
  • Verify server has write access to config
  • Run steering validate to check generated rules
  • Check for conflicting manual steering rules

See Also