embedding

package
v0.35.0-rc.0 Latest Latest
Warning

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

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

Documentation

Overview

Package embedding provides text embedding capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProbeV2 added in v0.35.0

func ProbeV2(ctx context.Context, proxyURL string, tokenFn func() string) (string, bool)

ProbeV2 reports whether the proxy exposes the versioned /v2/embedding route and, if so, the embedding model it currently advertises. It POSTs an empty check request to /v2/embedding/check; a 200 response means v2 is available and its model is returned. Any non-200 status or transport error yields ("", false), signalling the caller to fall back to the legacy /embed routes.

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. When v2 is set it targets the versioned /v2/embedding routes (fp32 at a fixed dimensionality, model advertised per response); otherwise it uses the legacy /embed routes.

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 RemoteEmbedder that calls the proxy's legacy /embed routes. 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 NewRemoteWithEndpoint added in v0.35.0

func NewRemoteWithEndpoint(
	log logrus.FieldLogger,
	proxyURL string,
	tokenFn func() string,
	invalidateFn func(),
	localCache cache.Cache,
	model string,
	v2 bool,
) *RemoteEmbedder

NewRemoteWithEndpoint creates a RemoteEmbedder targeting either the v2 (/v2/embedding) routes when v2 is true, or the legacy /embed routes otherwise.

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) Model added in v0.35.0

func (e *RemoteEmbedder) Model() string

Model returns the embedding model this embedder is keyed to. Index builds use it to tag the embedding space they were built in, so a later change to the proxy's served model can be detected and trigger a re-index.

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.

Jump to

Keyboard shortcuts

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