Documentation
¶
Overview ¶
Package embedding provides text embedding capabilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Embedder ¶
type Embedder interface {
// Embed returns the L2-normalized embedding vector for a single text string.
Embed(text string) ([]float32, error)
// EmbedBatch returns L2-normalized embedding vectors for multiple texts.
EmbedBatch(texts []string) ([][]float32, error)
// Close releases resources held by the embedder.
Close() error
}
Embedder provides text embedding capabilities.
type RemoteEmbedder ¶ added in v0.14.0
type RemoteEmbedder struct {
// contains filtered or unexported fields
}
RemoteEmbedder implements Embedder by calling the proxy's /embed endpoint. An optional local cache avoids round-trips to the proxy on warm restarts.
func NewRemote ¶ added in v0.14.0
func NewRemote( log logrus.FieldLogger, proxyURL string, tokenFn func() string, invalidateFn func(), localCache cache.Cache, model string, ) *RemoteEmbedder
NewRemote creates a new RemoteEmbedder that calls the proxy's /embed endpoint. tokenFn is called on each request to get the current auth token, and invalidateFn drops the cached token so a 401/403 can be retried with a fresh one (it may be nil to disable the retry). localCache and model are optional — when both are set, embedding vectors are cached locally using {model}:{textHash} keys to avoid proxy round-trips.
func (*RemoteEmbedder) Close ¶ added in v0.14.0
func (e *RemoteEmbedder) Close() error
Close releases resources held by the embedder.
func (*RemoteEmbedder) Embed ¶ added in v0.14.0
func (e *RemoteEmbedder) Embed(text string) ([]float32, error)
Embed returns the L2-normalized embedding vector for a single text string.
func (*RemoteEmbedder) EmbedBatch ¶ added in v0.14.0
func (e *RemoteEmbedder) EmbedBatch(texts []string) ([][]float32, error)
EmbedBatch returns L2-normalized embedding vectors for multiple texts. When a local cache is configured, vectors are checked there first. Remaining misses are split into sub-batches of maxBatchSize and sent to the proxy (which has its own Redis cache + upstream API).
func (*RemoteEmbedder) OnProgress ¶ added in v0.34.0
func (e *RemoteEmbedder) OnProgress(fn func(completed, total int))
OnProgress registers a callback invoked during EmbedBatch with the number of documents embedded so far and the total in the batch. It enables document-level progress reporting for index builds.