engine

package
v1.14.6 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 20 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine coordinates scoring, clustering, pruning and retrieval of memories.

func NewEngine

func NewEngine(store store.VectorStore, opts Options) *Engine

NewEngine constructs an advanced memory engine on top of a VectorStore implementation.

func (*Engine) MetricsSnapshot

func (e *Engine) MetricsSnapshot() MetricsSnapshot

MetricsSnapshot returns a copy of the runtime counters.

func (*Engine) Prune

func (e *Engine) Prune(ctx context.Context) (err error)

Prune applies TTL, size and deduplication policies.

func (*Engine) Retrieve

func (e *Engine) Retrieve(ctx context.Context, sessionID, query string, limit int) ([]model.MemoryRecord, error)

Retrieve performs weighted retrieval with MMR diversification and optional re-embedding.

func (*Engine) Store

func (e *Engine) Store(ctx context.Context, sessionID, content string, metadata map[string]any) (model.MemoryRecord, error)

Store embeds, scores and persists a new memory.

func (*Engine) WithEmbedder

func (e *Engine) WithEmbedder(embedder embed.Embedder) *Engine

WithEmbedder overrides the default embedder.

func (*Engine) WithLogger

func (e *Engine) WithLogger(logger *log.Logger) *Engine

WithLogger overrides the default logger.

func (*Engine) WithSummarizer

func (e *Engine) WithSummarizer(s Summarizer) *Engine

WithSummarizer overrides the default cluster summarizer.

type HeuristicSummarizer

type HeuristicSummarizer struct{}

HeuristicSummarizer produces deterministic summaries suitable for tests.

func (HeuristicSummarizer) Summarize

func (HeuristicSummarizer) Summarize(_ context.Context, cluster []model.MemoryRecord) (string, error)

type Metrics

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

Metrics captures lightweight runtime counters for observability.

func (*Metrics) IncClustersSummarized

func (m *Metrics) IncClustersSummarized()

func (*Metrics) IncDeduplicated

func (m *Metrics) IncDeduplicated()

func (*Metrics) IncPruned

func (m *Metrics) IncPruned(n int)

func (*Metrics) IncReembedded

func (m *Metrics) IncReembedded()

func (*Metrics) IncRetrieved

func (m *Metrics) IncRetrieved(n int)

func (*Metrics) IncSizeEvicted

func (m *Metrics) IncSizeEvicted(n int)

func (*Metrics) IncStored

func (m *Metrics) IncStored()

func (*Metrics) IncTTLExpired

func (m *Metrics) IncTTLExpired(n int)

func (*Metrics) ObserveRecency

func (m *Metrics) ObserveRecency(decay float64)

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() MetricsSnapshot

type MetricsSnapshot

type MetricsSnapshot struct {
	Stored             int64   `json:"stored"`
	Retrieved          int64   `json:"retrieved"`
	Deduplicated       int64   `json:"deduplicated"`
	Reembedded         int64   `json:"reembedded"`
	Pruned             int64   `json:"pruned"`
	ClustersSummarized int64   `json:"clusters_summarized"`
	TTLExpired         int64   `json:"ttl_expired"`
	SizeEvicted        int64   `json:"size_evicted"`
	RecencySamples     int64   `json:"recency_samples"`
	RecencyDecayAvg    float64 `json:"recency_decay_avg"`
}

Snapshot returns the current values for reporting/logging.

type Options

type Options struct {
	Weights                ScoreWeights
	LambdaMMR              float64
	HalfLife               time.Duration
	ClusterSimilarity      float64
	DriftThreshold         float64
	DuplicateSimilarity    float64
	TTL                    time.Duration
	MaxSize                int
	SourceBoost            map[string]float64
	Clock                  func() time.Time
	EnableSummaries        bool
	GraphNeighborhoodHops  int
	GraphNeighborhoodLimit int
}

Options configures the advanced memory engine.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the recommended defaults for the advanced memory engine.

type ScoreWeights

type ScoreWeights struct {
	Similarity float64
	Keywords   float64
	Importance float64
	Recency    float64
	Source     float64
}

ScoreWeights controls the contribution of each scoring component during retrieval.

type Summarizer

type Summarizer interface {
	Summarize(ctx context.Context, cluster []model.MemoryRecord) (string, error)
}

Summarizer abstracts cluster summarization backends (LLMs or heuristics).

Jump to

Keyboard shortcuts

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