pub struct EmbeddingAggregator {
pub config: EmbeddingAggregatorConfig,
pub method: AggregationMethod,
pub history: VecDeque<AggregationResult>,
pub max_history: usize,
}Expand description
Aggregates multiple embedding vectors into a single representation.
Maintains a rolling history of the most recent aggregation results for monitoring and introspection.
Fields§
§config: EmbeddingAggregatorConfigConfiguration flags.
method: AggregationMethodThe pooling method.
history: VecDeque<AggregationResult>Rolling history of past results.
max_history: usizeMaximum number of entries kept in history.
Implementations§
Source§impl EmbeddingAggregator
impl EmbeddingAggregator
Sourcepub fn new(method: AggregationMethod, config: EmbeddingAggregatorConfig) -> Self
pub fn new(method: AggregationMethod, config: EmbeddingAggregatorConfig) -> Self
Create a new EmbeddingAggregator with the given method and config.
The history capacity defaults to 1 000 entries.
Sourcepub fn with_history_capacity(
method: AggregationMethod,
config: EmbeddingAggregatorConfig,
max_history: usize,
) -> Self
pub fn with_history_capacity( method: AggregationMethod, config: EmbeddingAggregatorConfig, max_history: usize, ) -> Self
Create a new aggregator with an explicit history capacity.
Sourcepub fn aggregate(
&mut self,
inputs: &[AggregationInput],
) -> Result<AggregationResult, AggregatorError>
pub fn aggregate( &mut self, inputs: &[AggregationInput], ) -> Result<AggregationResult, AggregatorError>
Aggregate a slice of AggregationInput values using self.method.
All inputs must share the same dimensionality. Returns an
AggregationResult and records it in the history ring.
Sourcepub fn aggregate_raw(
&mut self,
embeddings: &[Vec<f64>],
) -> Result<AggregationResult, AggregatorError>
pub fn aggregate_raw( &mut self, embeddings: &[Vec<f64>], ) -> Result<AggregationResult, AggregatorError>
Convenience method that treats all embeddings with weight 1.0 and
applies self.method.
Sourcepub fn aggregate_with_input_weights(
&mut self,
inputs: &[AggregationInput],
) -> Result<AggregationResult, AggregatorError>
pub fn aggregate_with_input_weights( &mut self, inputs: &[AggregationInput], ) -> Result<AggregationResult, AggregatorError>
Aggregate using the weight field of each AggregationInput directly,
ignoring the method’s own weight vector. Useful when weights are
determined dynamically (e.g. relevance scores).
Sourcepub fn merge_results(
results: &[AggregationResult],
method: AggregationMethod,
) -> Result<AggregationResult, AggregatorError>
pub fn merge_results( results: &[AggregationResult], method: AggregationMethod, ) -> Result<AggregationResult, AggregatorError>
Aggregate the output vectors from several AggregationResults using
the provided method.
Sourcepub fn l2_normalize(v: &[f64]) -> Vec<f64>
pub fn l2_normalize(v: &[f64]) -> Vec<f64>
L2-normalise v in place. Returns v unchanged if its norm is ≈ 0.
Sourcepub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
Cosine similarity between two vectors.
Returns 0.0 if either vector is the zero vector.
Sourcepub fn attention_scores(query: &[f64], embeddings: &[Vec<f64>]) -> Vec<f64>
pub fn attention_scores(query: &[f64], embeddings: &[Vec<f64>]) -> Vec<f64>
Compute softmax attention scores: softmax(query · embedding[i] / sqrt(d)).
Sourcepub fn recent_history(&self, n: usize) -> Vec<&AggregationResult>
pub fn recent_history(&self, n: usize) -> Vec<&AggregationResult>
Return the n most-recent AggregationResults (newest last).
Sourcepub fn stats(&self) -> EaAggregatorStats
pub fn stats(&self) -> EaAggregatorStats
Compute statistics over the full history.
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§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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
impl<T> Read<Exclusive, BecauseExclusive> 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.