pub struct EmbeddingAggregator { /* private fields */ }Expand description
Stateful embedding aggregator that tracks total aggregation operations.
Implementations§
Source§impl EmbeddingAggregator
impl EmbeddingAggregator
Sourcepub fn new(config: AggregatorConfig) -> Self
pub fn new(config: AggregatorConfig) -> Self
Create a new aggregator with the given configuration.
Sourcepub fn aggregate(&mut self, tokens: &[Vec<f32>]) -> Option<AggregatedEmbedding>
pub fn aggregate(&mut self, tokens: &[Vec<f32>]) -> Option<AggregatedEmbedding>
Aggregate a sequence of token embeddings using the default strategy.
Each inner Vec<f32> is a single token’s embedding.
All token embeddings must have the same dimensionality.
Sourcepub fn aggregate_with(
&mut self,
tokens: &[Vec<f32>],
strategy: PoolingStrategy,
attention_weights: Option<&[f32]>,
) -> Option<AggregatedEmbedding>
pub fn aggregate_with( &mut self, tokens: &[Vec<f32>], strategy: PoolingStrategy, attention_weights: Option<&[f32]>, ) -> Option<AggregatedEmbedding>
Aggregate using a specific strategy.
attention_weights is required when strategy == AttentionWeighted and
is ignored for other strategies.
Sourcepub fn aggregate_batch(&mut self, batch: &[Vec<Vec<f32>>]) -> BatchResult
pub fn aggregate_batch(&mut self, batch: &[Vec<Vec<f32>>]) -> BatchResult
Aggregate a batch of token sequences using the default strategy.
Sourcepub fn aggregate_batch_with(
&mut self,
batch: &[Vec<Vec<f32>>],
strategy: PoolingStrategy,
) -> BatchResult
pub fn aggregate_batch_with( &mut self, batch: &[Vec<Vec<f32>>], strategy: PoolingStrategy, ) -> BatchResult
Aggregate a batch with a specific strategy.
Sourcepub fn hierarchical_aggregate(
&mut self,
sentences: &[Vec<Vec<f32>>],
paragraph_boundaries: &[usize],
) -> Option<HierarchicalResult>
pub fn hierarchical_aggregate( &mut self, sentences: &[Vec<Vec<f32>>], paragraph_boundaries: &[usize], ) -> Option<HierarchicalResult>
Perform hierarchical aggregation: sentence -> paragraph -> document.
sentences– each entry is a sequence of token embeddings forming one sentence.paragraph_boundaries– indices intosentenceswhere a new paragraph starts (e.g.[0, 3, 7]means sentences 0..3 form paragraph 0, 3..7 form paragraph 1, etc.).
Uses mean pooling at every level.
Sourcepub fn compare_strategies(
&mut self,
tokens: &[Vec<f32>],
strategy_a: PoolingStrategy,
strategy_b: PoolingStrategy,
) -> (Option<AggregatedEmbedding>, Option<AggregatedEmbedding>)
pub fn compare_strategies( &mut self, tokens: &[Vec<f32>], strategy_a: PoolingStrategy, strategy_b: PoolingStrategy, ) -> (Option<AggregatedEmbedding>, Option<AggregatedEmbedding>)
Compare two pooling strategies on the same tokens and return both results.
Sourcepub fn total_aggregations(&self) -> u64
pub fn total_aggregations(&self) -> u64
Return the total number of individual aggregation operations performed.
Sourcepub fn config(&self) -> &AggregatorConfig
pub fn config(&self) -> &AggregatorConfig
Return the current configuration.
Sourcepub fn strategy_summary(
results: &[AggregatedEmbedding],
) -> HashMap<PoolingStrategy, usize>
pub fn strategy_summary( results: &[AggregatedEmbedding], ) -> HashMap<PoolingStrategy, usize>
Build a summary of aggregation results per strategy from provided labels.
Auto Trait Implementations§
impl Freeze for EmbeddingAggregator
impl RefUnwindSafe for EmbeddingAggregator
impl Send for EmbeddingAggregator
impl Sync for EmbeddingAggregator
impl Unpin for EmbeddingAggregator
impl UnsafeUnpin for EmbeddingAggregator
impl UnwindSafe for EmbeddingAggregator
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt 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.