controller

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 17 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) 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) 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) Score

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

func (*MemoryController) SemanticSearch

func (mc *MemoryController) SemanticSearch(query string, k int, scopes []store.Scope) ([]store.Entry, error)

SemanticSearch embeds the query and returns the k nearest entries. Returns nil when the embedder is unavailable.

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) ([]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.

Jump to

Keyboard shortcuts

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