Documentation
¶
Index ¶
- func NormalizeScope(scope string) string
- type EntityMemory
- type EntityStore
- type Entry
- type MemVectorStore
- func (s *MemVectorStore) Clear(_ context.Context) error
- func (s *MemVectorStore) Close() error
- func (s *MemVectorStore) Delete(_ context.Context, scope string) error
- func (s *MemVectorStore) Save(_ context.Context, scope, content string, embedding []float64, ...) (string, error)
- func (s *MemVectorStore) Search(_ context.Context, queryEmbedding []float64, limit int, scopeFilter string) ([]ScoredMemory, error)
- type MemoryScope
- type RecallOption
- type RememberOption
- type SQLiteVecOption
- type SQLiteVecStore
- func (s *SQLiteVecStore) Clear(_ context.Context) error
- func (s *SQLiteVecStore) Close() error
- func (s *SQLiteVecStore) Delete(_ context.Context, scope string) error
- func (s *SQLiteVecStore) Save(_ context.Context, scope, content string, embedding []float64, ...) (string, error)
- func (s *SQLiteVecStore) Search(_ context.Context, queryEmbedding []float64, limit int, scopeFilter string) ([]ScoredMemory, error)
- type ScoredMemory
- type ShortTerm
- type StorageBackend
- type Store
- type UnifiedMemory
- func (m *UnifiedMemory) AsStore() Store
- func (m *UnifiedMemory) Close() error
- func (m *UnifiedMemory) ExtractMemories(_ context.Context, content string) ([]string, error)
- func (m *UnifiedMemory) Forget(ctx context.Context, scope string) error
- func (m *UnifiedMemory) Recall(ctx context.Context, query string, opts ...RecallOption) (results []ScoredMemory, err error)
- func (m *UnifiedMemory) Remember(ctx context.Context, scope, content string, opts ...RememberOption) (err error)
- type UnifiedMemoryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeScope ¶ added in v0.7.0
NormalizeScope cleans a scope path: lowercases, removes trailing slash (except for root), and collapses double slashes.
Types ¶
type EntityMemory ¶
type EntityMemory struct {
ShortTerm
// contains filtered or unexported fields
}
EntityMemory extends ShortTerm with entity-specific fact storage.
func NewEntityMemory ¶
func NewEntityMemory(limit int) *EntityMemory
NewEntityMemory creates a new EntityMemory with the given entry limit.
func (*EntityMemory) GetAllEntities ¶
func (e *EntityMemory) GetAllEntities(_ context.Context) ([]string, error)
GetAllEntities returns all entity names that have stored facts.
type EntityStore ¶
type EntityStore interface {
Store
SaveFact(ctx context.Context, entity string, fact string) error
GetFacts(ctx context.Context, entity string) ([]string, error)
GetAllEntities(ctx context.Context) ([]string, error)
}
EntityStore extends Store with entity-specific fact storage and retrieval.
type Entry ¶
type Entry struct {
Role string `json:"role"`
Content string `json:"content"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Entry represents a single memory entry with role, content, and metadata.
type MemVectorStore ¶ added in v0.7.0
type MemVectorStore struct {
// contains filtered or unexported fields
}
MemVectorStore is an in-memory StorageBackend using brute-force cosine similarity.
func NewMemVectorStore ¶ added in v0.7.0
func NewMemVectorStore() *MemVectorStore
NewMemVectorStore creates an empty in-memory vector store.
func (*MemVectorStore) Clear ¶ added in v0.7.0
func (s *MemVectorStore) Clear(_ context.Context) error
func (*MemVectorStore) Close ¶ added in v0.7.0
func (s *MemVectorStore) Close() error
func (*MemVectorStore) Delete ¶ added in v0.7.0
func (s *MemVectorStore) Delete(_ context.Context, scope string) error
func (*MemVectorStore) Search ¶ added in v0.7.0
func (s *MemVectorStore) Search(_ context.Context, queryEmbedding []float64, limit int, scopeFilter string) ([]ScoredMemory, error)
type MemoryScope ¶ added in v0.7.0
type MemoryScope struct {
// contains filtered or unexported fields
}
MemoryScope represents a node in the hierarchical memory scope tree.
func GetScope ¶ added in v0.7.0
func GetScope(path string) *MemoryScope
GetScope returns the MemoryScope node for the given path, creating intermediate nodes as needed. Thread-safe.
func (*MemoryScope) Child ¶ added in v0.7.0
func (s *MemoryScope) Child(name string) *MemoryScope
Child returns the named child scope, creating it if it doesn't exist.
func (*MemoryScope) Children ¶ added in v0.7.0
func (s *MemoryScope) Children() []*MemoryScope
Children returns a copy of the direct child scopes.
func (*MemoryScope) DeleteSubtree ¶ added in v0.7.0
func (s *MemoryScope) DeleteSubtree()
DeleteSubtree removes this scope and all descendants from the parent's children map. Does nothing for the root scope.
func (*MemoryScope) Parent ¶ added in v0.7.0
func (s *MemoryScope) Parent() *MemoryScope
Parent returns the parent scope node, or nil for root.
func (*MemoryScope) Path ¶ added in v0.7.0
func (s *MemoryScope) Path() string
Path returns the normalized scope path (always ends with / except root).
type RecallOption ¶ added in v0.7.0
type RecallOption interface {
// contains filtered or unexported methods
}
RecallOption configures a Recall call.
func WithLimit ¶ added in v0.7.0
func WithLimit(limit int) RecallOption
WithLimit sets the maximum number of results (default 10).
func WithScope ¶ added in v0.7.0
func WithScope(scope string) RecallOption
WithScope restricts recall to entries within the given scope subtree.
type RememberOption ¶ added in v0.7.0
type RememberOption interface {
// contains filtered or unexported methods
}
RememberOption configures a Remember call.
func WithImportance ¶ added in v0.7.0
func WithImportance(importance float64) RememberOption
WithImportance sets the importance score for the memory entry (0.0 to 1.0).
type SQLiteVecOption ¶ added in v0.7.0
type SQLiteVecOption func(*SQLiteVecStore)
SQLiteVecOption configures the SQLiteVecStore.
func WithDBPath ¶ added in v0.7.0
func WithDBPath(path string) SQLiteVecOption
WithDBPath sets the SQLite database file path.
type SQLiteVecStore ¶ added in v0.7.0
type SQLiteVecStore struct {
// contains filtered or unexported fields
}
SQLiteVecStore is a StorageBackend backed by a SQLite database with brute-force cosine similarity search.
func NewSQLiteVecStore ¶ added in v0.7.0
func NewSQLiteVecStore(opts ...SQLiteVecOption) (*SQLiteVecStore, error)
NewSQLiteVecStore creates a SQLiteVecStore, opening or creating the database.
func (*SQLiteVecStore) Clear ¶ added in v0.7.0
func (s *SQLiteVecStore) Clear(_ context.Context) error
func (*SQLiteVecStore) Close ¶ added in v0.7.0
func (s *SQLiteVecStore) Close() error
func (*SQLiteVecStore) Delete ¶ added in v0.7.0
func (s *SQLiteVecStore) Delete(_ context.Context, scope string) error
func (*SQLiteVecStore) Search ¶ added in v0.7.0
func (s *SQLiteVecStore) Search(_ context.Context, queryEmbedding []float64, limit int, scopeFilter string) ([]ScoredMemory, error)
type ScoredMemory ¶ added in v0.7.0
type ScoredMemory struct {
ID string `json:"id"`
Scope string `json:"scope"`
Content string `json:"content"`
Score float64 `json:"score"`
MatchReasons []string `json:"match_reasons,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Importance float64 `json:"importance"`
CreatedAt time.Time `json:"created_at"`
// contains filtered or unexported fields
}
ScoredMemory is a single retrieved memory result with composite score.
type ShortTerm ¶
type ShortTerm struct {
// contains filtered or unexported fields
}
ShortTerm is an in-memory circular buffer store for recent conversation entries.
func NewShortTerm ¶
NewShortTerm creates a new ShortTerm store with the given entry limit.
type StorageBackend ¶ added in v0.7.0
type StorageBackend interface {
// Save stores a memory entry with its embedding and metadata.
Save(ctx context.Context, scope, content string, embedding []float64, metadata map[string]any) (id string, err error)
// Search returns all entries under scopeFilter (subtree) scored by
// brute-force cosine similarity against queryEmbedding. The returned
// Score field is raw cosine similarity (not composite) — UnifiedMemory
// applies composite scoring after Search.
Search(ctx context.Context, queryEmbedding []float64, limit int, scopeFilter string) ([]ScoredMemory, error)
// Delete removes all entries whose scope starts with scope (subtree).
Delete(ctx context.Context, scope string) error
// Clear removes all entries.
Clear(ctx context.Context) error
// Close releases backend resources.
Close() error
}
StorageBackend is the pluggable persistence layer for UnifiedMemory.
type Store ¶
type Store interface {
Save(ctx context.Context, key string, entry Entry) error
Search(ctx context.Context, key string, query string, limit int) ([]Entry, error)
Clear(ctx context.Context) error
}
Store is the interface for basic memory storage and retrieval.
type UnifiedMemory ¶ added in v0.7.0
type UnifiedMemory struct {
// contains filtered or unexported fields
}
UnifiedMemory is a hierarchical, scored memory system with pluggable backends.
func NewUnifiedMemory ¶ added in v0.7.0
func NewUnifiedMemory(cfg UnifiedMemoryConfig) *UnifiedMemory
NewUnifiedMemory creates a UnifiedMemory with the given config.
func (*UnifiedMemory) AsStore ¶ added in v0.7.0
func (m *UnifiedMemory) AsStore() Store
AsStore returns a memory.Store adapter wrapping this UnifiedMemory.
func (*UnifiedMemory) Close ¶ added in v0.7.0
func (m *UnifiedMemory) Close() error
Close releases backend resources and prevents further use.
func (*UnifiedMemory) ExtractMemories ¶ added in v0.7.0
ExtractMemories implements the UnifiedMemory method for splitting text into atomic factual sentences.
func (*UnifiedMemory) Forget ¶ added in v0.7.0
func (m *UnifiedMemory) Forget(ctx context.Context, scope string) error
Forget removes all memories under the given scope subtree.
func (*UnifiedMemory) Recall ¶ added in v0.7.0
func (m *UnifiedMemory) Recall(ctx context.Context, query string, opts ...RecallOption) (results []ScoredMemory, err error)
Recall retrieves scored memories matching the query, scoped and sorted by composite score.
func (*UnifiedMemory) Remember ¶ added in v0.7.0
func (m *UnifiedMemory) Remember(ctx context.Context, scope, content string, opts ...RememberOption) (err error)
Remember stores content with an optional scope and options.
type UnifiedMemoryConfig ¶ added in v0.7.0
type UnifiedMemoryConfig struct {
// SemanticWeight is the weight for cosine-similarity score (default 0.4).
SemanticWeight float64
// RecencyWeight is the weight for recency-based score (default 0.35).
RecencyWeight float64
// ImportanceWeight is the weight for user-assigned importance (default 0.25).
ImportanceWeight float64
// RecencyHalfLifeDays controls how fast recency decays (default 7.0).
RecencyHalfLifeDays float64
// StorageBackend is the persistence layer. Defaults to MemVectorStore.
StorageBackend StorageBackend
// Embedder converts text to a float64 vector. When nil, Recall uses
// recency + importance only (no semantic score).
Embedder func(ctx context.Context, text string) ([]float64, error)
// ScopeInference enables LLM-based scope inference when Remember is
// called with an empty scope (default false).
ScopeInference bool
// Callback is invoked for memory lifecycle events.
Callback callback.Callback
}
UnifiedMemoryConfig configures a UnifiedMemory instance.