pub trait Embedder: Send + Sync {
// Required methods
fn identity(&self) -> EmbedderIdentity;
fn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>;
// Provided methods
fn embed_query(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>> { ... }
fn query_keywords(&self, text: &str) -> Option<String> { ... }
}Expand description
Minimal trait any embedder implementation must satisfy. Returns
vectors in the same order as the input texts.
Implementations are expected to be cheap to clone / Send + Sync
when they wrap thread-safe state; the engine holds an Arc<dyn Embedder> on the handle via [Mnemo::set_embedder]. See
[Mnemo::remember_text] for the full user-facing contract.
Required Methods§
Sourcefn identity(&self) -> EmbedderIdentity
fn identity(&self) -> EmbedderIdentity
This embedder’s observable identity (name, dims, normalize).
Must be stable for the lifetime of the embedder — mnemo caches
it on set_embedder and does not re-query per call.
Sourcefn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
fn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
Embed texts, returning one vector per input in the same order.
Caller-level errors (network failure for a hosted embedder, OOM
in a local model) should bubble up as MnemoError::Invalid
with a short message — the specific crypto / page errors in
MnemoError are reserved for the engine’s own concerns.
This is the document side: everything stored is embedded with it.
Provided Methods§
Sourcefn embed_query(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
fn embed_query(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
12.3 step 4 (v0.15): embed texts as queries. Every recall by
text uses it (crate::RecallRequest::from_text, the CLI’s
recall --text, the MCP recall tool, Python’s recall_text). It
defaults to Embedder::embed. A model that embeds queries
differently (an instruction prefix, a separate query encoder)
overrides it and names the difference in
EmbedderIdentity::query_convention.
Sourcefn query_keywords(&self, text: &str) -> Option<String>
fn query_keywords(&self, text: &str) -> Option<String>
12.3 step 5 (v0.15): the keywords a recall by text scores with BM25
in place of its text, when the caller gave none. None (the
default) scores the text itself, at
crate::RecallRequest::text_keyword_weight. Some(k) scores k
as explicit keywords, at crate::RecallRequest::keyword_weight;
Some("") makes the recall vector-only.
The handle’s registered embedder (crate::Mnemo::set_embedder) is
asked on every recall that has a text and no keywords, on a v9 file.
Keywords the caller gives always win. The built-in embedder answers
with the identifiers in the question (identifier-aware recall; see
mnemo_engine::builtin).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<E: Embedder + ?Sized> Embedder for Arc<E>
A shared embedder is an embedder, so one loaded model can serve several
handles.
impl<E: Embedder + ?Sized> Embedder for Arc<E>
A shared embedder is an embedder, so one loaded model can serve several handles.
Source§impl<E: Embedder + ?Sized> Embedder for Box<E>
A boxed embedder is an embedder, so a caller can choose one at run time
(the CLI’s --embed-cmd or the built-in) and register it.
impl<E: Embedder + ?Sized> Embedder for Box<E>
A boxed embedder is an embedder, so a caller can choose one at run time
(the CLI’s --embed-cmd or the built-in) and register it.