Documentation
¶
Overview ¶
Package maintenance provides scheduled maintenance tasks for engram.
Package maintenance provides scheduled maintenance tasks for engram.
Package maintenance provides scheduled maintenance tasks for engram.
Index ¶
- type NearDuplicateFinder
- type OrphanPatternResult
- type Service
- func (s *Service) CleanupOrphanPatterns(ctx context.Context, dryRun bool) (OrphanPatternResult, error)
- func (s *Service) IsEmbeddingModelChanged() bool
- func (s *Service) RunNow(ctx context.Context)
- func (s *Service) Start(ctx context.Context)
- func (s *Service) Stats() map[string]any
- func (s *Service) Stop()
- func (s *Service) Wait()
- type SmartGC
- type SmartGCStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NearDuplicateFinder ¶ added in v1.5.0
type NearDuplicateFinder struct {
// contains filtered or unexported fields
}
NearDuplicateFinder finds and merges near-duplicate observations during maintenance. Observations with cosine similarity >= threshold (same project and type) are candidates for merging: the lower-importance one is marked as superseded.
func NewNearDuplicateFinder ¶ added in v1.5.0
func NewNearDuplicateFinder( observationStore *gorm.ObservationStore, vectorClient vector.Client, threshold float64, logger zerolog.Logger, ) *NearDuplicateFinder
NewNearDuplicateFinder creates a NearDuplicateFinder with the given dependencies. threshold is the cosine similarity above which two observations are considered near-duplicates.
func (*NearDuplicateFinder) FindAndMerge ¶ added in v1.5.0
func (f *NearDuplicateFinder) FindAndMerge(ctx context.Context) (int, error)
FindAndMerge scans recent observations and merges near-duplicate pairs. For each candidate, it performs a vector search; if a similar observation with the same project and type is found above the threshold, the lower-importance one is marked superseded. Returns the number of pairs merged.
type OrphanPatternResult ¶ added in v1.8.0
type OrphanPatternResult struct {
// OrphansFound is the total number of patterns that had at least one orphan observation reference.
OrphansFound int
// OrphansArchived is the number of patterns that were deprecated because ALL their observation IDs were orphaned.
OrphansArchived int
}
OrphanPatternResult holds the results of an orphan pattern cleanup pass.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles scheduled maintenance tasks.
func NewService ¶
func NewService( store *gorm.Store, observationStore *gorm.ObservationStore, injectionStore *gorm.InjectionStore, summaryStore *gorm.SummaryStore, promptStore *gorm.PromptStore, vectorCleanupFn func(ctx context.Context, deletedIDs []int64), cfg *config.Config, similarityTelemetry *telemetry.SimilarityTelemetry, smartGC *SmartGC, patternStore *gorm.PatternStore, vectorClient vector.Client, vectorSync *pgvector.Sync, relationStore *gorm.RelationStore, graphStore graph.GraphStore, log zerolog.Logger, ) *Service
NewService creates a new maintenance service.
func (*Service) CleanupOrphanPatterns ¶ added in v1.8.0
func (s *Service) CleanupOrphanPatterns(ctx context.Context, dryRun bool) (OrphanPatternResult, error)
CleanupOrphanPatterns detects patterns whose observation_ids reference non-existent observations. Patterns where all referenced observations are gone are deprecated. Patterns where only some references are gone have those references pruned. dryRun=true only counts without modifying.
func (*Service) IsEmbeddingModelChanged ¶ added in v1.7.0
IsEmbeddingModelChanged returns true if the embedding model changed since the last maintenance run.
type SmartGC ¶
type SmartGC struct {
// contains filtered or unexported fields
}
SmartGC archives low-value observations using multi-signal scoring. Unlike blunt age-based cleanup, it considers ImportanceScore, RetrievalCount, UtilityScore, SourceType, and observation age before archiving.
func NewSmartGC ¶
func NewSmartGC( store *gorm.Store, observationStore *gorm.ObservationStore, vectorCleanupFn func(ctx context.Context, deletedIDs []int64), calculator *scoring.Calculator, cfg *config.Config, log zerolog.Logger, ) *SmartGC
NewSmartGC creates a new SmartGC instance.
func (*SmartGC) Run ¶
func (gc *SmartGC) Run(ctx context.Context) SmartGCStats
Run executes the Smart GC pass across all projects.
func (*SmartGC) Stats ¶
func (gc *SmartGC) Stats() SmartGCStats
Stats returns the results of the last Smart GC run.