embedding

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 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

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,
	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. 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).

Jump to

Keyboard shortcuts

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