Documentation
¶
Overview ¶
Package embed defines the embedding providers the memory service uses to turn text into vectors: a search query on one side, the chunks of a concept on the other.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// Err is returned by Embed when it is not nil.
Err error
// contains filtered or unexported fields
}
Fake is a deterministic Provider for tests and CI: a hashed bag of words, so texts that share words land close together. It imitates a lexical embedder, not a semantic one — a quality claim needs a real model. Err, when set, makes Embed fail with it (the provider-down path).
type Kind ¶
type Kind int
Kind tells a provider which side of a search a text is on. Providers that need an instruction or an input_type for queries take it from the kind.
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI is a Provider over an OpenAI-compatible embeddings API.
func NewOpenAI ¶
func NewOpenAI(cfg *OpenAIConfig) (*OpenAI, error)
NewOpenAI validates the configuration and returns the provider.
type OpenAIConfig ¶
type OpenAIConfig struct {
// BaseURL is the API base, e.g. https://openrouter.ai/api/v1.
BaseURL string
APIKey string
Model string
// Dim is the stored vector size; sent as `dimensions` (MRL models).
Dim int
// QueryPrefix and DocPrefix are put before every text of that kind:
// Qwen3-Embedding expects an instruction before a query, e5 "query:" and
// "passage:".
QueryPrefix string
DocPrefix string
// InputType sends input_type "query" / "document": Perplexity's
// embeddings refuse to answer without it.
InputType bool
// Batch is the number of texts per request (0 = 64).
Batch int
// Timeout is per request (0 = 30s).
Timeout time.Duration
// Client overrides the HTTP client (nil = Timeout applied).
Client *http.Client
}
OpenAIConfig configures an OpenAI-compatible /embeddings endpoint (OpenRouter, Ollama's OpenAI layer, vLLM, ...).
type Provider ¶
type Provider interface {
Embed(ctx context.Context, texts []string, kind Kind) ([][]float32, error)
Dim() int
// Name identifies the provider and model; the service records it with
// every bundle it indexes.
Name() string
}
Provider embeds texts into vectors of Dim dimensions. Embeddings of the same text with the same provider are stable; switching provider or model means re-indexing, because vectors of different models are not comparable.