Documentation
¶
Overview ¶
Package pattern provides pattern detection and recognition functionality.
Package pattern provides pattern detection and recognition functionality.
Package pattern provides pattern detection and recognition functionality.
Index ¶
- Constants
- func DynamicQuality(frequency int, confidence float64, projectCount int, maxFrequency int, ...) float64
- func QualityScore(frequency int, confidence float64, projectCount int, maxFrequency int) float64
- func RunDecay(ctx context.Context, patternStore *gorm.PatternStore) (int, error)
- func TemporalDecay(daysSinceLastSeen float64) float64
- type DetectionResult
- type Detector
- func (d *Detector) AnalyzeObservation(ctx context.Context, obs *models.Observation) (*DetectionResult, error)
- func (d *Detector) AnalyzeRecentObservations(ctx context.Context) error
- func (d *Detector) BatchRecalculateConfidence(ctx context.Context) (int, error)
- func (d *Detector) CandidateCount() int
- func (d *Detector) GetPatternInsight(ctx context.Context, patternID int64) (string, error)
- func (d *Detector) SetSyncFunc(fn PatternSyncFunc)
- func (d *Detector) Start()
- func (d *Detector) Stop()
- type DetectorConfig
- type PatternSyncFunc
Constants ¶
const ( // DeprecateThreshold marks a pattern for soft-deprecation when Q_dynamic drops below this value. DeprecateThreshold = 0.10 // DeleteThreshold marks a pattern as eligible for hard deletion when Q_dynamic reaches exactly 0. DeleteThreshold = 0.0 )
Lifecycle thresholds for pattern quality management.
Variables ¶
This section is empty.
Functions ¶
func DynamicQuality ¶ added in v1.3.0
func DynamicQuality(frequency int, confidence float64, projectCount int, maxFrequency int, daysSinceLastSeen float64) float64
DynamicQuality computes the final quality score with temporal decay applied. Q_dynamic = QualityScore(...) * TemporalDecay(daysSinceLastSeen)
func QualityScore ¶ added in v1.1.0
QualityScore computes a pattern's quality baseline score. Formula: Q_base = 0.3*log_freq + 0.5*sigmoid_conf + 0.2*diversity
Components:
- log_freq: log2(frequency+1) / log2(maxFrequency+1), normalized 0-1.
- sigmoid_conf: 1 / (1 + exp(-10*(confidence-0.5))), centered at 0.5.
- diversity: min(projectCount, 5) / 5.0, normalized 0-1.
func RunDecay ¶ added in v1.1.0
RunDecay processes all active patterns, computing dynamic quality and deprecating low-quality ones. Returns the count of deprecated patterns.
func TemporalDecay ¶ added in v1.3.0
TemporalDecay computes the decay multiplier based on days since last seen. Three phases:
- Grace period (0-7 days): returns 1.0, no decay.
- Gaussian decay (7-60 days): smooth decay from 1.0 to ~exp(-3) ≈ 0.05.
- Linear terminal (60-90 days): linear ramp from Gaussian end value to 0.
Types ¶
type DetectionResult ¶
DetectionResult contains the result of pattern detection.
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector detects and tracks recurring patterns across observations.
func NewDetector ¶
func NewDetector(patternStore *gorm.PatternStore, observationStore *gorm.ObservationStore, config DetectorConfig) *Detector
NewDetector creates a new pattern detector.
func (*Detector) AnalyzeObservation ¶
func (d *Detector) AnalyzeObservation(ctx context.Context, obs *models.Observation) (*DetectionResult, error)
AnalyzeObservation processes a new observation for pattern detection. This is called synchronously when a new observation is stored.
func (*Detector) AnalyzeRecentObservations ¶
AnalyzeRecentObservations analyzes recent observations for pattern detection. This is used for background batch analysis.
func (*Detector) BatchRecalculateConfidence ¶ added in v1.8.0
BatchRecalculateConfidence recomputes confidence for all active patterns using the model formula (frequency + cross-project bonus) and persists updated values. Returns the number of patterns recalculated.
func (*Detector) CandidateCount ¶
CandidateCount returns the current number of pattern candidates.
func (*Detector) GetPatternInsight ¶
GetPatternInsight returns a formatted insight string for a pattern. GetPatternInsight returns a formatted insight string for a pattern.
func (*Detector) SetSyncFunc ¶
func (d *Detector) SetSyncFunc(fn PatternSyncFunc)
SetSyncFunc sets the callback for syncing patterns to vector store.
type DetectorConfig ¶
type DetectorConfig struct {
// MinMatchScore is the minimum similarity score to consider a match (0.0-1.0).
MinMatchScore float64
// MinFrequencyForPattern is the minimum occurrences before creating a pattern.
MinFrequencyForPattern int
// AnalysisInterval is how often to run background pattern analysis.
AnalysisInterval time.Duration
// MaxPatternsToTrack is the maximum number of active patterns.
MaxPatternsToTrack int
// MaxCandidates is the maximum number of candidates to track (LRU eviction).
MaxCandidates int
}
DetectorConfig contains configuration for the pattern detector.
func DefaultConfig ¶
func DefaultConfig() DetectorConfig
DefaultConfig returns the default detector configuration.
type PatternSyncFunc ¶
PatternSyncFunc is a callback for syncing patterns to vector store.