pub struct EmbeddingMiddleware<P: EmbeddingProvider> { /* private fields */ }Expand description
Embedding generation middleware
This struct provides pre-processing and post-processing for embedding requests, such as:
- Text normalization
- Embedding caching
- Batch processing optimization
- Vector normalization
Implementations§
Source§impl<P: EmbeddingProvider> EmbeddingMiddleware<P>
impl<P: EmbeddingProvider> EmbeddingMiddleware<P>
Sourcepub fn new(provider: P, normalize_vectors: bool) -> Self
pub fn new(provider: P, normalize_vectors: bool) -> Self
Create a new embedding middleware instance
Sourcepub fn initialize_tokenizer() -> Result<()>
pub fn initialize_tokenizer() -> Result<()>
Initialize tokenizer
Sourcepub fn normalize_text(&self, text: &str) -> String
pub fn normalize_text(&self, text: &str) -> String
Normalize text content
Sourcepub fn normalize_vector(&self, vector: &mut [f32])
pub fn normalize_vector(&self, vector: &mut [f32])
Normalize vector to make it a unit vector
Trait Implementations§
Source§impl<P: EmbeddingProvider + Send + Sync> EmbeddingProvider for EmbeddingMiddleware<P>
impl<P: EmbeddingProvider + Send + Sync> EmbeddingProvider for EmbeddingMiddleware<P>
Source§fn generate_embedding<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate_embedding<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate embedding vector for a single text
Auto Trait Implementations§
impl<P> Freeze for EmbeddingMiddleware<P>where
P: Freeze,
impl<P> RefUnwindSafe for EmbeddingMiddleware<P>where
P: RefUnwindSafe,
impl<P> Send for EmbeddingMiddleware<P>
impl<P> Sync for EmbeddingMiddleware<P>
impl<P> Unpin for EmbeddingMiddleware<P>where
P: Unpin,
impl<P> UnwindSafe for EmbeddingMiddleware<P>where
P: UnwindSafe,
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