Documentation
¶
Overview ¶
Package embed: auto.go implements an embedder that transparently falls back to the built-in lexical provider when the configured remote (Ollama / OpenAI-compatible) is unreachable. This is what makes forgetmenot work in every agent environment out of the box: no Ollama running, no API key, no PATH tricks - remember/recall still function.
Package embed provides embedding providers: a local Ollama embedder and an OpenAI-compatible remote embedder used as a fallback. The MCP server picks one via flags/env (default: Ollama at http://localhost:11434).
Package embed: lexical.go implements a deterministic, dependency-free embedding provider. It powers the offline fallback so remember/recall keep working when no Ollama or OpenAI-compatible endpoint is reachable: every agent environment (Claude Code, Cursor, opencode, ...) gets working memory with zero configuration.
Index ¶
Constants ¶
const DefaultLexicalDim = 768
DefaultLexicalDim matches the most common local model (nomic-embed-text, 768 dims). The exact value does not matter for correctness: recall heals dimension mismatches by re-embedding, and provenance in memory metadata separates lexical from semantic vectors even at equal dimensions.
Variables ¶
var Client = &http.Client{Timeout: 60 * time.Second}
Client is the shared HTTP client for all providers.
Functions ¶
This section is empty.
Types ¶
type AutoEmbedder ¶ added in v0.4.0
type AutoEmbedder struct {
// contains filtered or unexported fields
}
AutoEmbedder tries a primary provider and degrades to a fallback when the primary fails. After a failure it stops hammering the dead endpoint: it serves fallback vectors for cooldown, then probes the primary once (with a short timeout) and switches back the moment it answers.
func NewAuto ¶ added in v0.4.0
func NewAuto(primary, fallback embedder) *AutoEmbedder
NewAuto returns an AutoEmbedder with a 30s cooldown and 3s probe timeout.
func (*AutoEmbedder) Embed ¶ added in v0.4.0
Embed returns primary vectors while the primary is healthy; otherwise it returns fallback vectors.
func (*AutoEmbedder) IsLexical ¶ added in v0.4.0
func (a *AutoEmbedder) IsLexical() bool
IsLexical reports whether the active provider is the lexical fallback. The memory service uses this to calibrate recall/dedupe/conflict thresholds.
type LexicalEmbedder ¶ added in v0.4.0
type LexicalEmbedder struct {
// contains filtered or unexported fields
}
LexicalEmbedder hashes word unigrams and bigrams into a fixed-size vector. It is deterministic across runs and machines (no randomness), so memories written offline stay comparable later.
func NewLexical ¶ added in v0.4.0
func NewLexical(dim ...int) *LexicalEmbedder
NewLexical returns a LexicalEmbedder. An optional positive dimension overrides DefaultLexicalDim.
func (*LexicalEmbedder) IsLexical ¶ added in v0.4.0
func (l *LexicalEmbedder) IsLexical() bool
IsLexical marks this provider so the memory service calibrates its thresholds (recall floor, dedupe, conflict) to lexical similarity values.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
BaseURL string // e.g. http://localhost:11434
Model string // e.g. nomic-embed-text
}
OllamaEmbedder calls the local Ollama /api/embed endpoint.
func NewOllama ¶
func NewOllama(baseURL, model string) *OllamaEmbedder
NewOllama returns an OllamaEmbedder with defaults.
type OpenAICompatEmbedder ¶
type OpenAICompatEmbedder struct {
BaseURL string // e.g. https://api.openai.com/v1
APIKey string
Model string
}
OpenAICompatEmbedder calls any OpenAI-compatible /v1/embeddings endpoint.
func NewOpenAICompat ¶
func NewOpenAICompat(baseURL, apiKey, model string) *OpenAICompatEmbedder
NewOpenAICompat returns an OpenAICompatEmbedder with defaults.