embedder

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParseRetryAfterForTest = parseRetryAfter

ParseRetryAfterForTest exposes parseRetryAfter for unit testing only.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	// Embed returns a vector embedding for the given text.
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch returns vector embeddings for multiple texts.
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimension returns the embedding vector dimension.
	Dimension() int
}

Embedder generates vector embeddings from text.

type OllamaEmbedder

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

OllamaEmbedder implements Embedder using the Ollama HTTP API.

func NewOllamaEmbedder

func NewOllamaEmbedder(baseURL, model string, dimension int, logger *slog.Logger) *OllamaEmbedder

NewOllamaEmbedder creates a new Ollama-based embedder.

func (*OllamaEmbedder) Dimension

func (o *OllamaEmbedder) Dimension() int

Dimension returns the embedding vector dimension.

func (*OllamaEmbedder) Embed

func (o *OllamaEmbedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed returns a vector embedding for the given text using the Ollama API.

func (*OllamaEmbedder) EmbedBatch

func (o *OllamaEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch embeds multiple texts in a single HTTP call to Ollama's /api/embed endpoint, which accepts an array of inputs and returns all embeddings at once. This is dramatically faster than per-text calls (1 round-trip vs N).

type OpenAIEmbedder added in v0.4.0

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

OpenAIEmbedder implements Embedder using the OpenAI Embeddings API. It uses text-embedding-3-small with a configurable dimensions parameter to maintain compatibility with existing Qdrant collections.

func NewOpenAIEmbedder added in v0.4.0

func NewOpenAIEmbedder(apiKey, model string, dimensions int, logger *slog.Logger) *OpenAIEmbedder

NewOpenAIEmbedder creates a new OpenAI-based embedder.

apiKey is the OpenAI API key (required). model defaults to "text-embedding-3-small" when empty. dimensions defaults to 768 when 0, enabling compatibility with existing Qdrant collections.

func NewOpenAIEmbedderWithURL added in v0.4.0

func NewOpenAIEmbedderWithURL(endpointURL, apiKey, model string, dimensions int, logger *slog.Logger) *OpenAIEmbedder

NewOpenAIEmbedderWithURL creates a new OpenAI-based embedder with a custom endpoint URL. This is intended for testing with a local httptest server; production code should use NewOpenAIEmbedder instead.

func (*OpenAIEmbedder) Dimension added in v0.4.0

func (o *OpenAIEmbedder) Dimension() int

Dimension returns the configured embedding dimension.

func (*OpenAIEmbedder) Embed added in v0.4.0

func (o *OpenAIEmbedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed returns a vector embedding for the given text using the OpenAI API.

func (*OpenAIEmbedder) EmbedBatch added in v0.4.0

func (o *OpenAIEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch returns vector embeddings for multiple texts in a single API call.

Jump to

Keyboard shortcuts

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