pub struct SemanticClusterManager {
pub clusters: Vec<SemanticCluster>,
pub config: ClusterManagerConfig,
pub total_assignments: u64,
}Expand description
Online k-means-style semantic cluster manager.
Documents are assigned to the nearest initialised cluster (by Euclidean distance) and each assignment incrementally shifts the cluster centroid toward the document embedding.
Fields§
§clusters: Vec<SemanticCluster>The managed clusters (length == config.n_clusters).
config: ClusterManagerConfigManager configuration.
total_assignments: u64Total number of successful assignments since creation or last reset.
Implementations§
Source§impl SemanticClusterManager
impl SemanticClusterManager
Sourcepub fn new(config: ClusterManagerConfig) -> Self
pub fn new(config: ClusterManagerConfig) -> Self
Create a new manager with n_clusters empty (uninitialized) clusters.
Sourcepub fn initialize_centroids(&mut self, centroids: Vec<Vec<f32>>)
pub fn initialize_centroids(&mut self, centroids: Vec<Vec<f32>>)
Initialise cluster centroids from the provided list.
Only up to min(centroids.len(), n_clusters) clusters are initialised.
Sourcepub fn assign(
&mut self,
doc_id: u64,
embedding: &[f32],
) -> Option<ClusterAssignment>
pub fn assign( &mut self, doc_id: u64, embedding: &[f32], ) -> Option<ClusterAssignment>
Assign doc_id to the nearest initialised cluster and update the centroid.
A cluster is considered initialised when its centroid is non-empty and its
dimension matches that of embedding.
Returns None when no valid cluster exists.
Sourcepub fn nearest_cluster(&self, embedding: &[f32]) -> Option<usize>
pub fn nearest_cluster(&self, embedding: &[f32]) -> Option<usize>
Return the cluster_id of the nearest initialised cluster to embedding without
mutating any state.
Sourcepub fn cluster(&self, cluster_id: usize) -> Option<&SemanticCluster>
pub fn cluster(&self, cluster_id: usize) -> Option<&SemanticCluster>
Return a reference to a cluster by its cluster_id, or None if out of bounds.
Sourcepub fn stats(&self) -> ClusterManagerStats
pub fn stats(&self) -> ClusterManagerStats
Compute aggregate statistics over all clusters.
Sourcepub fn reset_drift(&mut self)
pub fn reset_drift(&mut self)
Reset total_drift to 0.0 for all clusters.
Auto Trait Implementations§
impl Freeze for SemanticClusterManager
impl RefUnwindSafe for SemanticClusterManager
impl Send for SemanticClusterManager
impl Sync for SemanticClusterManager
impl Unpin for SemanticClusterManager
impl UnsafeUnpin for SemanticClusterManager
impl UnwindSafe for SemanticClusterManager
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.