lifecycle

package
v0.0.0-...-a3bda8b Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSimilarityThreshold = 0.92

DefaultSimilarityThreshold is the default cosine similarity threshold for entity merging.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsolidationResult

type ConsolidationResult struct {
	KBID             string       `json:"kb_id"`
	Candidates       int          `json:"candidates"`
	Merged           int          `json:"merged"`
	Pairs            []*MergePair `json:"pairs,omitempty"`
	RelationsFixed   int64        `json:"relations_fixed"`
	RelationsDeduped int64        `json:"relations_deduped"`
}

ConsolidationResult summarizes a consolidation run.

type Consolidator

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

Consolidator finds and merges duplicate entities based on embedding similarity.

func NewConsolidator

func NewConsolidator(store storage.Store, threshold float64) *Consolidator

NewConsolidator creates a consolidator with the given similarity threshold.

func (*Consolidator) FindCandidates

func (c *Consolidator) FindCandidates(ctx context.Context, kbID string) ([]*MergePair, error)

FindCandidates returns pairs of entities with similarity above threshold. This is a brute-force O(n²) scan — suitable for <10K entities per KB.

func (*Consolidator) Merge

func (c *Consolidator) Merge(ctx context.Context, kbID string, pair *MergePair) (*MergeResult, error)

Merge executes a consolidation: redirects relations from merged entity to survivor, deduplicates any resulting duplicate edges, then deletes the merged entity.

func (*Consolidator) RunConsolidation

func (c *Consolidator) RunConsolidation(ctx context.Context, kbID string) (*ConsolidationResult, error)

RunConsolidation finds candidates and merges them all. Returns a summary.

type Manager

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

Manager runs periodic decay and prune cycles across all knowledge bases.

func NewManager

func NewManager(store storage.Store, cfg ManagerConfig) *Manager

NewManager creates a lifecycle manager.

func (*Manager) DecayKB

func (m *Manager) DecayKB(ctx context.Context, kbID string) (int64, error)

DecayKB runs a single decay pass on one knowledge base.

func (*Manager) PruneKB

func (m *Manager) PruneKB(ctx context.Context, kbID string, threshold float64) (int, error)

PruneKB runs a single prune pass on one knowledge base.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run starts the lifecycle loop. Blocks until ctx is cancelled.

type ManagerConfig

type ManagerConfig struct {
	DecayInterval  time.Duration // how often to run decay (default 1h)
	PruneInterval  time.Duration // how often to run prune (default 24h)
	DecayHalfLife  float64       // half-life in hours (default 168 = 1 week)
	PruneThreshold float64       // minimum strength to keep (default 0.05)
}

ManagerConfig configures the background lifecycle manager.

type MergePair

type MergePair struct {
	Survivor *domain.Entity `json:"survivor"`
	Merged   *domain.Entity `json:"merged"`
	Score    float64        `json:"score"` // cosine similarity
}

MergePair represents two entities that should be merged.

type MergeResult

type MergeResult struct {
	RelationsRedirected int64
	RelationsDeduped    int64
}

MergeResult holds counters from a single entity merge operation.

Jump to

Keyboard shortcuts

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