Documentation
¶
Index ¶
Constants ¶
const DefaultContextWindow = 512
DefaultContextWindow is the fallback context window (in tokens) when auto-detection is unavailable and no config is set.
Variables ¶
This section is empty.
Functions ¶
func EmbedForQuery ¶
EmbedForQuery is the canonical helper for embedding a search query. Uses the provider's EmbedQuery when implemented; otherwise calls Embed with a single-text slice. Returns a single vector (or nil + error).
Types ¶
type Provider ¶
type Provider interface {
// Embed generates embeddings for one or more texts. Returns one
// vector per input text, in the same order. Implementations should
// support batching where the underlying provider allows it.
Embed(ctx context.Context, texts []string) ([][]float32, error)
// ModelID returns the identifier of the model being used, for
// tracking in the embedding_model property on nodes.
ModelID() string
// ContextWindow returns the model's context window in tokens.
// Used to size chunks before embedding. Implementations should
// auto-detect where possible (e.g., Ollama /api/show) and fall
// back to config or DefaultContextWindow.
ContextWindow() int
}
Provider generates vector embeddings from text. This is the shared interface with multiple implementations -- the correct Go reason to define an interface at the provider (D29).
type QueryEmbedder ¶
QueryEmbedder is implemented by providers that distinguish between document-time and query-time embeddings at the underlying API level. Cohere on Bedrock accepts an `input_type` field that's "search_document" when embedding indexed content and "search_query" when embedding a retrieval query; using the document type for queries degrades cosine similarity measurably.
Search-time code should type-assert its embedder for QueryEmbedder and prefer EmbedQuery when available; non-implementing providers (OpenAI, Ollama, Titan) treat queries and documents identically and can fall back to Embed.
type SetupResult ¶
SetupResult describes what the setup process found and configured.
func SetupEmbedding ¶
func SetupEmbedding(ctx context.Context, cfg *config.Config) SetupResult
SetupEmbedding detects and configures an embedding provider. Modifies cfg in place. Returns a result with status messages for display.
Priority: if provider is already set (e.g., from config), use it. Otherwise try built-in BERT first (always available, just needs model download), then fall back to Ollama detection.