Skip to main content

Module embedder

Module embedder 

Source
Expand description

Embedder — local text-to-vector using fastembed-rs.

§Model

Uses all-MiniLM-L6-v2 (384 dimensions), the same model ChromaDB defaults to, so embeddings produced here are semantically comparable to an existing ChromaDB setup.

The ONNX model (~23 MB) is downloaded from HuggingFace Hub on first call and cached at ~/.cache/huggingface/hub/. Subsequent calls are instant.

§Threading

Embedder is Clone + Send + Sync. The inner ONNX session is wrapped in Arc<Mutex<...>> so multiple tasks can share one instance without contention — embed calls are batched internally by fastembed.

§Example

use aimem_core::Embedder;

let embedder = Embedder::new()?;

// Batch embedding (preferred — amortizes ONNX overhead)
let vecs = embedder.embed(&["hello world", "turso vector search"])?;
assert_eq!(vecs[0].len(), 384); // all-MiniLM-L6-v2 dim

// Single embedding
let v = embedder.embed_one("semantic memory")?;
assert_eq!(v.len(), 384);

// Serialize to Turso vector32 JSON for SQL params
let json = Embedder::to_vector32_json(&v);
assert!(json.starts_with('['));

Structs§

Embedder
Thread-safe wrapper around a fastembed TextEmbedding instance.

Enums§

EmbedError

Constants§

EMBED_DIM
Dimension of the default embedding model (all-MiniLM-L6-v2).