Documentation
¶
Overview ¶
Package embedding provides text embedding via external APIs (OpenAI, Ollama).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFunctions ¶
func RegisterFunctions()
RegisterFunctions registers embed() and embed_dim() in the expression registry.
func SetProvider ¶
func SetProvider(p Provider)
SetProvider configures the global embedding provider used by embed().
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an LRU cache for embeddings keyed on (model, text_hash).
type Ollama ¶
type Ollama struct {
// contains filtered or unexported fields
}
Ollama implements Provider using a local Ollama server's /api/embed endpoint.
func NewOllama ¶
func NewOllama(cfg OllamaConfig, cache *Cache) *Ollama
NewOllama creates an Ollama embedding provider.
type OllamaConfig ¶
type OllamaConfig struct {
Model string // default: nomic-embed-text
Dimensions int // 0 = inferred from the model name (falls back to first response)
BaseURL string // default: http://localhost:11434
}
OllamaConfig configures the Ollama embedding provider for local, self-hosted embedding models (no API key, runs on the user's machine).
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI implements Provider using the OpenAI embeddings API.
func NewOpenAI ¶
func NewOpenAI(cfg OpenAIConfig, cache *Cache) *OpenAI
NewOpenAI creates an OpenAI embedding provider.
type OpenAIConfig ¶
type OpenAIConfig struct {
APIKey string // required
Model string // default: text-embedding-3-small
Dimensions int // 0 = model default (1536 for small, 3072 for large)
BaseURL string // default: https://api.openai.com/v1
}
OpenAIConfig configures the OpenAI embedding provider.
type Provider ¶
type Provider interface {
// Embed returns embedding vectors for one or more texts.
// The returned slice has the same length as texts.
Embed(texts []string) ([][]float32, error)
// Dimension returns the output vector dimension.
Dimension() int
// Model returns the model identifier.
Model() string
}
Provider generates vector embeddings from text.
func GetProvider ¶
func GetProvider() Provider
GetProvider returns the current global provider, or nil.
type Voyage ¶
type Voyage struct {
// contains filtered or unexported fields
}
Voyage implements Provider using the Voyage AI embeddings API.
func NewVoyage ¶
func NewVoyage(cfg VoyageConfig, cache *Cache) *Voyage
NewVoyage creates a Voyage AI embedding provider.
type VoyageConfig ¶
type VoyageConfig struct {
APIKey string // required
Model string // default: voyage-3.5
Dimensions int // 0 = model default (1024 for voyage-3.5 / voyage-3-large)
InputType string // optional: "document" or "query" — improves retrieval quality
BaseURL string // default: https://api.voyageai.com/v1
}
VoyageConfig configures the Voyage AI embedding provider. Voyage AI is Anthropic's officially recommended embeddings provider — Anthropic does not serve a native embeddings endpoint, so "Anthropic embeddings" means Voyage. See https://docs.claude.com/en/docs/build-with-claude/embeddings.