pattern

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 10 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func HybridDecay added in v1.1.0

func HybridDecay(lastSeenAt time.Time) float64

HybridDecay computes the temporal decay multiplier for a pattern. Three phases:

  • Grace period (0-7 days): no decay, returns 1.0.
  • Gaussian decay (7-60 days): smooth exponential decay reaching ~0.5 at 37 days.
  • Linear terminal (60-90 days): linear ramp to zero.

func QualityScore added in v1.1.0

func QualityScore(frequency int, confidence float64, projectCount int, maxFrequency int) float64

QualityScore computes a pattern's quality based on frequency, confidence, and diversity. Returns a value between 0.0 and 1.0.

Components:

  • Frequency (30% weight): Log-scaled frequency normalized against the maximum.
  • Confidence (50% weight): Sigmoid-transformed confidence centered at 0.5.
  • Diversity (20% weight): Project count normalized to a maximum of 10.

func RunDecay added in v1.1.0

func RunDecay(ctx context.Context, patternStore *gorm.PatternStore) (int, error)

RunDecay processes all active patterns, computing dynamic quality and deprecating low-quality ones. Returns the count of deprecated patterns.

Types

type DetectionResult

type DetectionResult struct {
	MatchedPattern *models.Pattern
	MatchScore     float64
	IsNewPattern   bool
}

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

func (d *Detector) AnalyzeRecentObservations(ctx context.Context) error

AnalyzeRecentObservations analyzes recent observations for pattern detection. This is used for background batch analysis.

func (*Detector) CandidateCount

func (d *Detector) CandidateCount() int

CandidateCount returns the current number of pattern candidates.

func (*Detector) GetPatternInsight

func (d *Detector) GetPatternInsight(ctx context.Context, patternID int64) (string, error)

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.

func (*Detector) Start

func (d *Detector) Start()

Start begins background pattern analysis.

func (*Detector) Stop

func (d *Detector) Stop()

Stop stops background pattern analysis.

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

type PatternSyncFunc func(pattern *models.Pattern)

PatternSyncFunc is a callback for syncing patterns to vector store.

Jump to

Keyboard shortcuts

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