embedder

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package embedder defines the interface for generating vector embeddings from text.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("weave: not implemented")

ErrNotImplemented is returned when a feature is not yet implemented.

Functions

This section is empty.

Types

type EmbedResult

type EmbedResult struct {
	// Vector is the embedding vector.
	Vector []float32 `json:"vector"`
	// TokenCount is the number of tokens consumed.
	TokenCount int `json:"token_count"`
}

EmbedResult contains the embedding vector for a single text input.

type Embedder

type Embedder interface {
	// Embed generates embeddings for the given texts.
	Embed(ctx context.Context, texts []string) ([]EmbedResult, error)

	// Dimensions returns the dimensionality of the embeddings produced
	// by this embedder.
	Dimensions() int
}

Embedder generates vector embeddings from text.

type LocalEmbedder

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

LocalEmbedder is a placeholder for local model embedding (e.g., ONNX).

func NewLocalEmbedder

func NewLocalEmbedder(dimensions int) *LocalEmbedder

NewLocalEmbedder creates a placeholder local embedder.

func (*LocalEmbedder) Describe

func (*LocalEmbedder) Describe() weave.ComponentInfo

Describe reports the local embedder, which is not implemented yet: every Embed call returns ErrNotImplemented.

func (*LocalEmbedder) Dimensions

func (e *LocalEmbedder) Dimensions() int

Dimensions returns the configured dimensionality.

func (*LocalEmbedder) Embed

func (e *LocalEmbedder) Embed(_ context.Context, _ []string) ([]EmbedResult, error)

Embed is not yet implemented.

type OpenAIEmbedder

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

OpenAIEmbedder generates embeddings using the OpenAI Embeddings API.

func NewOpenAIEmbedder

func NewOpenAIEmbedder(apiKey string, opts ...OpenAIOption) *OpenAIEmbedder

NewOpenAIEmbedder creates an OpenAI embedder.

func (*OpenAIEmbedder) Describe

func (e *OpenAIEmbedder) Describe() weave.ComponentInfo

Describe reports the OpenAI embedder and its model.

func (*OpenAIEmbedder) Dimensions

func (e *OpenAIEmbedder) Dimensions() int

Dimensions returns the embedding dimensionality.

func (*OpenAIEmbedder) Embed

func (e *OpenAIEmbedder) Embed(ctx context.Context, texts []string) ([]EmbedResult, error)

Embed generates embeddings for the given texts.

type OpenAIOption

type OpenAIOption func(*OpenAIEmbedder)

OpenAIOption configures the OpenAI embedder.

func WithOpenAIBaseURL

func WithOpenAIBaseURL(baseURL string) OpenAIOption

WithOpenAIBaseURL overrides the base URL for API-compatible endpoints.

func WithOpenAIClient

func WithOpenAIClient(c *http.Client) OpenAIOption

WithOpenAIClient sets a custom HTTP client. The embedder traces each call itself, so a client whose transport is already traced (forge.HTTPClient, otelhttp) records the call twice.

func WithOpenAIDimensions

func WithOpenAIDimensions(dims int) OpenAIOption

WithOpenAIDimensions sets the output dimensions.

func WithOpenAIModel

func WithOpenAIModel(model string) OpenAIOption

WithOpenAIModel sets the model name (default: text-embedding-3-small).

type StatusError

type StatusError struct {
	// StatusCode is the HTTP status the endpoint returned.
	StatusCode int
}

StatusError is returned when the embeddings endpoint answers with a status other than 200 OK. Telemetry names a failed call by this type and the status code, never by the response body.

func (*StatusError) Error

func (e *StatusError) Error() string

Directories

Path Synopsis
nexus module

Jump to

Keyboard shortcuts

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