Help us shape the future of Go! Take the 2026 Go Developer Survey

embedder

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package embedder turns text into vectors via an OpenAI-compatible /v1/embeddings endpoint — llama.cpp, Ollama, vLLM, LM Studio or any gateway that speaks the same shape. Everything runs against a URL you control; there is no cloud SDK and no credential handling here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbedMetrics

type EmbedMetrics struct {
	CacheHits  int64 `json:"cacheHits"`
	EmbedCalls int64 `json:"embedCalls"`
}

EmbedMetrics holds cache and API call counters.

type Embedder

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

Embedder generates vector embeddings through an OpenAI-compatible gateway, memoizing exact-text lookups so repeated queries cost nothing.

func NewEmbedder

func NewEmbedder(_ context.Context, endpoint, model string, outputDims, maxInputChars int, logger zerolog.Logger) (*Embedder, error)

NewEmbedder creates an Embedder against an OpenAI-compatible endpoint. outputDims reduces the output dimension (0 = model native); it is applied client-side as a Matryoshka truncation, see truncateNormalize. maxInputChars hard-caps input length before the call (0 = defaultMaxInputChars).

func (*Embedder) EmbedBatch

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

EmbedBatch returns embeddings for multiple texts, preserving input order. It issues up to embedBatchConcurrency requests concurrently and fails fast on the first error, cancelling the rest.

func (*Embedder) EmbedDocument

func (e *Embedder) EmbedDocument(ctx context.Context, text string) ([]float32, error)

EmbedDocument returns the embedding vector for a document to be indexed.

func (*Embedder) EmbedQuery

func (e *Embedder) EmbedQuery(ctx context.Context, text string) ([]float32, error)

EmbedQuery returns the embedding vector for a search query.

func (*Embedder) Metrics

func (e *Embedder) Metrics() EmbedMetrics

Metrics returns a snapshot of cache hit and API call counters.

Jump to

Keyboard shortcuts

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