Skip to main content

Module embed

Module embed 

Source
Expand description

Pluggable text embedding — so similarity can be semantic, not just lexical.

Local-first: the default real implementation talks to Ollama on localhost (e.g. nomic-embed-text), which is part of the user’s machine — no external API. When no embedder is configured (or it fails), the scorer falls back to lexical term overlap, so retrieval always works offline.

Structs§

OllamaEmbedder
Local-first embedder backed by Ollama’s /api/embeddings. Run e.g. ollama pull nomic-embed-text first.

Traits§

Embedder
Anything that can turn text into a vector.

Functions§

bytes_to_vec
Decode little-endian f32 bytes back into an embedding. Returns an empty vec if the byte length isn’t a multiple of 4 (corrupt/foreign blob).
cosine
Cosine similarity in [0,1] (negatives clamped to 0 — we only care about “how related,” not “how opposite”).
vec_to_bytes
Encode an embedding as little-endian f32 bytes (for caching as a SQLite BLOB).