learning

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustRuntimeConfidence

func AdjustRuntimeConfidence(baseConf float64, hasPreference bool, providerBias float64, isTimeMatch bool) float64

AdjustRuntimeConfidence adjusts a hypothetical runtime confidence based on learned factors. This implements the design doc formula: Base + Pref Boost + Bias + Time

func CalculatePreferenceConfidence

func CalculatePreferenceConfidence(successCount, totalCount int, avgQuality float64) float64

CalculatePreferenceConfidence computes the confidence score for a learned preference. It considers success rate, sample size, and consistency.

Types

type AnalysisResult

type AnalysisResult struct {
	UserID           string
	Timestamp        time.Time
	RequestsAnalyzed int
	NewPreferences   *PreferenceModel
	Suggestions      []string
}

AnalysisResult holds the result of a history analysis run.

type LearningEngine

type LearningEngine struct {
	// contains filtered or unexported fields
}

LearningEngine orchestrates learning from routing history.

func NewLearningEngine

func NewLearningEngine(cfg *config.LearningConfig, mem memory.MemoryManager) (*LearningEngine, error)

NewLearningEngine creates a new learning engine.

func (*LearningEngine) AnalyzeAll

func (le *LearningEngine) AnalyzeAll()

AnalyzeAll triggers analysis for all known users.

func (*LearningEngine) AnalyzeUser

func (le *LearningEngine) AnalyzeUser(ctx context.Context, apiKeyHash string) (*AnalysisResult, error)

AnalyzeUser performs deep analysis on a specific user's history.

func (*LearningEngine) ApplyPreferences

func (le *LearningEngine) ApplyPreferences(model *PreferenceModel) error

ApplyPreferences applies learned preferences to the memory system.

func (*LearningEngine) Start

func (le *LearningEngine) Start()

Start starts the background analysis routine.

func (*LearningEngine) Stop

func (le *LearningEngine) Stop()

Stop stops the background analysis.

type ModelPreference

type ModelPreference struct {
	Model       string  `json:"model"`
	Confidence  float64 `json:"confidence"`
	UsageCount  int     `json:"usage_count"`
	SuccessRate float64 `json:"success_rate"`
}

ModelPreference represents a specific preference for a model given an intent.

type PreferenceModel

type PreferenceModel struct {
	UserID           string                      `json:"user_id"`
	LastUpdated      time.Time                   `json:"last_updated"`
	TotalRequests    int                         `json:"total_requests"`
	ModelPreferences map[string]*ModelPreference `json:"model_preferences"` // Key: Intent
	ProviderBias     map[string]float64          `json:"provider_bias"`     // Key: Provider, Value: -1.0 to 1.0
	TimePatterns     map[string]*TimePattern     `json:"time_patterns"`     // Key: "weekday" or "weekend"
}

PreferenceModel represents a learned model of user preferences.

type TimePattern

type TimePattern struct {
	// Simple hourly distribution (0-23)
	HourlyUsage map[int]int `json:"hourly_usage"`
	// Peak hours where specific intents are more common
	PeakIntents map[int]string `json:"peak_intents"`
}

TimePattern represents usage patterns based on time of day.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL