Documentation
ΒΆ
Index ΒΆ
- func Hash(key string, size uint64) uint64
- func Rollout(key string, percentage uint64) bool
- type AnalyticsEngine
- func (a *AnalyticsEngine) CreateMetric(metric *Metric) error
- func (a *AnalyticsEngine) CreateSegment(segment *Segment) error
- func (a *AnalyticsEngine) ExportAnalytics(ctx context.Context, analytics *ExperimentAnalytics, format string) ([]byte, error)
- func (a *AnalyticsEngine) GenerateAnalytics(ctx context.Context, experimentID string, timeRange TimeRange) (*ExperimentAnalytics, error)
- func (a *AnalyticsEngine) RecordMetricValue(ctx context.Context, value MetricValue) error
- type AnalyticsMetrics
- type AnalyticsStorage
- type Assignment
- type BanditAlgorithm
- type BanditAnalysis
- type BanditArm
- type BanditArmAnalysis
- type BanditEngine
- func (b *BanditEngine) CreateBanditExperiment(exp *BanditExperiment) error
- func (b *BanditEngine) DeleteExperiment(id string) bool
- func (b *BanditEngine) Experiments() []*BanditExperiment
- func (b *BanditEngine) GetBanditResults(experimentID string) (*BanditAnalysis, error)
- func (b *BanditEngine) GetExperimentRecommendation(experimentID string) (*BanditRecommendation, error)
- func (b *BanditEngine) Metrics() BanditMetrics
- func (b *BanditEngine) RecordReward(experimentID, armID, userID string, reward float64, success bool, ...) error
- func (b *BanditEngine) SelectArm(experimentID, userID string, context map[string]any) (*BanditArm, error)
- func (b *BanditEngine) StopExperiment(experimentID string) error
- type BanditExperiment
- type BanditMetrics
- type BanditRecommendation
- type BanditResult
- type BanditStorage
- type BiasDetectionConfig
- type ConfidenceInterval
- type ConfigChange
- type ConfigManager
- func (c *ConfigManager) CreateExperimentConfig(ctx context.Context, config *ExperimentConfig) error
- func (c *ConfigManager) CreateFeatureFlag(ctx context.Context, flag *FeatureFlag) error
- func (c *ConfigManager) DeleteExperimentConfig(ctx context.Context, experimentID string) error
- func (c *ConfigManager) DeleteFeatureFlag(ctx context.Context, flagID string) error
- func (c *ConfigManager) EvaluateFeatureFlag(ctx context.Context, flagID, userID string, ...) (*FeatureFlagResult, error)
- func (c *ConfigManager) GetExperimentConfig(ctx context.Context, experimentID string) (*ExperimentConfig, error)
- func (c *ConfigManager) GetFeatureFlag(ctx context.Context, flagID string) (*FeatureFlag, error)
- func (c *ConfigManager) GetMetrics() ConfigMetrics
- func (c *ConfigManager) ListExperimentConfigs(ctx context.Context) ([]*ExperimentConfig, error)
- func (c *ConfigManager) ListFeatureFlags(ctx context.Context) ([]*FeatureFlag, error)
- func (c *ConfigManager) ValidateConfig(config interface{}) error
- func (c *ConfigManager) WatchConfig(ctx context.Context, key string) (<-chan ConfigChange, error)
- type ConfigMetrics
- type ConfigProvider
- type ConfigStorage
- type ConversionEvent
- type Experiment
- type ExperimentAnalytics
- type ExperimentConfig
- type ExperimentEngine
- func (e *ExperimentEngine) AssignVariant(ctx context.Context, userID, experimentID string, ...) (*Assignment, error)
- func (e *ExperimentEngine) CreateExperiment(exp *Experiment) error
- func (e *ExperimentEngine) GetExperimentResults(experimentID string) (*ExperimentResults, error)
- func (e *ExperimentEngine) RecordConversion(ctx context.Context, event *ConversionEvent) error
- type ExperimentResults
- type ExperimentStatus
- type ExperimentStore
- type FeatureFlag
- type FeatureFlagResult
- type FeatureFlagRule
- type InMemoryAnalyticsStorage
- func (s *InMemoryAnalyticsStorage) GetMetricValues(ctx context.Context, experimentID string, timeRange TimeRange) ([]MetricValue, error)
- func (s *InMemoryAnalyticsStorage) GetSegments(ctx context.Context) ([]*Segment, error)
- func (s *InMemoryAnalyticsStorage) SaveMetricValue(ctx context.Context, value MetricValue) error
- func (s *InMemoryAnalyticsStorage) SaveSegment(ctx context.Context, segment *Segment) error
- type InMemoryBanditStorage
- func (s *InMemoryBanditStorage) ListResults(expID string, limit int) ([]BanditResult, error)
- func (s *InMemoryBanditStorage) SaveArm(expID string, arm *BanditArm) error
- func (s *InMemoryBanditStorage) SaveExperiment(exp *BanditExperiment) error
- func (s *InMemoryBanditStorage) SaveResult(result BanditResult) error
- type InMemoryConfigProvider
- func (p *InMemoryConfigProvider) DeleteConfig(ctx context.Context, key string) error
- func (p *InMemoryConfigProvider) GetConfig(ctx context.Context, key string) (interface{}, error)
- func (p *InMemoryConfigProvider) ListConfigs(ctx context.Context, prefix string) (map[string]interface{}, error)
- func (p *InMemoryConfigProvider) SetConfig(ctx context.Context, key string, value interface{}) error
- func (p *InMemoryConfigProvider) Watch(ctx context.Context, key string) (<-chan ConfigChange, error)
- type InMemoryConfigStorage
- func (s *InMemoryConfigStorage) ListExperimentConfigs() ([]*ExperimentConfig, error)
- func (s *InMemoryConfigStorage) ListFeatureFlags() ([]*FeatureFlag, error)
- func (s *InMemoryConfigStorage) SaveExperimentConfig(config *ExperimentConfig) error
- func (s *InMemoryConfigStorage) SaveFeatureFlag(flag *FeatureFlag) error
- type InMemoryExperimentStore
- func (s *InMemoryExperimentStore) GetAssignment(userID, experimentID string) (*Assignment, error)
- func (s *InMemoryExperimentStore) GetExperiment(id string) (*Experiment, error)
- func (s *InMemoryExperimentStore) ListAssignments(experimentID string) ([]*Assignment, error)
- func (s *InMemoryExperimentStore) ListConversions(experimentID string) ([]*ConversionEvent, error)
- func (s *InMemoryExperimentStore) ListExperiments() ([]*Experiment, error)
- func (s *InMemoryExperimentStore) SaveAssignment(assignment *Assignment) error
- func (s *InMemoryExperimentStore) SaveConversion(event *ConversionEvent) error
- func (s *InMemoryExperimentStore) SaveExperiment(exp *Experiment) error
- type InMemoryRecommendationStorage
- func (s *InMemoryRecommendationStorage) ListRecommendations(userID string, limit int) ([]Recommendation, error)
- func (s *InMemoryRecommendationStorage) SaveInteraction(interaction Interaction) error
- func (s *InMemoryRecommendationStorage) SaveItem(item *Item) error
- func (s *InMemoryRecommendationStorage) SaveRecommendation(rec Recommendation) error
- func (s *InMemoryRecommendationStorage) SaveUser(user *User) error
- type Interaction
- type Item
- type Metric
- type MetricConfig
- type MetricSummary
- type MetricType
- type MetricValue
- type NoveltyConfig
- type OutlierConfig
- type PowerAnalysisConfig
- type QualityControlConfig
- type Recommendation
- type RecommendationEngine
- func (r *RecommendationEngine) AddItem(item *Item)
- func (r *RecommendationEngine) AddUser(user *User)
- func (r *RecommendationEngine) GetRecommendations(ctx context.Context, userID string, count int, algorithm RecommendationType) ([]Recommendation, error)
- func (r *RecommendationEngine) RecordInteraction(interaction Interaction)
- func (r *RecommendationEngine) SetAlgorithmWeights(content, collaborative, popularity, trending float64) error
- type RecommendationMetrics
- type RecommendationStorage
- type RecommendationType
- type RolloutConfig
- type RuleAction
- type RuleCondition
- type SRMConfig
- type SampleSizeConfig
- type Segment
- type SegmentAnalysis
- type SegmentCriteria
- type SimilarUser
- type StatisticalTest
- type StoppingRule
- type TargetingRule
- type TimeRange
- type TimeSeriesPoint
- type User
- type Variant
- type VariantResults
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type AnalyticsEngine ΒΆ
type AnalyticsEngine struct {
// contains filtered or unexported fields
}
AnalyticsEngine provides comprehensive analytics capabilities Now supports pluggable storage and metrics
func NewAnalyticsEngine ΒΆ
func NewAnalyticsEngine() *AnalyticsEngine
NewAnalyticsEngine creates a new analytics engine (default in-memory)
func NewAnalyticsEngineWithStorage ΒΆ
func NewAnalyticsEngineWithStorage(storage AnalyticsStorage, metricsObs *AnalyticsMetrics) *AnalyticsEngine
NewAnalyticsEngine creates a new analytics engine with storage and metrics
func (*AnalyticsEngine) CreateMetric ΒΆ
func (a *AnalyticsEngine) CreateMetric(metric *Metric) error
CreateMetric creates a new metric definition
func (*AnalyticsEngine) CreateSegment ΒΆ
func (a *AnalyticsEngine) CreateSegment(segment *Segment) error
CreateSegment creates a new user segment (now uses storage and metrics)
func (*AnalyticsEngine) ExportAnalytics ΒΆ
func (a *AnalyticsEngine) ExportAnalytics(ctx context.Context, analytics *ExperimentAnalytics, format string) ([]byte, error)
ExportAnalytics exports analytics data in various formats
func (*AnalyticsEngine) GenerateAnalytics ΒΆ
func (a *AnalyticsEngine) GenerateAnalytics(ctx context.Context, experimentID string, timeRange TimeRange) (*ExperimentAnalytics, error)
GenerateAnalytics generates comprehensive analytics for an experiment (now uses storage)
func (*AnalyticsEngine) RecordMetricValue ΒΆ
func (a *AnalyticsEngine) RecordMetricValue(ctx context.Context, value MetricValue) error
RecordMetricValue records a value for a metric (now uses storage and metrics)
type AnalyticsMetrics ΒΆ
type AnalyticsMetrics struct {
MetricValueCount int64
SegmentCount int64
LastError error
LastOperation string
}
AnalyticsMetrics holds operational metrics for observability (e.g., counts, error rates, latency, etc.)
type AnalyticsStorage ΒΆ
type AnalyticsStorage interface {
SaveMetricValue(ctx context.Context, value MetricValue) error
GetMetricValues(ctx context.Context, experimentID string, timeRange TimeRange) ([]MetricValue, error)
SaveSegment(ctx context.Context, segment *Segment) error
GetSegments(ctx context.Context) ([]*Segment, error)
}
AnalyticsStorage defines the interface for persistent analytics storage (e.g., for metric values, segments, etc.)
type Assignment ΒΆ
type Assignment struct {
UserID string `json:"user_id"`
ExperimentID string `json:"experiment_id"`
VariantID string `json:"variant_id"`
AssignedAt time.Time `json:"assigned_at"`
Attributes map[string]string `json:"attributes"`
}
Assignment represents a user's assignment to an experiment variant
type BanditAlgorithm ΒΆ
type BanditAlgorithm string
BanditAlgorithm represents different bandit algorithms
const ( EpsilonGreedy BanditAlgorithm = "epsilon_greedy" UCB BanditAlgorithm = "ucb" // Upper Confidence Bound ThompsonSampling BanditAlgorithm = "thompson" // Thompson Sampling BayesianBandit BanditAlgorithm = "bayesian" // Bayesian Bandit )
type BanditAnalysis ΒΆ
type BanditAnalysis struct {
ExperimentID string `json:"experiment_id"`
TotalPulls int64 `json:"total_pulls"`
TotalRegret float64 `json:"total_regret"`
Arms []BanditArmAnalysis `json:"arms"`
}
BanditAnalysis contains analysis results for a bandit experiment
type BanditArm ΒΆ
type BanditArm struct {
ID string `json:"id"`
Name string `json:"name"`
Pulls int64 `json:"pulls"` // Number of times this arm was pulled
Rewards int64 `json:"rewards"` // Number of successful outcomes
TotalReward float64 `json:"total_reward"` // Sum of all rewards
// Bayesian parameters (for Thompson Sampling and Bayesian bandits)
Alpha float64 `json:"alpha"` // Success count + 1 (prior)
Beta float64 `json:"beta"` // Failure count + 1 (prior)
// Configuration
Config map[string]any `json:"config"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BanditArm represents a single arm in a multi-armed bandit
type BanditArmAnalysis ΒΆ
type BanditArmAnalysis struct {
ArmID string `json:"arm_id"`
Pulls int64 `json:"pulls"`
Rewards int64 `json:"rewards"`
ConversionRate float64 `json:"conversion_rate"`
AverageReward float64 `json:"average_reward"`
ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
PosteriorMean float64 `json:"posterior_mean"`
Regret float64 `json:"regret"`
}
BanditArmAnalysis contains analysis for a single bandit arm
type BanditEngine ΒΆ
type BanditEngine struct {
// contains filtered or unexported fields
}
BanditEngine manages multi-armed bandit experiments
func NewBanditEngine ΒΆ
func NewBanditEngine() *BanditEngine
NewBanditEngine creates a new bandit engine
func NewBanditEngineWithStorage ΒΆ
func NewBanditEngineWithStorage(storage BanditStorage, metrics *BanditMetrics) *BanditEngine
NewBanditEngineWithStorage creates a new bandit engine with custom storage and metrics
func (*BanditEngine) CreateBanditExperiment ΒΆ
func (b *BanditEngine) CreateBanditExperiment(exp *BanditExperiment) error
CreateBanditExperiment creates a new bandit experiment
func (*BanditEngine) DeleteExperiment ΒΆ
func (b *BanditEngine) DeleteExperiment(id string) bool
func (*BanditEngine) Experiments ΒΆ
func (b *BanditEngine) Experiments() []*BanditExperiment
func (*BanditEngine) GetBanditResults ΒΆ
func (b *BanditEngine) GetBanditResults(experimentID string) (*BanditAnalysis, error)
GetBanditResults returns analysis of bandit experiment results
func (*BanditEngine) GetExperimentRecommendation ΒΆ
func (b *BanditEngine) GetExperimentRecommendation(experimentID string) (*BanditRecommendation, error)
GetExperimentRecommendation provides recommendations for experiment decisions
func (*BanditEngine) Metrics ΒΆ
func (b *BanditEngine) Metrics() BanditMetrics
func (*BanditEngine) RecordReward ΒΆ
func (b *BanditEngine) RecordReward(experimentID, armID, userID string, reward float64, success bool, context map[string]any) error
RecordReward records the reward for a bandit arm pull
func (*BanditEngine) SelectArm ΒΆ
func (b *BanditEngine) SelectArm(experimentID, userID string, context map[string]any) (*BanditArm, error)
SelectArm selects an arm based on the bandit algorithm
func (*BanditEngine) StopExperiment ΒΆ
func (b *BanditEngine) StopExperiment(experimentID string) error
StopExperiment stops a bandit experiment
type BanditExperiment ΒΆ
type BanditExperiment struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Algorithm BanditAlgorithm `json:"algorithm"`
Arms []BanditArm `json:"arms"`
// Algorithm parameters
Epsilon float64 `json:"epsilon"` // For epsilon-greedy
Confidence float64 `json:"confidence"` // For UCB
ExploreRatio float64 `json:"explore_ratio"` // General exploration parameter
// Experiment state
TotalPulls int64 `json:"total_pulls"`
Status string `json:"status"`
StartTime time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BanditExperiment represents a multi-armed bandit experiment
type BanditMetrics ΒΆ
BanditMetrics tracks operational metrics for bandit engine
type BanditRecommendation ΒΆ
type BanditRecommendation struct {
ExperimentID string `json:"experiment_id"`
Decision string `json:"decision"` // "continue", "stop", "need_more_data"
WinnerArmID string `json:"winner_arm_id,omitempty"`
Confidence string `json:"confidence"` // "low", "medium", "high"
Reasons []string `json:"reasons"`
}
BanditRecommendation provides recommendations for bandit experiment decisions
type BanditResult ΒΆ
type BanditResult struct {
ExperimentID string `json:"experiment_id"`
ArmID string `json:"arm_id"`
UserID string `json:"user_id"`
Reward float64 `json:"reward"`
Success bool `json:"success"`
Context map[string]any `json:"context"`
Timestamp time.Time `json:"timestamp"`
}
BanditResult represents the result of pulling a bandit arm
type BanditStorage ΒΆ
type BanditStorage interface {
SaveExperiment(exp *BanditExperiment) error
SaveArm(expID string, arm *BanditArm) error
SaveResult(result BanditResult) error
ListResults(expID string, limit int) ([]BanditResult, error)
}
BanditStorage defines interface for persisting bandit experiments, arms, and results In production, implement with Redis, SQL, etc.
type BiasDetectionConfig ΒΆ
type BiasDetectionConfig struct {
Enabled bool `json:"enabled"`
CheckSegments []string `json:"check_segments"` // Segments to check for bias
SignificanceLevel float64 `json:"significance_level"`
}
BiasDetectionConfig defines bias detection parameters
type ConfidenceInterval ΒΆ
ConfidenceInterval represents a confidence interval
type ConfigChange ΒΆ
type ConfigChange struct {
Key string `json:"key"`
OldValue interface{} `json:"old_value"`
NewValue interface{} `json:"new_value"`
Timestamp time.Time `json:"timestamp"`
Source string `json:"source"`
}
ConfigChange represents a configuration change event
type ConfigManager ΒΆ
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager manages all configuration for A/B testing
func NewConfigManager ΒΆ
func NewConfigManager(provider ConfigProvider) *ConfigManager
NewConfigManager creates a new configuration manager
func NewConfigManagerWithStorage ΒΆ
func NewConfigManagerWithStorage(storage ConfigStorage, metrics *ConfigMetrics) *ConfigManager
NewConfigManagerWithStorage creates a new config manager with custom storage and metrics
func (*ConfigManager) CreateExperimentConfig ΒΆ
func (c *ConfigManager) CreateExperimentConfig(ctx context.Context, config *ExperimentConfig) error
CreateExperimentConfig creates experiment configuration
func (*ConfigManager) CreateFeatureFlag ΒΆ
func (c *ConfigManager) CreateFeatureFlag(ctx context.Context, flag *FeatureFlag) error
CreateFeatureFlag creates a new feature flag
func (*ConfigManager) DeleteExperimentConfig ΒΆ
func (c *ConfigManager) DeleteExperimentConfig(ctx context.Context, experimentID string) error
DeleteExperimentConfig deletes an experiment config by ID
func (*ConfigManager) DeleteFeatureFlag ΒΆ
func (c *ConfigManager) DeleteFeatureFlag(ctx context.Context, flagID string) error
DeleteFeatureFlag deletes a feature flag by ID
func (*ConfigManager) EvaluateFeatureFlag ΒΆ
func (c *ConfigManager) EvaluateFeatureFlag(ctx context.Context, flagID, userID string, userAttributes map[string]interface{}) (*FeatureFlagResult, error)
EvaluateFeatureFlag evaluates a feature flag for a user
func (*ConfigManager) GetExperimentConfig ΒΆ
func (c *ConfigManager) GetExperimentConfig(ctx context.Context, experimentID string) (*ExperimentConfig, error)
GetExperimentConfig retrieves experiment configuration
func (*ConfigManager) GetFeatureFlag ΒΆ
func (c *ConfigManager) GetFeatureFlag(ctx context.Context, flagID string) (*FeatureFlag, error)
GetFeatureFlag retrieves a feature flag
func (*ConfigManager) GetMetrics ΒΆ
func (c *ConfigManager) GetMetrics() ConfigMetrics
GetMetrics returns config manager metrics
func (*ConfigManager) ListExperimentConfigs ΒΆ
func (c *ConfigManager) ListExperimentConfigs(ctx context.Context) ([]*ExperimentConfig, error)
ListExperimentConfigs returns all experiment configs
func (*ConfigManager) ListFeatureFlags ΒΆ
func (c *ConfigManager) ListFeatureFlags(ctx context.Context) ([]*FeatureFlag, error)
ListFeatureFlags returns all feature flags
func (*ConfigManager) ValidateConfig ΒΆ
func (c *ConfigManager) ValidateConfig(config interface{}) error
ValidateConfig validates configuration before saving
func (*ConfigManager) WatchConfig ΒΆ
func (c *ConfigManager) WatchConfig(ctx context.Context, key string) (<-chan ConfigChange, error)
WatchConfig watches for configuration changes
type ConfigMetrics ΒΆ
type ConfigMetrics struct {
FeatureFlagEvaluations int64
FeatureFlagErrors int64
ConfigChanges int64
}
ConfigMetrics tracks operational metrics for config manager
type ConfigProvider ΒΆ
type ConfigProvider interface {
GetConfig(ctx context.Context, key string) (interface{}, error)
SetConfig(ctx context.Context, key string, value interface{}) error
DeleteConfig(ctx context.Context, key string) error
ListConfigs(ctx context.Context, prefix string) (map[string]interface{}, error)
Watch(ctx context.Context, key string) (<-chan ConfigChange, error)
}
ConfigProvider defines interface for configuration providers
type ConfigStorage ΒΆ
type ConfigStorage interface {
SaveFeatureFlag(flag *FeatureFlag) error
SaveExperimentConfig(config *ExperimentConfig) error
ListFeatureFlags() ([]*FeatureFlag, error)
ListExperimentConfigs() ([]*ExperimentConfig, error)
}
ConfigStorage defines interface for persisting feature flags and experiment configs In production, implement with Redis, SQL, etc.
type ConversionEvent ΒΆ
type ConversionEvent struct {
UserID string `json:"user_id"`
ExperimentID string `json:"experiment_id"`
VariantID string `json:"variant_id"`
EventType string `json:"event_type"`
Value float64 `json:"value,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
ConversionEvent represents a conversion event for analytics
type Experiment ΒΆ
type Experiment struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Status ExperimentStatus `json:"status"`
Variants []Variant `json:"variants"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Targeting criteria
TargetPercentage float64 `json:"target_percentage"` // 0.0 to 1.0
Filters map[string]string `json:"filters"` // User attributes for targeting
// Analytics
MinSampleSize int `json:"min_sample_size"`
ConfidenceLevel float64 `json:"confidence_level"` // e.g., 0.95 for 95%
MinDetectableEffect float64 `json:"min_detectable_effect"`
}
Experiment represents an A/B test experiment
type ExperimentAnalytics ΒΆ
type ExperimentAnalytics struct {
ExperimentID string `json:"experiment_id"`
TimeRange TimeRange `json:"time_range"`
OverallMetrics []MetricSummary `json:"overall_metrics"`
VariantMetrics map[string][]MetricSummary `json:"variant_metrics"` // variant_id -> metrics
SegmentAnalysis map[string]SegmentAnalysis `json:"segment_analysis"` // segment_id -> analysis
TimeSeriesData []TimeSeriesPoint `json:"time_series_data"`
StatisticalTests []StatisticalTest `json:"statistical_tests"`
GeneratedAt time.Time `json:"generated_at"`
}
ExperimentAnalytics provides comprehensive analytics for experiments
type ExperimentConfig ΒΆ
type ExperimentConfig struct {
ExperimentID string `json:"experiment_id"`
TrafficSplit map[string]float64 `json:"traffic_split"` // variant_id -> percentage
TargetingRules []TargetingRule `json:"targeting_rules"`
SampleSize *SampleSizeConfig `json:"sample_size,omitempty"`
StoppingRules []StoppingRule `json:"stopping_rules"`
MetricConfig map[string]MetricConfig `json:"metric_config"`
QualityControl *QualityControlConfig `json:"quality_control,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ExperimentConfig represents configuration for an experiment
type ExperimentEngine ΒΆ
type ExperimentEngine struct {
// contains filtered or unexported fields
}
ExperimentEngine manages A/B test experiments
func NewExperimentEngine ΒΆ
func NewExperimentEngine(store ExperimentStore) *ExperimentEngine
NewExperimentEngine creates a new experiment engine
func (*ExperimentEngine) AssignVariant ΒΆ
func (e *ExperimentEngine) AssignVariant(ctx context.Context, userID, experimentID string, userAttributes map[string]string) (*Assignment, error)
AssignVariant assigns a user to a variant in an experiment
func (*ExperimentEngine) CreateExperiment ΒΆ
func (e *ExperimentEngine) CreateExperiment(exp *Experiment) error
CreateExperiment creates a new experiment
func (*ExperimentEngine) GetExperimentResults ΒΆ
func (e *ExperimentEngine) GetExperimentResults(experimentID string) (*ExperimentResults, error)
GetExperimentResults calculates statistical results for an experiment
func (*ExperimentEngine) RecordConversion ΒΆ
func (e *ExperimentEngine) RecordConversion(ctx context.Context, event *ConversionEvent) error
RecordConversion records a conversion event for analytics
type ExperimentResults ΒΆ
type ExperimentResults struct {
ExperimentID string `json:"experiment_id"`
Variants []VariantResults `json:"variants"`
}
ExperimentResults contains the statistical results of an experiment
type ExperimentStatus ΒΆ
type ExperimentStatus string
ExperimentStatus represents the status of an experiment
const ( StatusDraft ExperimentStatus = "draft" StatusActive ExperimentStatus = "active" StatusPaused ExperimentStatus = "paused" StatusComplete ExperimentStatus = "complete" )
type ExperimentStore ΒΆ
type ExperimentStore interface {
SaveExperiment(exp *Experiment) error
GetExperiment(id string) (*Experiment, error)
ListExperiments() ([]*Experiment, error)
SaveAssignment(assignment *Assignment) error
GetAssignment(userID, experimentID string) (*Assignment, error)
ListAssignments(experimentID string) ([]*Assignment, error)
SaveConversion(event *ConversionEvent) error
ListConversions(experimentID string) ([]*ConversionEvent, error)
}
ExperimentStore defines the interface for persisting experiments, variants, assignments, and conversions In production, implement with Redis, SQL, etc.
type FeatureFlag ΒΆ
type FeatureFlag struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Rules []FeatureFlagRule `json:"rules"`
Rollout *RolloutConfig `json:"rollout,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy string `json:"created_by"`
}
FeatureFlag represents a feature flag configuration
type FeatureFlagResult ΒΆ
type FeatureFlagResult struct {
FlagID string `json:"flag_id"`
UserID string `json:"user_id"`
Enabled bool `json:"enabled"`
Variant string `json:"variant"`
Config map[string]interface{} `json:"config"`
RuleMatched string `json:"rule_matched"`
Reason string `json:"reason"`
EvaluatedAt time.Time `json:"evaluated_at"`
}
FeatureFlagResult represents the result of feature flag evaluation
type FeatureFlagRule ΒΆ
type FeatureFlagRule struct {
ID string `json:"id"`
Name string `json:"name"`
Conditions []RuleCondition `json:"conditions"`
Action RuleAction `json:"action"`
Weight float64 `json:"weight"` // 0.0 to 1.0
Priority int `json:"priority"` // Higher number = higher priority
Metadata map[string]interface{} `json:"metadata"`
}
FeatureFlagRule defines targeting rules for feature flags
type InMemoryAnalyticsStorage ΒΆ
type InMemoryAnalyticsStorage struct {
// contains filtered or unexported fields
}
InMemoryAnalyticsStorage is an in-memory implementation of AnalyticsStorage (for testing and development)
func NewInMemoryAnalyticsStorage ΒΆ
func NewInMemoryAnalyticsStorage() *InMemoryAnalyticsStorage
func (*InMemoryAnalyticsStorage) GetMetricValues ΒΆ
func (s *InMemoryAnalyticsStorage) GetMetricValues(ctx context.Context, experimentID string, timeRange TimeRange) ([]MetricValue, error)
func (*InMemoryAnalyticsStorage) GetSegments ΒΆ
func (s *InMemoryAnalyticsStorage) GetSegments(ctx context.Context) ([]*Segment, error)
func (*InMemoryAnalyticsStorage) SaveMetricValue ΒΆ
func (s *InMemoryAnalyticsStorage) SaveMetricValue(ctx context.Context, value MetricValue) error
func (*InMemoryAnalyticsStorage) SaveSegment ΒΆ
func (s *InMemoryAnalyticsStorage) SaveSegment(ctx context.Context, segment *Segment) error
type InMemoryBanditStorage ΒΆ
type InMemoryBanditStorage struct {
// contains filtered or unexported fields
}
InMemoryBanditStorage is a simple in-memory implementation
func NewInMemoryBanditStorage ΒΆ
func NewInMemoryBanditStorage() *InMemoryBanditStorage
func (*InMemoryBanditStorage) ListResults ΒΆ
func (s *InMemoryBanditStorage) ListResults(expID string, limit int) ([]BanditResult, error)
func (*InMemoryBanditStorage) SaveArm ΒΆ
func (s *InMemoryBanditStorage) SaveArm(expID string, arm *BanditArm) error
func (*InMemoryBanditStorage) SaveExperiment ΒΆ
func (s *InMemoryBanditStorage) SaveExperiment(exp *BanditExperiment) error
func (*InMemoryBanditStorage) SaveResult ΒΆ
func (s *InMemoryBanditStorage) SaveResult(result BanditResult) error
type InMemoryConfigProvider ΒΆ
type InMemoryConfigProvider struct {
// contains filtered or unexported fields
}
InMemoryConfigProvider provides an in-memory configuration store
func NewInMemoryConfigProvider ΒΆ
func NewInMemoryConfigProvider() *InMemoryConfigProvider
NewInMemoryConfigProvider creates a new in-memory config provider
func (*InMemoryConfigProvider) DeleteConfig ΒΆ
func (p *InMemoryConfigProvider) DeleteConfig(ctx context.Context, key string) error
DeleteConfig deletes a configuration value
func (*InMemoryConfigProvider) GetConfig ΒΆ
func (p *InMemoryConfigProvider) GetConfig(ctx context.Context, key string) (interface{}, error)
GetConfig retrieves a configuration value
func (*InMemoryConfigProvider) ListConfigs ΒΆ
func (p *InMemoryConfigProvider) ListConfigs(ctx context.Context, prefix string) (map[string]interface{}, error)
ListConfigs lists all configurations with a given prefix
func (*InMemoryConfigProvider) SetConfig ΒΆ
func (p *InMemoryConfigProvider) SetConfig(ctx context.Context, key string, value interface{}) error
SetConfig sets a configuration value
func (*InMemoryConfigProvider) Watch ΒΆ
func (p *InMemoryConfigProvider) Watch(ctx context.Context, key string) (<-chan ConfigChange, error)
Watch watches for changes to a configuration key
type InMemoryConfigStorage ΒΆ
type InMemoryConfigStorage struct {
// contains filtered or unexported fields
}
InMemoryConfigStorage is a simple in-memory implementation
func NewInMemoryConfigStorage ΒΆ
func NewInMemoryConfigStorage() *InMemoryConfigStorage
func (*InMemoryConfigStorage) ListExperimentConfigs ΒΆ
func (s *InMemoryConfigStorage) ListExperimentConfigs() ([]*ExperimentConfig, error)
func (*InMemoryConfigStorage) ListFeatureFlags ΒΆ
func (s *InMemoryConfigStorage) ListFeatureFlags() ([]*FeatureFlag, error)
func (*InMemoryConfigStorage) SaveExperimentConfig ΒΆ
func (s *InMemoryConfigStorage) SaveExperimentConfig(config *ExperimentConfig) error
func (*InMemoryConfigStorage) SaveFeatureFlag ΒΆ
func (s *InMemoryConfigStorage) SaveFeatureFlag(flag *FeatureFlag) error
type InMemoryExperimentStore ΒΆ
type InMemoryExperimentStore struct {
// contains filtered or unexported fields
}
InMemoryExperimentStore is a simple in-memory implementation (for testing and development)
func NewInMemoryExperimentStore ΒΆ
func NewInMemoryExperimentStore() *InMemoryExperimentStore
func (*InMemoryExperimentStore) GetAssignment ΒΆ
func (s *InMemoryExperimentStore) GetAssignment(userID, experimentID string) (*Assignment, error)
func (*InMemoryExperimentStore) GetExperiment ΒΆ
func (s *InMemoryExperimentStore) GetExperiment(id string) (*Experiment, error)
func (*InMemoryExperimentStore) ListAssignments ΒΆ
func (s *InMemoryExperimentStore) ListAssignments(experimentID string) ([]*Assignment, error)
func (*InMemoryExperimentStore) ListConversions ΒΆ
func (s *InMemoryExperimentStore) ListConversions(experimentID string) ([]*ConversionEvent, error)
func (*InMemoryExperimentStore) ListExperiments ΒΆ
func (s *InMemoryExperimentStore) ListExperiments() ([]*Experiment, error)
func (*InMemoryExperimentStore) SaveAssignment ΒΆ
func (s *InMemoryExperimentStore) SaveAssignment(assignment *Assignment) error
func (*InMemoryExperimentStore) SaveConversion ΒΆ
func (s *InMemoryExperimentStore) SaveConversion(event *ConversionEvent) error
func (*InMemoryExperimentStore) SaveExperiment ΒΆ
func (s *InMemoryExperimentStore) SaveExperiment(exp *Experiment) error
type InMemoryRecommendationStorage ΒΆ
type InMemoryRecommendationStorage struct {
// contains filtered or unexported fields
}
InMemoryRecommendationStorage is a simple in-memory implementation Not for production use
func NewInMemoryRecommendationStorage ΒΆ
func NewInMemoryRecommendationStorage() *InMemoryRecommendationStorage
func (*InMemoryRecommendationStorage) ListRecommendations ΒΆ
func (s *InMemoryRecommendationStorage) ListRecommendations(userID string, limit int) ([]Recommendation, error)
func (*InMemoryRecommendationStorage) SaveInteraction ΒΆ
func (s *InMemoryRecommendationStorage) SaveInteraction(interaction Interaction) error
func (*InMemoryRecommendationStorage) SaveItem ΒΆ
func (s *InMemoryRecommendationStorage) SaveItem(item *Item) error
func (*InMemoryRecommendationStorage) SaveRecommendation ΒΆ
func (s *InMemoryRecommendationStorage) SaveRecommendation(rec Recommendation) error
func (*InMemoryRecommendationStorage) SaveUser ΒΆ
func (s *InMemoryRecommendationStorage) SaveUser(user *User) error
type Interaction ΒΆ
type Interaction struct {
UserID string `json:"user_id"`
ItemID string `json:"item_id"`
Type string `json:"type"` // view, click, purchase, like, etc.
Rating float64 `json:"rating"` // explicit rating if available
ImplicitScore float64 `json:"implicit_score"` // implicit rating derived from behavior
Timestamp time.Time `json:"timestamp"`
Context map[string]interface{} `json:"context"` // contextual information
}
Interaction represents a user-item interaction
type Item ΒΆ
type Item struct {
ID string `json:"id"`
Title string `json:"title"`
Category string `json:"category"`
Tags []string `json:"tags"`
Features map[string]float64 `json:"features"` // Feature vector for content-based filtering
Popularity float64 `json:"popularity"` // Popularity score
TrendScore float64 `json:"trend_score"` // Trending score
CreatedAt time.Time `json:"created_at"`
Metadata map[string]interface{} `json:"metadata"`
}
Item represents an item that can be recommended
type Metric ΒΆ
type Metric struct {
ID string `json:"id"`
Name string `json:"name"`
Type MetricType `json:"type"`
Description string `json:"description"`
Unit string `json:"unit"` // e.g., "percent", "dollars", "count"
IsPrimary bool `json:"is_primary"` // Primary metric for the experiment
Properties map[string]interface{} `json:"properties"`
CreatedAt time.Time `json:"created_at"`
}
Metric represents a metric definition
type MetricConfig ΒΆ
type MetricConfig struct {
MetricID string `json:"metric_id"`
IsPrimary bool `json:"is_primary"`
Weight float64 `json:"weight"` // For composite metrics
Threshold float64 `json:"threshold"` // Alert threshold
Direction string `json:"direction"` // "increase", "decrease", "either"
}
MetricConfig defines configuration for metrics
type MetricSummary ΒΆ
type MetricSummary struct {
MetricID string `json:"metric_id"`
MetricName string `json:"metric_name"`
Count int64 `json:"count"`
Sum float64 `json:"sum"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StandardDev float64 `json:"standard_deviation"`
Percentiles map[int]float64 `json:"percentiles"` // 25th, 75th, 90th, 95th, 99th
ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
}
MetricSummary provides summary statistics for a metric
type MetricType ΒΆ
type MetricType string
MetricType represents different types of metrics
const ( MetricConversion MetricType = "conversion" MetricRevenue MetricType = "revenue" MetricEngagement MetricType = "engagement" MetricRetention MetricType = "retention" MetricClickThrough MetricType = "click_through" MetricCustom MetricType = "custom" )
type MetricValue ΒΆ
type MetricValue struct {
MetricID string `json:"metric_id"`
ExperimentID string `json:"experiment_id"`
VariantID string `json:"variant_id"`
UserID string `json:"user_id"`
Value float64 `json:"value"`
Properties map[string]interface{} `json:"properties"`
Timestamp time.Time `json:"timestamp"`
}
MetricValue represents a measured value for a metric
type NoveltyConfig ΒΆ
type NoveltyConfig struct {
Enabled bool `json:"enabled"`
MonitorPeriod time.Duration `json:"monitor_period"` // How long to monitor for novelty
BaselinePeriod time.Duration `json:"baseline_period"` // Period to establish baseline
}
NoveltyConfig defines novelty effect detection
type OutlierConfig ΒΆ
type OutlierConfig struct {
Enabled bool `json:"enabled"`
Method string `json:"method"` // "iqr", "zscore", "isolation_forest"
Threshold float64 `json:"threshold"` // Method-specific threshold
Action string `json:"action"` // "exclude", "flag", "transform"
}
OutlierConfig defines outlier detection parameters
type PowerAnalysisConfig ΒΆ
type PowerAnalysisConfig struct {
Alpha float64 `json:"alpha"` // Type I error rate (e.g., 0.05)
Beta float64 `json:"beta"` // Type II error rate (e.g., 0.2)
MinDetectableEffect float64 `json:"min_detectable_effect"` // Minimum effect size to detect
BaselineConversionRate float64 `json:"baseline_conversion_rate"`
}
PowerAnalysisConfig defines power analysis parameters
type QualityControlConfig ΒΆ
type QualityControlConfig struct {
SampleRatioMismatch *SRMConfig `json:"sample_ratio_mismatch,omitempty"`
OutlierDetection *OutlierConfig `json:"outlier_detection,omitempty"`
NoveltyEffect *NoveltyConfig `json:"novelty_effect,omitempty"`
BiasDetection *BiasDetectionConfig `json:"bias_detection,omitempty"`
}
QualityControlConfig defines quality control parameters
type Recommendation ΒΆ
type Recommendation struct {
UserID string `json:"user_id"`
ItemID string `json:"item_id"`
Score float64 `json:"score"`
Reason string `json:"reason"`
Algorithm RecommendationType `json:"algorithm"`
Context map[string]interface{} `json:"context"`
GeneratedAt time.Time `json:"generated_at"`
}
Recommendation represents a recommended item for a user
type RecommendationEngine ΒΆ
type RecommendationEngine struct {
// contains filtered or unexported fields
}
RecommendationEngine provides personalized recommendations
func NewRecommendationEngine ΒΆ
func NewRecommendationEngine() *RecommendationEngine
NewRecommendationEngine creates a new recommendation engine
func NewRecommendationEngineWithStorage ΒΆ
func NewRecommendationEngineWithStorage(storage RecommendationStorage, metrics *RecommendationMetrics) *RecommendationEngine
NewRecommendationEngineWithStorage creates a new recommendation engine with custom storage and metrics
func (*RecommendationEngine) AddItem ΒΆ
func (r *RecommendationEngine) AddItem(item *Item)
AddItem adds an item to the recommendation system
func (*RecommendationEngine) AddUser ΒΆ
func (r *RecommendationEngine) AddUser(user *User)
AddUser adds a user to the recommendation system
func (*RecommendationEngine) GetRecommendations ΒΆ
func (r *RecommendationEngine) GetRecommendations(ctx context.Context, userID string, count int, algorithm RecommendationType) ([]Recommendation, error)
GetRecommendations generates recommendations for a user
func (*RecommendationEngine) RecordInteraction ΒΆ
func (r *RecommendationEngine) RecordInteraction(interaction Interaction)
RecordInteraction records a user-item interaction
func (*RecommendationEngine) SetAlgorithmWeights ΒΆ
func (r *RecommendationEngine) SetAlgorithmWeights(content, collaborative, popularity, trending float64) error
SetAlgorithmWeights sets the weights for hybrid recommendation algorithms
type RecommendationMetrics ΒΆ
type RecommendationMetrics struct {
RecommendationsServed int64
RecommendationErrors int64
RecommendationLatency []float64
}
RecommendationMetrics tracks operational metrics for recommendations
type RecommendationStorage ΒΆ
type RecommendationStorage interface {
SaveUser(user *User) error
SaveItem(item *Item) error
SaveInteraction(interaction Interaction) error
SaveRecommendation(rec Recommendation) error
ListRecommendations(userID string, limit int) ([]Recommendation, error)
}
RecommendationStorage defines interface for persisting recommendations, users, items, and interactions In production, implement this with Redis, SQL, or other backends
type RecommendationType ΒΆ
type RecommendationType string
RecommendationType represents the type of recommendation algorithm
const ( RecommendationContentBased RecommendationType = "content_based" RecommendationCollaborative RecommendationType = "collaborative" RecommendationHybrid RecommendationType = "hybrid" RecommendationPopularity RecommendationType = "popularity" RecommendationTrending RecommendationType = "trending" )
type RolloutConfig ΒΆ
type RolloutConfig struct {
Strategy string `json:"strategy"` // "percentage", "user_list", "attributes"
Percentage float64 `json:"percentage"` // 0.0 to 100.0
UserList []string `json:"user_list,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
}
RolloutConfig defines gradual rollout configuration
type RuleAction ΒΆ
type RuleAction struct {
Type string `json:"type"` // "enable", "disable", "variant", "redirect"
Value interface{} `json:"value"` // Variant ID, URL, etc.
Config map[string]interface{} `json:"config"` // Additional configuration
}
RuleAction defines the action to take when a rule matches
type RuleCondition ΒΆ
type RuleCondition struct {
Attribute string `json:"attribute"`
Operator string `json:"operator"` // "equals", "not_equals", "contains", "in", "not_in", "greater_than", "less_than"
Value interface{} `json:"value"`
CaseSensitive bool `json:"case_sensitive"`
}
RuleCondition defines a condition for feature flag rules
type SRMConfig ΒΆ
type SRMConfig struct {
Enabled bool `json:"enabled"`
TolerancePercent float64 `json:"tolerance_percent"` // Allowed deviation from expected ratio
AlertThreshold float64 `json:"alert_threshold"` // P-value threshold for alerts
}
SRMConfig defines Sample Ratio Mismatch detection
type SampleSizeConfig ΒΆ
type SampleSizeConfig struct {
MinSamplePerVariant int `json:"min_sample_per_variant"`
MaxSamplePerVariant int `json:"max_sample_per_variant"`
PowerAnalysis *PowerAnalysisConfig `json:"power_analysis,omitempty"`
}
SampleSizeConfig defines sample size requirements
type Segment ΒΆ
type Segment struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Criteria []SegmentCriteria `json:"criteria"`
CreatedAt time.Time `json:"created_at"`
}
Segment represents a user segment for analysis
type SegmentAnalysis ΒΆ
type SegmentAnalysis struct {
SegmentID string `json:"segment_id"`
SegmentName string `json:"segment_name"`
UserCount int64 `json:"user_count"`
VariantMetrics map[string][]MetricSummary `json:"variant_metrics"`
Insights []string `json:"insights"`
}
SegmentAnalysis provides analysis for a specific segment
type SegmentCriteria ΒΆ
type SegmentCriteria struct {
Attribute string `json:"attribute"`
Operator string `json:"operator"` // "equals", "contains", "greater_than", etc.
Value interface{} `json:"value"`
}
SegmentCriteria defines criteria for user segmentation
type SimilarUser ΒΆ
SimilarUser represents a user similar to the target user
type StatisticalTest ΒΆ
type StatisticalTest struct {
TestType string `json:"test_type"` // "t_test", "chi_square", "mann_whitney"
MetricID string `json:"metric_id"`
ControlVariant string `json:"control_variant"`
TreatmentVariant string `json:"treatment_variant"`
PValue float64 `json:"p_value"`
TestStatistic float64 `json:"test_statistic"`
DegreesOfFreedom int `json:"degrees_of_freedom,omitempty"`
EffectSize float64 `json:"effect_size"`
IsSignificant bool `json:"is_significant"`
ConfidenceLevel float64 `json:"confidence_level"`
}
StatisticalTest represents results of a statistical test
type StoppingRule ΒΆ
type StoppingRule struct {
ID string `json:"id"`
Type string `json:"type"` // "significance", "sample_size", "time", "custom"
Condition map[string]interface{} `json:"condition"` // Rule-specific parameters
Action string `json:"action"` // "stop", "extend", "notify"
Priority int `json:"priority"`
}
StoppingRule defines when to stop an experiment
type TargetingRule ΒΆ
type TargetingRule struct {
ID string `json:"id"`
Name string `json:"name"`
Conditions []RuleCondition `json:"conditions"`
Include bool `json:"include"` // true = include, false = exclude
Priority int `json:"priority"`
}
TargetingRule defines who should be included in an experiment
type TimeSeriesPoint ΒΆ
type TimeSeriesPoint struct {
Timestamp time.Time `json:"timestamp"`
VariantID string `json:"variant_id"`
MetricID string `json:"metric_id"`
Value float64 `json:"value"`
Count int64 `json:"count"`
Metadata map[string]interface{} `json:"metadata"`
}
TimeSeriesPoint represents a point in time series data
type User ΒΆ
type User struct {
ID string `json:"id"`
Preferences map[string]float64 `json:"preferences"` // User preference vector
Demographics map[string]string `json:"demographics"`
Segments []string `json:"segments"`
CreatedAt time.Time `json:"created_at"`
}
User represents a user in the recommendation system
type Variant ΒΆ
type Variant struct {
ID string `json:"id"`
Name string `json:"name"`
Weight float64 `json:"weight"` // 0.0 to 1.0
Config map[string]interface{} `json:"config"` // Variant-specific configuration
Conversions int64 `json:"conversions"` // Number of conversions
Impressions int64 `json:"impressions"` // Number of impressions
}
Variant represents a single variant in an A/B test
type VariantResults ΒΆ
type VariantResults struct {
VariantID string `json:"variant_id"`
Impressions int64 `json:"impressions"`
Conversions int64 `json:"conversions"`
ConversionRate float64 `json:"conversion_rate"`
ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
PValue float64 `json:"p_value,omitempty"`
IsSignificant bool `json:"is_significant"`
}
VariantResults contains results for a single variant