embedcache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package embedcache caches embedding vectors keyed by (model_id, dim, sha256(text)) so repeated ingest runs over the same corpus do not re-embed unchanged chunks. The store is its own SQLite file; it shares no schema with memmy's reference backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashText

func HashText(text string) string

HashText returns the sha256 hex digest used for the cache key.

Types

type Cache

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

Cache is a content-addressed embedding cache backed by SQLite.

func Open

func Open(path string) (*Cache, error)

Open opens or creates the cache file at path.

func (*Cache) Close

func (c *Cache) Close() error

Close releases the database handle.

func (*Cache) Count

func (c *Cache) Count(ctx context.Context) (int, error)

Count returns the total number of cached vectors.

func (*Cache) EmbedBatch

func (c *Cache) EmbedBatch(ctx context.Context, e embed.Embedder, modelID string, task embed.EmbedTask, texts []string) ([][]float32, error)

EmbedBatch returns vectors aligned with `texts`, hitting the cache for known content and calling embedder for the misses. The result preserves input order regardless of cache hit pattern.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, modelID string, dim int, text string) ([]float32, bool, error)

Get returns (vec, true) when a vector for (modelID, dim, text) is cached. The vector is freshly allocated on each call so callers cannot accidentally mutate the stored row.

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, modelID string, dim int, text string, vec []float32) error

Put stores a vector under (modelID, dim, text). Idempotent.

Jump to

Keyboard shortcuts

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