Last updated 2026-05-17
Package llmrouter — Embeddings
Every public symbol declared in
embeddings.go.
One interface — Embedder —
plus the request and response types it speaks.
Import path:
import "github.com/elloloop/llmrouter"Embedder
The embedding contract. Implementations are concurrency-safe. Source: embeddings.go#L11.
type Embedder interface { Embed(ctx context.Context, req EmbedRequest) (*EmbedResponse, error)} Embed is a single-round-trip call — there is no
streaming, no Stream handle. A non-nil error is
returned on synchronous failures (bad config, non-2xx HTTP
status, malformed response body).
EmbedRequest
The polymorphic embedding-request shape. Source: embeddings.go#L17.
type EmbedRequest struct { Model string // model id; e.g. "text-embedding-3-small" Inputs []string // texts to embed; index-aligned with response Dimensions int // optional lower-dim output (OpenAI v3, Voyage, ...) TaskType string // task hint, normalised cross-vendor EncodingFormat string // "float" (default) or "base64" User string // OpenAI-style end-user id Raw json.RawMessage // byte passthrough; Model is overlaid}Model- The model identifier. The literal string is sent to the upstream; providers don't alias.
Inputs-
The list of strings to embed.
EmbedResponse.Embeddingsis index-aligned with this slice. Dimensions-
Requests a lower-dimensional output. Supported by OpenAI
text-embedding-3-*, Voyage, and a few others. Zero means "use the model default." TaskType-
Canonical task hint
(
RETRIEVAL_QUERY/RETRIEVAL_DOCUMENT/SEMANTIC_SIMILARITY/CLASSIFICATION/CLUSTERING/QUESTION_ANSWERING/FACT_VERIFICATION). Providers translate to their native vocabulary (Cohereinput_type, Voyageinput_type). See cross-vendor task-type mapping. EncodingFormat-
"float"(default) or"base64". Only affects wire format; the response always contains[][]float32. User- OpenAI-style end-user identifier for telemetry and abuse tracking. Forwarded by OpenAI / Azure; ignored elsewhere.
Raw-
Byte passthrough escape hatch. The library overlays
Model; everything else (Cohere'sembedding_types, Voyage'struncation, Titan'snormalize) survives.
EmbedResponse
The embedding-response shape. Source: embeddings.go#L51.
type EmbedResponse struct { Model string // resolved model id echoed by the provider Embeddings [][]float32 // index-aligned with EmbedRequest.Inputs Usage *Usage // token counts; may be nil Raw json.RawMessage // original wire-format JSON}Model-
The model id the upstream actually used. May include a version
suffix (
text-embedding-3-small-2024). Embeddings-
One vector per input.
len(Embeddings) == len(req.Inputs)always — the library reorders if the wire response is out-of-order tagged (Cohere v1 was, v3 is not). Usage-
Token usage. Embedding endpoints populate
PromptTokens(sometimes alsoTotalTokens). May be nil. Raw- Original wire bytes for callers that want to forward the response without re-marshaling.
See also
- Embeddings concept — narrative overview with examples.
- Voyage AI provider — embedding specialist.
- Cohere provider — input-type semantics.
- OpenAI provider — default embedding backend.