controller

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmbedderNotAvailable is returned when an operation requires an embedder but one is not available.
	ErrEmbedderNotAvailable = errors.New("embedder not available")
)

Functions

This section is empty.

Types

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) All

func (mc *MemoryController) All(scopes []store.Scope) ([]store.Entry, error)

func (*MemoryController) AllByCategory

func (mc *MemoryController) AllByCategory(category string, topK int, scopes []store.Scope) ([]store.Entry, error)

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) Get

func (mc *MemoryController) Get(id string) (*store.Entry, error)

func (*MemoryController) ListHeads

func (mc *MemoryController) ListHeads(scopes []store.Scope) ([]store.HeadInfo, error)

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) Query

func (mc *MemoryController) Query(category string, tags []string) ([]store.Entry, error)

func (*MemoryController) QueryByCategory

func (mc *MemoryController) QueryByCategory(category, query string, topK int, scopes []store.Scope) ([]store.Entry, error)

func (*MemoryController) Save added in v0.0.7

func (mc *MemoryController) Save(entry *store.Entry) error

Save allows for re-save without all the embedding and deduplication logic of Upsert. DOES _NOT_ UPDATE INDEX.

func (*MemoryController) Score

func (mc *MemoryController) Score(id string, delta float64) error

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.

func (*MemoryController) Upsert

func (mc *MemoryController) Upsert(entry *store.Entry) error

type Option

type Option func(*options)

Option defines a functional option for configuring MemoryController.

func WithEmbedder

func WithEmbedder(e embed.Embedder) Option

WithEmbedder overrides the default embedder.

func WithIndexer

func WithIndexer(i index.Indexer) Option

WithIndexer overrides the default indexer.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger overrides the default logger.

func WithMnemonicDir

func WithMnemonicDir(dir string) Option

WithMnemonicDir sets the mnemonic directory (default: ~/.mnemonic).

func WithSkipInitialSync

func WithSkipInitialSync(skip bool) Option

WithSkipInitialSync skips the initial index sync on startup. Use this when restarting, or when invoking embedding manually.

func WithStore

func WithStore(s store.Store) Option

WithStore overrides the default store.

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.

type SimilarEntry added in v0.0.5

type SimilarEntry struct {
	store.Entry
	Distance float32
}

Jump to

Keyboard shortcuts

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