Documentation
¶
Index ¶
- Constants
- func Register(registrar interface{ ... }, log ...logger.Logger)
- type Memory
- type Option
- func WithAIClient(client mcpai.Client, model string) Option
- func WithHalfLifeEvent(d time.Duration) Option
- func WithHalfLifeFact(d time.Duration) Option
- func WithHalfLifeNote(d time.Duration) Option
- func WithLogger(l logger.Logger) Option
- func WithMaxAge(d time.Duration) Option
- func WithPruneThreshold(f float64) Option
- func WithSimilarityMergeRange(mid, high float64) Option
- type Store
Constants ¶
const ( TypeFact = "fact" TypePreference = "preference" TypeEvent = "event" TypeNote = "note" DefaultMaxAge = 180 * 24 * time.Hour DefaultPruneThreshold = 0.1 DefaultHalfLifeFact = 90 * 24 * time.Hour DefaultHalfLifeEvent = 30 * 24 * time.Hour DefaultHalfLifeNote = 7 * 24 * time.Hour DefaultSimilarityHighThreshold = 0.85 // MinHash >= this -> update existing in place DefaultSimilarityMidThreshold = 0.50 // MinHash >= this -> ask LLM if available )
const MemoryLibraryName = "scriptling.ai.memory"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Memory ¶
type Memory struct {
ID string `msgpack:"id"`
Content string `msgpack:"content"`
Type string `msgpack:"type"`
Importance float64 `msgpack:"importance"`
CreatedAt time.Time `msgpack:"created_at"`
AccessedAt time.Time `msgpack:"accessed_at"`
MinHash []uint32 `msgpack:"min_hash"` // pre-computed MinHash signature for similarity
}
Memory is a single stored memory entry.
type Option ¶
type Option func(*storeConfig)
Option is a functional option for Store.
func WithAIClient ¶
WithAIClient enables LLM-based similarity resolution for compaction. If client is nil, only rule-based pruning and auto-merging are performed.
func WithHalfLifeEvent ¶
func WithHalfLifeFact ¶
func WithHalfLifeNote ¶
func WithMaxAge ¶
func WithPruneThreshold ¶
func WithSimilarityMergeRange ¶
WithSimilarityMergeRange sets the Jaccard similarity thresholds for pre-flight deduplication at write time. high: score >= high -> update existing memory in place (no LLM needed). mid: score >= mid -> ask LLM to merge or keep separate (if LLM configured).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a memory store backed by a snapshotkv DB. It does not own the DB - the caller manages its lifecycle.
func New ¶
func New(db *snapshotkv.DB, opts ...Option) *Store
New creates a Store using the provided DB and optional functional options.
func (*Store) Compact ¶
Compact runs compaction synchronously (prune + deduplicate). Returns the number of memories remaining after compaction.
func (*Store) Recall ¶
Recall searches memories by keyword and semantic similarity, returning up to limit results ranked by score. Use limit=-1 for unlimited results. Use typeFilter="!xxx" to exclude a type (e.g., "!preference" returns all non-preferences).
func (*Store) Remember ¶
Remember stores a memory and returns it with a UUIDv7 ID. Before saving, performs a pre-flight similarity check against existing memories of the same type:
- score >= similarityHighThreshold -> update the existing memory in place
- score >= similarityMidThreshold -> ask LLM to merge or keep (if configured)
After saving, checks whether background compaction should be triggered.