pub enum BenchEmbedder {
BagOfTokens(ToyEmbedder),
OnnxMiniLm {
inner: Box<dyn Embedder>,
model_id: String,
dim: u32,
},
}Expand description
Unified embedder used by crate::adapters::MnemAdapter.
The two flavours share a method surface (model(), dim(),
embed_text()) so the adapter does not branch on the variant on
every call. Construction is the only code path that picks one.
§Variants
BenchEmbedder::BagOfTokens- the always-compiled toy embedder. Selected bycrate::EmbedderChoice::BagOfTokens.BenchEmbedder::OnnxMiniLm- real MiniLM-L6-v2 viamnem-embed-providers(gated on theonnx-minilmfeature). Selected bycrate::EmbedderChoice::OnnxMiniLm.
Variants§
BagOfTokens(ToyEmbedder)
Toy hashed bag-of-tokens. Network-free, ~0.2 recall@5 on LongMemEval; ships as the offline / WASM-clean fallback.
OnnxMiniLm
Real all-MiniLM-L6-v2 via mnem-embed-providers. The
concrete type is hidden behind a Box<dyn Embedder> so this
crate stays agnostic to the underlying ORT session lifetime.
model_id and dim are cached so the hot path (per-doc
ingest, per-query retrieve) avoids vtable round-trips.
Implementations§
Source§impl BenchEmbedder
impl BenchEmbedder
Sourcepub fn bag_of_tokens(dim: u32) -> Self
pub fn bag_of_tokens(dim: u32) -> Self
Construct the toy hashed bag-of-tokens embedder of dimension
dim. Matches 0.1.0 behaviour.
Sourcepub fn onnx_minilm() -> Result<Self, Box<dyn Error>>
pub fn onnx_minilm() -> Result<Self, Box<dyn Error>>
Construct the real ONNX MiniLM-L6-v2 embedder via
mnem-embed-providers (onnx-bundled flavour). Lazy-
downloads the model on first call (ORT + tokenizer + weights
fetched into the HuggingFace cache; ~90MB).
§Errors
Surfaces tokenizer / model-load / ORT-session failures from
mnem-embed-providers verbatim as a Box<dyn Error>.
Sourcepub fn model(&self) -> &str
pub fn model(&self) -> &str
Fully-qualified model identifier. Stamped on every
Embedding and used as the key the retriever’s vector lane
resolves on, so two embedders with the same model() MUST
produce vectors in the same semantic space.
Sourcepub fn embed_text(&self, text: &str) -> Result<Vec<f32>, Box<dyn Error>>
pub fn embed_text(&self, text: &str) -> Result<Vec<f32>, Box<dyn Error>>
Embed a single string. Errors from the ONNX path (tokenizer,
session.run) are surfaced as Box<dyn Error>. The toy path
is infallible, so Result here is a small ergonomic tax we
pay so the call site stays variant-blind.
§Errors
Returns the underlying provider error verbatim for the ONNX flavour. The bag-of-tokens flavour cannot fail.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BenchEmbedder
impl !RefUnwindSafe for BenchEmbedder
impl Send for BenchEmbedder
impl Sync for BenchEmbedder
impl Unpin for BenchEmbedder
impl UnsafeUnpin for BenchEmbedder
impl !UnwindSafe for BenchEmbedder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more