Skip to main content

BenchEmbedder

Enum BenchEmbedder 

Source
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

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.

Fields

§inner: Box<dyn Embedder>

Boxed provider implementing mnem_embed_providers::Embedder.

§model_id: String

Cached fully-qualified model id (e.g. "onnx:all-MiniLM-L6-v2"). Identifies the vector lane keyed on the mnem retriever.

§dim: u32

Cached output dimension (384 for MiniLM-L6-v2).

Implementations§

Source§

impl BenchEmbedder

Source

pub fn bag_of_tokens(dim: u32) -> Self

Construct the toy hashed bag-of-tokens embedder of dimension dim. Matches 0.1.0 behaviour.

Source

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>.

Source

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.

Source

pub fn dim(&self) -> u32

Output vector dimension.

Source

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§

Source§

impl Debug for BenchEmbedder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more