embeddings

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package embeddings

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRequestedTokens added in v0.19.0

func ParseRequestedTokens(message string) int

ParseRequestedTokens extracts the token count a provider reports in an oversize message (e.g. "...however you requested 9523 tokens..."), returning 0 when no count is present.

Types

type APIError added in v0.19.0

type APIError struct {
	// Status is the HTTP status code, or 0 for a transport-level failure
	// (connection refused, timeout) where no response was received.
	Status int
	// Code is the provider's machine error code when present (e.g.
	// "context_length_exceeded"); empty when the provider omits it.
	Code string
	// Message is the provider's human-readable error message, or the
	// transport error string when Status is 0.
	Message string
	// RequestedTokens is the token count the provider reported for the
	// rejected input, parsed from Message; 0 when not reported.
	RequestedTokens int
	// Transient marks a transport-level failure (Status 0) as retryable.
	Transient bool
}

APIError is a structured error from an embedding provider's HTTP API. It lets the embed pass tell three failure modes apart:

  • oversize input (IsOversize) — the model rejected the text for exceeding its context window; the caller should chunk the input and embed the pieces rather than retry the whole thing.
  • transient fault (Retryable) — a rate limit, server error, or transport failure; the same input may succeed on a later pass.
  • any other deterministic rejection — neither of the above; retrying the same input is pointless, so the caller records it and stops.

It unwraps to vector.ErrEmbedding so existing errors.Is(err, vector.ErrEmbedding) checks keep working.

func AsAPIError added in v0.19.0

func AsAPIError(err error) (*APIError, bool)

AsAPIError extracts an *APIError from err, if one is present in the chain.

func (*APIError) Error added in v0.19.0

func (e *APIError) Error() string

func (*APIError) IsOversize added in v0.19.0

func (e *APIError) IsOversize() bool

IsOversize reports whether the input was rejected for exceeding the model's context window — the signal to chunk the input and embed the pieces.

func (*APIError) Retryable added in v0.19.0

func (e *APIError) Retryable() bool

Retryable reports whether the failure is transient (rate limit, server error, or transport failure) and the same input may succeed on a later pass.

func (*APIError) Unwrap added in v0.19.0

func (e *APIError) Unwrap() error

Unwrap reports vector.ErrEmbedding so callers can keep matching on the package's sentinel.

type Embedder

type Embedder interface {
	// Embed converts text into a vector embedding.
	Embed(ctx context.Context, text string) ([]float32, error)

	// Close releases any resources held by the embedder.
	Close() error
}

Embedder provides text embedding capabilities.

Directories

Path Synopsis
Package ollama implements pkg/embedding's Embedder client for Ollama's embedding APIs
Package ollama implements pkg/embedding's Embedder client for Ollama's embedding APIs
Package openai implements pkg/embeddings's Embedder client for OpenAI's embeddings API.
Package openai implements pkg/embeddings's Embedder client for OpenAI's embeddings API.
Package embeddingutils is the embeddings utility package
Package embeddingutils is the embeddings utility package

Jump to

Keyboard shortcuts

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