pub struct Embedder { /* private fields */ }Expand description
Loads sentence-transformers/all-MiniLM-L6-v2 once and computes
normalized sentence embeddings from it.
Construction fetches the model’s config.json, tokenizer.json, and
model.safetensors from the Hugging Face Hub on first use (cached under
the platform cache directory afterward), and loads them into a CPU-only
candle BERT model. Reuse one Embedder across calls to Self::embed
rather than reloading the model per call.
Implementations§
Source§impl Embedder
impl Embedder
Sourcepub fn load() -> Result<Self, EmbedError>
pub fn load() -> Result<Self, EmbedError>
Fetches (or loads from cache) and initializes the embedding model.
§Errors
Returns EmbedError if the platform cache directory cannot be
resolved, the model files cannot be fetched from the Hugging Face Hub,
or the fetched files cannot be parsed/loaded as a BERT model.
Sourcepub fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedError>
pub fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedError>
Computes a 384-dimensional, mean-pooled, L2-normalized sentence
embedding for text.
§Errors
Returns EmbedError if tokenization or model inference fails.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Embedder
impl !RefUnwindSafe for Embedder
impl !UnwindSafe for Embedder
impl Send for Embedder
impl Sync for Embedder
impl Unpin for Embedder
impl UnsafeUnpin for Embedder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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