pub struct MeteredEmbedder<E>where
E: Embedder,{ /* private fields */ }Expand description
Embedder decorator that emits OTel-compatible telemetry per
call (and optional cost via EmbeddingCostCalculator).
Wraps any inner E: Embedder and itself implements Embedder,
so the wrapper drops in transparently anywhere the bare type
was used.
Implementations§
Source§impl<E> MeteredEmbedder<E>where
E: Embedder,
impl<E> MeteredEmbedder<E>where
E: Embedder,
Sourcepub fn new(inner: E, model: impl Into<Arc<str>>) -> Self
pub fn new(inner: E, model: impl Into<Arc<str>>) -> Self
Wrap inner with a metered surface. model is the wire-name
the operator wants surfaced in telemetry (gen_ai.embedding.model)
and used as the lookup key in the cost calculator’s pricing
table.
Sourcepub fn from_arc(inner: Arc<E>, model: impl Into<Arc<str>>) -> Self
pub fn from_arc(inner: Arc<E>, model: impl Into<Arc<str>>) -> Self
Variant for callers that already hold an Arc<E> (typical
when the embedder is shared across multiple memory backends).
Sourcepub fn with_cost_calculator(
self,
calculator: Arc<dyn EmbeddingCostCalculator>,
) -> Self
pub fn with_cost_calculator( self, calculator: Arc<dyn EmbeddingCostCalculator>, ) -> Self
Attach an EmbeddingCostCalculator. When set, the wrapper
emits gen_ai.embedding.cost on the success branch of every
embed / embed_batch call whose (tenant, model) resolves to
a pricing row.
Trait Implementations§
Source§impl<E> Embedder for MeteredEmbedder<E>where
E: Embedder,
impl<E> Embedder for MeteredEmbedder<E>where
E: Embedder,
Source§fn dimension(&self) -> usize
fn dimension(&self) -> usize
Output vector dimension. Used by
VectorStore impls to validate
inserts against the configured index dimension.Source§fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
text: &'life1 str,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Embedding>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
text: &'life1 str,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Embedding>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed one input string. Returns the vector plus optional
usage metadata so downstream cost meters can charge the
call without a second round-trip.
Source§fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Batch embed. Default impl runs sequentially via
embed,
polling ExecutionContext::is_cancelled between iterations
so a long batch bails out within one embed round-trip of
cancellation rather than draining the full pool.
Implementations that support a true batch endpoint
should override — sequential calls amplify network
latency by N.Auto Trait Implementations§
impl<E> Freeze for MeteredEmbedder<E>
impl<E> !RefUnwindSafe for MeteredEmbedder<E>
impl<E> Send for MeteredEmbedder<E>
impl<E> Sync for MeteredEmbedder<E>
impl<E> Unpin for MeteredEmbedder<E>
impl<E> UnsafeUnpin for MeteredEmbedder<E>
impl<E> !UnwindSafe for MeteredEmbedder<E>
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