pub struct LazyFastembedProvider { /* private fields */ }Expand description
Lazy-loading embedding provider backed by FastembedProvider.
The constructor is instant — it sets initial state to Cached if
model weights already exist on disk, or NotLoaded otherwise. The
first call to embed triggers model
download and ONNX session initialisation.
Thread-safe: concurrent callers block on a Condvar with a
configurable timeout. After an idle period, the ONNX session is
dropped to release memory while keeping weights on disk for fast
reload.
Implementations§
Source§impl LazyFastembedProvider
impl LazyFastembedProvider
Sourcepub fn new(model: EmbeddingModel, cache_dir: PathBuf, opts: LazyOpts) -> Self
pub fn new(model: EmbeddingModel, cache_dir: PathBuf, opts: LazyOpts) -> Self
Create a new lazy provider.
Returns instantly — no model download or ONNX initialisation.
Sourcepub fn new_with_loader(
model: EmbeddingModel,
cache_dir: PathBuf,
opts: LazyOpts,
load_fn: Arc<dyn Fn(EmbeddingModel, PathBuf) -> Result<FastembedProvider> + Send + Sync>,
) -> Self
pub fn new_with_loader( model: EmbeddingModel, cache_dir: PathBuf, opts: LazyOpts, load_fn: Arc<dyn Fn(EmbeddingModel, PathBuf) -> Result<FastembedProvider> + Send + Sync>, ) -> Self
Create a lazy provider with an injected model loader.
Production callers should use new; this constructor exists
so tests can drive the panic/failure paths of ensure_model
deterministically without real ONNX weights.
Sourcepub fn state(&self) -> ModelState
pub fn state(&self) -> ModelState
Current model lifecycle state.
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Whether the model is loaded and ready for inference.
Cheaper than state for hot-path polling — avoids
cloning the Failed { message, .. } variant’s string.
Sourcepub fn reset(&self)
pub fn reset(&self)
Clear a Failed state so the next ensure_model
call retries the load, instead of returning the cached error forever.
No-op if the provider isn’t currently Failed. Resets to Cached if
weights are already on disk, NotLoaded otherwise — mirroring the
initial-state logic in new_with_loader.
Callers should check ModelState::is_panic before calling this:
retrying after a panic-origin failure re-enters the same loader (and
thus the same ort/ONNX init path) that just panicked, which may hit
corrupted process-global state rather than a fresh, safe retry.
Sourcepub fn ensure_model(&self) -> Result<(), String>
pub fn ensure_model(&self) -> Result<(), String>
Block until the model is ready for inference.
If the model is idle beyond the configured timeout, the ONNX session
is evicted and reloaded from the on-disk cache. If the model is not
yet loaded, this triggers download and initialisation on the calling
thread. Concurrent callers wait on a Condvar for up to
load_timeout_secs.
Trait Implementations§
Source§impl EmbeddingProvider for LazyFastembedProvider
impl EmbeddingProvider for LazyFastembedProvider
Source§fn embed_batch(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>>
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>>
Auto Trait Implementations§
impl !Freeze for LazyFastembedProvider
impl RefUnwindSafe for LazyFastembedProvider
impl Send for LazyFastembedProvider
impl Sync for LazyFastembedProvider
impl Unpin for LazyFastembedProvider
impl UnsafeUnpin for LazyFastembedProvider
impl UnwindSafe for LazyFastembedProvider
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.