Documentation
¶
Overview ¶
Package embed turns text into vectors for retrieval and memory. The Embedder interface keeps the rest of the system independent of the embedding model. Two implementations ship: a deterministic, offline HashEmbedder (default — zero deps, always works, used for tests and air-gapped first-run) and an Ollama embedder (higher quality when a local embedding model is available).
Whichever produces a pack's vectors is pinned by ID in the pack manifest, so a pack can never be queried with a mismatched embedder.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Embedder ¶
type Embedder interface {
// ID is the stable identifier recorded in manifests, e.g. "hash-v1:256" or
// "ollama:nomic-embed-text".
ID() string
// Dim is the output dimensionality.
Dim() int
// Embed returns the vector for a single text.
Embed(ctx context.Context, text string) (vector.Vector, error)
// EmbedBatch embeds many texts (default impl loops; adapters may optimize).
EmbedBatch(ctx context.Context, texts []string) ([]vector.Vector, error)
}
Embedder converts text to vectors. ID must uniquely identify the model+config so packs/memories can be pinned to it.
type HashEmbedder ¶
type HashEmbedder struct {
// contains filtered or unexported fields
}
HashEmbedder is a deterministic, dependency-free embedder using the feature- hashing ("hashing trick") technique over word unigrams and bigrams. It needs no model file and works fully offline — ideal as the always-available default and for reproducible tests.
Honest limitation: hashed bag-of-words captures lexical overlap, not deep semantics. It pairs well with the keyword arm of hybrid retrieval (which carries the literal CLI tokens). For stronger semantic recall, use the Ollama embedder (nomic-embed-text) or a future bge-small ONNX embedder behind this same iface.
func NewHashEmbedder ¶
func NewHashEmbedder(dim int) *HashEmbedder
NewHashEmbedder builds a HashEmbedder with the given dimensionality (e.g. 256).
func (*HashEmbedder) EmbedBatch ¶
EmbedBatch implements Embedder.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
Endpoint string
Model string
// contains filtered or unexported fields
}
OllamaEmbedder produces embeddings via a local Ollama server's /api/embeddings endpoint (e.g. the nomic-embed-text model). Higher semantic quality than the hash embedder, still fully local. Dim is discovered from the first response.
func NewOllamaEmbedder ¶
func NewOllamaEmbedder(endpoint, model string) *OllamaEmbedder
NewOllamaEmbedder builds an Ollama-backed embedder. Empty endpoint defaults to loopback; empty model defaults to nomic-embed-text.
func (*OllamaEmbedder) Dim ¶
func (o *OllamaEmbedder) Dim() int
Dim implements Embedder (0 until the first successful Embed).
func (*OllamaEmbedder) EmbedBatch ¶
EmbedBatch implements Embedder.