local

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package local implements the material.Searcher interface using local vector embeddings for similarity search over a user's own asset library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// EmbedEngine is the embedding backend used for vectorizing queries and assets.
	EmbedEngine embed.EmbedEngine
	// IndexPath is where the vector index is persisted (JSON file).
	IndexPath string
}

Config configures the local vector searcher.

type IndexEntry

type IndexEntry struct {
	Path      string            `json:"path"`
	MediaType string            `json:"media_type"`
	Size      int64             `json:"size,omitempty"`
	ModTime   int64             `json:"mod_time,omitempty"` // unix timestamp for change detection
	Vector    []float32         `json:"vector"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

IndexEntry represents a single indexed asset with its vector embedding.

type Searcher

type Searcher struct {
	// contains filtered or unexported fields
}

Searcher performs vector similarity search over locally indexed assets.

func New

func New(cfg Config) (*Searcher, error)

New creates a local vector searcher.

func (*Searcher) EntryCount

func (s *Searcher) EntryCount() int

EntryCount returns the number of indexed assets.

func (*Searcher) IndexDir

func (s *Searcher) IndexDir(ctx context.Context, dir string) (int, error)

IndexDir scans a directory and indexes all supported files incrementally. Files already indexed with the same size and mod time are skipped.

func (*Searcher) IndexFile

func (s *Searcher) IndexFile(ctx context.Context, path string) error

IndexFile adds or updates a single file in the vector index. If the file is already indexed and unchanged (same size + mod time), it is skipped.

func (*Searcher) RemoveStale

func (s *Searcher) RemoveStale() int

RemoveStale removes index entries whose files no longer exist on disk.

func (*Searcher) SaveIndex

func (s *Searcher) SaveIndex() error

SaveIndex persists the current index to disk.

func (*Searcher) Search

func (s *Searcher) Search(ctx context.Context, req material.Request) (material.Result, error)

Search vectorizes the query and finds the most similar assets in the index.

func (*Searcher) Source

func (s *Searcher) Source() string

func (*Searcher) SupportedMediaTypes

func (s *Searcher) SupportedMediaTypes() []string

Jump to

Keyboard shortcuts

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