Documentation
¶
Index ¶
- Variables
- type IndexManager
- type IndexMetadata
- type MemoryController
- func (mc *MemoryController) All(scopes []store.Scope) ([]store.Entry, error)
- func (mc *MemoryController) AllByCategory(category string, topK int, scopes []store.Scope) ([]store.Entry, error)
- func (mc *MemoryController) BuildIndexes(force bool) error
- func (mc *MemoryController) Close() error
- func (mc *MemoryController) Delete(id string) error
- func (mc *MemoryController) FindSimilar(id string, threshold float64) ([]SimilarEntry, error)
- func (mc *MemoryController) Get(id string) (*store.Entry, error)
- func (mc *MemoryController) ListHeads(scopes []store.Scope) ([]store.HeadInfo, error)
- func (mc *MemoryController) Merge(keepId string, deleteId string) error
- func (mc *MemoryController) Promote(id string, targetScope store.Scope) error
- func (mc *MemoryController) Query(category string, tags []string) ([]store.Entry, error)
- func (mc *MemoryController) QueryByCategory(category, query string, topK int, scopes []store.Scope) ([]store.Entry, error)
- func (mc *MemoryController) Save(entry *store.Entry) error
- func (mc *MemoryController) Score(id string, delta float64) error
- func (mc *MemoryController) SemanticSearch(query string, k int, scopes []store.Scope, categories []string) ([]store.Entry, error)
- func (mc *MemoryController) Upsert(entry *store.Entry) error
- type Option
- type SemanticSearcher
- type SimilarEntry
Constants ¶
This section is empty.
Variables ¶
var ErrEmbedderNotAvailable = errors.New("embedder not available")
ErrEmbedderNotAvailable is returned when an operation requires an embedder but one is not available.
Functions ¶
This section is empty.
Types ¶
type IndexManager ¶ added in v0.0.10
type IndexManager interface {
index.Indexer
io.Closer
// Flush persists any dirty state to disk.
Flush() error
// BuildIndexes updates the index from the given entries. If force is true, the index is rebuilt from scratch.
// embed is used to retrieve vector representations for texts.
BuildIndexes(entries []store.Entry, force bool, embed func(texts []string) ([][]float32, error)) error
// IndexEntry inserts or updates an entry in the index.
IndexEntry(entry *store.Entry, embed func(text string) ([]float32, error))
// RemoveFromIndex deletes an entry from the index.
RemoveFromIndex(id string)
// Validate checks that the index is healthy.
Validate() error
}
IndexManager wraps an index.Indexer to manage its lifecycle, including synchronization and persistence.
type IndexMetadata ¶
type IndexMetadata struct {
// Entries maps entry ID to the time it was indexed.
Entries map[string]time.Time `json:"entries"`
}
IndexMetadata tracks which entry IDs have been indexed.
type MemoryController ¶
type MemoryController struct {
// contains filtered or unexported fields
}
MemoryController wraps a Store with optional semantic indexing via HNSW.
When an Embedder is available, it keeps vectors in sync with store entries and supports SemanticSearch. When no Embedder is available, it passes through to the inner store.
func New ¶
func New(conf config.Config, opts ...Option) (*MemoryController, error)
New creates a MemoryController. cfg is required; Embedder, Indexer, and Store are constructed from cfg unless overridden via options. mnemonicDir defaults to ~/.mnemonic unless overridden.
func (*MemoryController) AllByCategory ¶
func (*MemoryController) BuildIndexes ¶
func (mc *MemoryController) BuildIndexes(force bool) error
BuildIndexes builds the index or force rebuilds the entire index from scratch.
func (*MemoryController) Close ¶
func (mc *MemoryController) Close() error
Close stops the flush loop, persists the index, and closes the inner store.
func (*MemoryController) Delete ¶
func (mc *MemoryController) Delete(id string) error
func (*MemoryController) FindSimilar ¶ added in v0.0.5
func (mc *MemoryController) FindSimilar(id string, threshold float64) ([]SimilarEntry, error)
FindSimilar finds semantically similar entries by id with a threshold of similarity. A higher threshold means more similar results.
func (*MemoryController) Merge ¶ added in v0.0.5
func (mc *MemoryController) Merge(keepId string, deleteId string) error
Merge takes the text of the entry (keepId) and combines other metadata from the other entry (deleteId), then deletes the other entry. Text is only keept from the first (keepId), and fully discarded from the second (deleteId).
func (*MemoryController) Promote ¶
func (mc *MemoryController) Promote(id string, targetScope store.Scope) error
func (*MemoryController) QueryByCategory ¶
func (*MemoryController) Save ¶ added in v0.0.7
func (mc *MemoryController) Save(entry *store.Entry) error
Save persists an entry without controller-level semantic deduplication and keeps the vector index in sync when available.
func (*MemoryController) SemanticSearch ¶
func (mc *MemoryController) SemanticSearch(query string, k int, scopes []store.Scope, categories []string) ([]store.Entry, error)
SemanticSearch embeds the query and returns the k nearest entries. When categories are provided, semantic candidates category-limited so query filters apply consistently across semantic and keyword search. Returns nil when embedder is not available, or an error if embedding or index search fails.
type Option ¶
type Option func(*options)
Option defines a functional option for configuring MemoryController.
func WithEmbedder ¶
WithEmbedder overrides the default embedder.
func WithIndexManager ¶ added in v0.0.10
func WithIndexManager(m IndexManager) Option
WithIndexManager overrides the default index manager.
func WithMnemonicDir ¶
WithMnemonicDir sets the mnemonic directory (default: ~/.mnemonic).
func WithSkipInitialSync ¶
WithSkipInitialSync skips the initial index sync on startup. Use this when restarting, or when invoking embedding manually.
type SemanticSearcher ¶
type SemanticSearcher interface {
SemanticSearch(query string, k int, scopes []store.Scope, categories []string) ([]store.Entry, error)
}
SemanticSearcher implements vector-based semantic search. This is separate from store.Store because SemanticSearch is a responsibility of the embed.Embedder + index.Indexer control structure, not necessarily every future store implementation.