Documentation
¶
Overview ¶
Package embed turns text into dense vectors via an external, OpenAI-compatible embeddings endpoint; memini never embeds locally.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDisabled = errors.New("embeddings endpoint not configured (set MEMINI_EMBED_BASE_URL)")
ErrDisabled is returned when memory operations need embeddings but no embeddings endpoint is configured.
Functions ¶
Types ¶
type Batched ¶
type Batched struct {
// contains filtered or unexported fields
}
Batched splits an Embed call into sub-requests bounded by item count and character budget to keep payloads under endpoint limits, truncating over-long texts.
func NewBatched ¶
NewBatched wraps inner. maxItems caps items per request; maxChars caps total characters per request; maxItemChars truncates any single text (0 disables).
type Cached ¶
type Cached struct {
// contains filtered or unexported fields
}
Cached wraps an Embedder with a content-hash LRU cache so identical text is embedded only once. Safe for concurrent use.
type Disabled ¶
type Disabled struct{ D int }
Disabled is an Embedder used when no endpoint is configured: the server boots but remember/recall fail with ErrDisabled.
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache wraps an Embedder with a persistent content-hashed cache, so identical text is embedded once across process runs. Safe for concurrent use.
func NewDiskCache ¶
NewDiskCache wraps inner, loading any existing cache at path.
type Embedder ¶
type Embedder interface {
// Embed returns one vector per input text, in the same order.
Embed(ctx context.Context, texts []string) ([][]float32, error)
// Dims is the dimensionality of returned vectors.
Dims() int
}
Embedder converts text into fixed-dimension vectors.
type Metrics ¶
type Metrics interface {
// Observe records one Embed call: backend labels the layer that produced
// the result ("openai", "cached", "diskcache", "batched", "disabled"),
// items is the number of input texts, tokens is the API-reported token
// usage (0 for cache hits and the disabled backend), and d is the wall
// duration.
Observe(backend string, items int, tokens int, d time.Duration)
// Error records a failed Embed call on the given backend.
Error(backend string)
}
Metrics receives embedder events for observability. Methods must be safe for concurrent use; a nil Metrics is replaced by a no-op.
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient calls an OpenAI-compatible /embeddings endpoint.
func NewOpenAI ¶
func NewOpenAI(cfg OpenAIConfig) (*OpenAIClient, error)
NewOpenAI builds an embeddings client. BaseURL and Model are required.
func (*OpenAIClient) Dims ¶
func (c *OpenAIClient) Dims() int
Dims returns the configured embedding dimensionality.
func (*OpenAIClient) SetMetrics ¶
func (c *OpenAIClient) SetMetrics(m Metrics)
SetMetrics installs an observability sink on this client. Reports real token usage from the API's Usage block. A nil m disables instrumentation.
type OpenAIConfig ¶
type OpenAIConfig struct {
BaseURL string // e.g. http://localhost:8081/v1
APIKey string // optional bearer token
Model string
Dims int
// HTTPClient is optional; the SDK default is used when nil.
HTTPClient *http.Client
}
OpenAIConfig configures the OpenAI-compatible embeddings client.