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

embedder

package
v1.11.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL  string
	APIKey   string
	Model    string
	Provider Provider
	Timeout  time.Duration
	// BatchSize caps how many texts are sent in a single embeddings API
	// call, defaulting to defaultEmbedBatchSize when zero. Most hosted
	// embedding APIs enforce a per-request token/count budget - Mistral's
	// embeddings endpoint, for one, rejects a request outright with "too
	// many tokens overall, split into more batches" rather than truncating,
	// so a single call for an entire large document's chunks fails instead
	// of just running slowly.
	BatchSize int
}

Config holds the configuration for a provider-backed embedder.

func FromEnv

func FromEnv() *Config

FromEnv reads embedding configuration from environment variables:

RAG_EMBEDDING_URL      — base URL (e.g. https://api.openai.com/v1 or http://localhost:11434)
RAG_EMBEDDING_MODEL    — model name (e.g. text-embedding-3-small or nomic-embed-text)
RAG_EMBEDDING_API_KEY  — API key (optional for Ollama)
RAG_EMBEDDING_PROVIDER — "openai" or "ollama" (auto-detected if empty)

func (*Config) IsConfigured

func (c *Config) IsConfigured() bool

IsConfigured reports whether all required fields are present.

type Embedder

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

Embedder calls a remote embedding API to produce dense float vectors.

func New

func New(cfg *Config) *Embedder

New creates an Embedder from an explicit Config.

func NewFromEnv

func NewFromEnv() *Embedder

NewFromEnv creates an Embedder from environment variables. Returns nil if the required variables are not set (so callers can guard with IsConfigured).

func (*Embedder) EmbedTexts

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

EmbedTexts implements rag.Embedder. Splits texts into Config.BatchSize- sized groups and calls the provider once per group, concatenating results in order - a single unbounded call for a large document's worth of chunks can be flatly rejected by the provider (see Config.BatchSize).

type Provider

type Provider string

Provider selects which embedding API format to use.

const (
	ProviderOpenAI Provider = "openai" // OpenAI-compatible: POST /embeddings
	ProviderOllama Provider = "ollama" // Ollama: POST /api/embed
)

func DetectProviderPublic

func DetectProviderPublic(baseURL string) Provider

DetectProviderPublic is the exported version of detectProvider for use outside this package.

Jump to

Keyboard shortcuts

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