pub struct AiBatchClient<S = AiTransportSender> { /* private fields */ }Expand description
Batch embedding client.
Generic over the backend so tests can inject mocks without HTTP.
The default type parameter is AiTransportSender (production).
Implementations§
Source§impl AiBatchClient<AiTransportSender>
impl AiBatchClient<AiTransportSender>
pub fn new(transport: AiTransport) -> Self
pub fn from_runtime(runtime: &RedDBRuntime) -> Self
Source§impl<S: SubBatchSender> AiBatchClient<S>
impl<S: SubBatchSender> AiBatchClient<S>
Sourcepub fn with_sender(sender: S) -> Self
pub fn with_sender(sender: S) -> Self
Create with a custom backend (useful in tests).
Sourcepub fn with_max_batch_size(self, size: usize) -> Self
pub fn with_max_batch_size(self, size: usize) -> Self
Override the max sub-batch size (defaults per provider if not set).
Sourcepub fn with_dedup_cache(self, cache: Arc<EmbeddingDedupCache>) -> Self
pub fn with_dedup_cache(self, cache: Arc<EmbeddingDedupCache>) -> Self
Enable dedup cache.
Sourcepub fn with_chunk_mode(self, mode: ChunkMode) -> Self
pub fn with_chunk_mode(self, mode: ChunkMode) -> Self
Set chunk mode (Single or Multi).
Sourcepub fn with_max_tokens(self, max: usize) -> Self
pub fn with_max_tokens(self, max: usize) -> Self
Set max tokens per chunk.
pub fn with_audit_log(self, audit_log: Arc<AuditLogger>) -> Self
Sourcepub async fn embed_batch(
&self,
provider: &AiProvider,
model: &str,
api_key: &str,
texts: Vec<String>,
) -> Result<Vec<Vec<f32>>, AiTransportError>
pub async fn embed_batch( &self, provider: &AiProvider, model: &str, api_key: &str, texts: Vec<String>, ) -> Result<Vec<Vec<f32>>, AiTransportError>
Embed texts in batch. Returns one Vec<f32> per input in order.
Empty/whitespace-only inputs yield an empty Vec<f32> at their position
without consuming a provider request slot.
When dedup is enabled, previously-seen texts are served from cache and only unseen texts are sent to the provider. Duplicate texts within a single call are also deduplicated — the provider receives each unique text only once.
When chunking is enabled, texts exceeding max_tokens are chunked;
in Single mode the first chunk is sent to the provider.
Auto Trait Implementations§
impl<S> Freeze for AiBatchClient<S>where
S: Freeze,
impl<S = AiTransportSender> !RefUnwindSafe for AiBatchClient<S>
impl<S> Send for AiBatchClient<S>where
S: Send,
impl<S> Sync for AiBatchClient<S>where
S: Sync,
impl<S> Unpin for AiBatchClient<S>where
S: Unpin,
impl<S> UnsafeUnpin for AiBatchClient<S>where
S: UnsafeUnpin,
impl<S = AiTransportSender> !UnwindSafe for AiBatchClient<S>
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> 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::Request