pub struct EmbedModel { /* private fields */ }Expand description
A local embedding model backed by fastembed (ONNX Runtime).
Constructed via FastEmbedModel::from_options. The underlying
fastembed::TextEmbedding is synchronous, so all calls to
FastEmbedModel::embed are dispatched onto Tokio’s blocking thread pool
via tokio::task::spawn_blocking.
Implementations§
Source§impl FastEmbedModel
impl FastEmbedModel
Sourcepub fn from_options(
opts: FastEmbedOptions,
) -> Result<FastEmbedModel, FastEmbedError>
pub fn from_options( opts: FastEmbedOptions, ) -> Result<FastEmbedModel, FastEmbedError>
Construct a new FastEmbedModel from the given options.
This is a blocking operation that may download model weights from
HuggingFace on first use. Call from a context where blocking is
acceptable (e.g. application startup), or wrap in
tokio::task::spawn_blocking.
§Errors
Returns FastEmbedError if the fastembed model fails to initialise
(e.g. unknown model name, network error during download).
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Embedding vector dimensionality for this model.
Sourcepub async fn embed(
&self,
texts: &[String],
) -> Result<FastEmbedResponse, FastEmbedError>
pub async fn embed( &self, texts: &[String], ) -> Result<FastEmbedResponse, FastEmbedError>
Embed one or more texts, returning one vector per input text.
The fastembed crate’s embed method is synchronous – this function
dispatches the work onto Tokio’s blocking thread pool via
tokio::task::spawn_blocking to avoid starving the async runtime.
§Errors
Returns FastEmbedError if the underlying fastembed call fails or
the blocking task panics.
Auto Trait Implementations§
impl Freeze for FastEmbedModel
impl RefUnwindSafe for FastEmbedModel
impl Send for FastEmbedModel
impl Sync for FastEmbedModel
impl Unpin for FastEmbedModel
impl UnsafeUnpin for FastEmbedModel
impl UnwindSafe for FastEmbedModel
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> 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