embedding

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewProviderRegistry()

DefaultRegistry is the global provider registry used by init() auto-registration.

View Source
var ErrMissingCredentials = errdefs.Unauthorized(errors.New("embedding: missing required credentials"))

ErrMissingCredentials is returned when a provider cannot be created because required credentials (api_key, endpoint, etc.) are missing.

Functions

func EmbedText

func EmbedText(ctx context.Context, emb Embedder, text string) ([]float32, error)

EmbedText calls Embed when emb is non-nil; otherwise returns nil, nil.

func ListProviders

func ListProviders() []string

ListProviders lists providers from DefaultRegistry.

func RegisterProvider

func RegisterProvider(name string, factory ProviderFactory)

RegisterProvider registers a factory in DefaultRegistry.

Types

type DimensionAware

type DimensionAware interface {
	Dimensions() int
}

DimensionAware is an optional interface that Embedder implementations may implement to report their output vector dimensions.

type Embedder

type Embedder interface {
	Embed(ctx context.Context, text string) ([]float32, error)
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
}

Embedder generates vector embeddings from text. Implementations must be safe for concurrent use.

Embed returns a single embedding for the given text. EmbedBatch returns embeddings for multiple texts (order-preserving). Implementations that do not support batching may fall back to sequential single calls.

func NewFromConfig

func NewFromConfig(provider, model string, config map[string]any) (Embedder, error)

NewFromConfig creates an Embedder from DefaultRegistry.

type ProviderFactory

type ProviderFactory func(model string, config map[string]any) (Embedder, error)

ProviderFactory creates an Embedder for the given model. config contains connection settings (api_key, base_url, etc.).

type ProviderRegistry

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

ProviderRegistry is a thread-safe registry of embedding provider factories.

func NewProviderRegistry

func NewProviderRegistry() *ProviderRegistry

func (*ProviderRegistry) ListProviders

func (r *ProviderRegistry) ListProviders() []string

func (*ProviderRegistry) NewFromConfig

func (r *ProviderRegistry) NewFromConfig(provider, model string, config map[string]any) (Embedder, error)

NewFromConfig creates an Embedder via the registered factory. Returns an error if the provider is not registered.

func (*ProviderRegistry) Register

func (r *ProviderRegistry) Register(name string, factory ProviderFactory)

Jump to

Keyboard shortcuts

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