Documentation
¶
Overview ¶
Package embedder provides implementations of the rag.Embedder interface for converting text into dense vector embeddings. Each implementation talks to a different backend (OpenAI, Azure OpenAI, Ollama) via plain HTTP — no additional SDK dependencies are required.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDimensions ¶
DefaultDimensions returns the correct default embedding vector size for the given backend name. Callers that need to pre-configure a vector store (e.g. Qdrant collection creation) should use this rather than hardcoding a value. EMBEDDING_DIMENSIONS always takes precedence when set.
func NewFromEnv ¶
NewFromEnv constructs a rag.Embedder using cascading defaults that inherit from the chat provider configuration when embedding-specific overrides are not set.
Resolution order:
- EMBEDDING_PROVIDER — if unset, inherits MODEL_PROVIDER (default: ollama)
- Per-backend credentials are inherited from the chat provider's env vars
- EMBEDDING_MODEL — overrides the default model for the resolved backend
- EMBEDDING_API_KEY — overrides the inherited API key
- EMBEDDING_ENDPOINT — overrides the inherited endpoint
- EMBEDDING_DIMENSIONS — overrides the default dimensions (ollama: 768, openai/azure: 1536)
func ValidateForRAG ¶
ValidateForRAG checks that the embedder configuration is safe to use when QDRANT_HOST is set. It returns an error if the configuration is clearly broken (e.g. azure embedder with no API key), and logs a warning if EMBEDDING_MODEL looks like a chat model rather than an embedding model.
This is a pre-flight check — call it before constructing the embedder or the Qdrant store so operators get a clear error at startup rather than a cryptic failure during the first embed call.
Types ¶
type OllamaConfig ¶
type OllamaConfig struct {
// Host is the Ollama server base URL (e.g. "http://localhost:11434").
Host string
// Model is the embedding model name (e.g. "nomic-embed-text").
Model string
}
OllamaConfig holds the settings for constructing an OllamaEmbedder.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
// contains filtered or unexported fields
}
OllamaEmbedder implements rag.Embedder using the Ollama /api/embed endpoint. It is safe for concurrent use. No API key is required — Ollama runs locally.
func NewOllamaEmbedder ¶
func NewOllamaEmbedder(cfg *OllamaConfig) *OllamaEmbedder
NewOllamaEmbedder constructs an OllamaEmbedder from the given config.
type OpenAIConfig ¶
type OpenAIConfig struct {
// BaseURL is the API base URL. For OpenAI: "https://api.openai.com/v1".
// For Azure: "https://<resource>.openai.azure.com/openai".
BaseURL string
// APIKey is the authentication key.
APIKey string
// Model is the embedding model name (e.g. "text-embedding-3-small").
Model string
// Dimensions is the desired vector length (0 = model default).
Dimensions int
// Azure enables Azure OpenAI mode (api-key header + api-version param).
Azure bool
// APIVersion is the Azure OpenAI API version (e.g. "2025-04-01-preview").
// Ignored when Azure is false.
APIVersion string
}
OpenAIConfig holds the settings for constructing an OpenAIEmbedder.
type OpenAIEmbedder ¶
type OpenAIEmbedder struct {
// contains filtered or unexported fields
}
OpenAIEmbedder implements rag.Embedder using the OpenAI (or Azure OpenAI) embeddings REST API. It is safe for concurrent use.
func NewOpenAIEmbedder ¶
func NewOpenAIEmbedder(cfg *OpenAIConfig) *OpenAIEmbedder
NewOpenAIEmbedder constructs an OpenAIEmbedder from the given config.