pub struct EmbedderService<M> { /* private fields */ }Expand description
Background batching service for semantic embedding requests.
BatchItem values preserve their embedding role and optional title
metadata. Dropping the returned result receiver cancels background
processing.
Implementations§
Source§impl<M: Send + 'static> EmbedderService<M>
impl<M: Send + 'static> EmbedderService<M>
Sourcepub fn new(
embedder: Arc<dyn EmbeddingProvider>,
max_tokens: NonZeroUsize,
max_batch_size: NonZeroUsize,
workers: NonZeroUsize,
) -> Result<(Self, Receiver<Result<EmbeddingResult<M>>>)>
pub fn new( embedder: Arc<dyn EmbeddingProvider>, max_tokens: NonZeroUsize, max_batch_size: NonZeroUsize, workers: NonZeroUsize, ) -> Result<(Self, Receiver<Result<EmbeddingResult<M>>>)>
Creates a new embedding service and result stream.
§Errors
Returns an error if no Tokio runtime is active.
This constructor spawns background tasks immediately.
Sourcepub async fn enqueue(&mut self, item: BatchItem<M>) -> Result<bool>
pub async fn enqueue(&mut self, item: BatchItem<M>) -> Result<bool>
Adds one item into the service and flushes a batch if needed.
§Errors
Returns Error::BatchChannelClosed after Self::flush has closed the service.
Returns Error::BatchItemTooLarge when one item exceeds the configured
hard token limit.
Sourcepub async fn flush(&mut self) -> Result<bool>
pub async fn flush(&mut self) -> Result<bool>
Flushes pending batched items and closes the batch input channel.
After this returns successfully, subsequent Self::enqueue calls return
Error::BatchChannelClosed.
Auto Trait Implementations§
impl<M> Freeze for EmbedderService<M>
impl<M> !RefUnwindSafe for EmbedderService<M>
impl<M> Send for EmbedderService<M>where
M: Send,
impl<M> !Sync for EmbedderService<M>
impl<M> Unpin for EmbedderService<M>where
M: Unpin,
impl<M> UnsafeUnpin for EmbedderService<M>
impl<M> !UnwindSafe for EmbedderService<M>
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
Mutably borrows from an owned value. Read more
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>
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 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>
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