pub struct BatchSemanticClusterManager { /* private fields */ }Expand description
Batch k-means semantic cluster manager.
Runs Lloyd’s k-means algorithm over a set of named embeddings, then supports prediction (nearest centroid lookup), membership queries, and quality metrics.
Implementations§
Source§impl BatchSemanticClusterManager
impl BatchSemanticClusterManager
Sourcepub fn new(config: BatchClusterConfig) -> Self
pub fn new(config: BatchClusterConfig) -> Self
Create a new (unfitted) batch cluster manager.
Sourcepub fn fit(&mut self, embeddings: &[(String, Vec<f64>)]) -> Result<(), String>
pub fn fit(&mut self, embeddings: &[(String, Vec<f64>)]) -> Result<(), String>
Run k-means clustering on the provided embeddings.
Embeddings are (doc_id, vector) pairs. The method initialises centroids
from the first k distinct embeddings and then iterates assignment + update
steps until convergence or max_iterations is reached.
Calling fit again resets all previous state.
Sourcepub fn predict(&self, embedding: &[f64]) -> Result<usize, String>
pub fn predict(&self, embedding: &[f64]) -> Result<usize, String>
Predict which cluster a new embedding belongs to (nearest centroid).
Returns an error if the manager has not been fitted yet.
Sourcepub fn get_cluster(&self, id: usize) -> Option<&BatchCluster>
pub fn get_cluster(&self, id: usize) -> Option<&BatchCluster>
Return a reference to a cluster by id, or None if out of range.
Sourcepub fn get_assignment(&self, doc_id: &str) -> Option<usize>
pub fn get_assignment(&self, doc_id: &str) -> Option<usize>
Return the cluster assignment for a document, or None if unknown.
Sourcepub fn cluster_members(&self, cluster_id: usize) -> Vec<String>
pub fn cluster_members(&self, cluster_id: usize) -> Vec<String>
Return the list of document IDs assigned to a given cluster.
Sourcepub fn total_inertia(&self) -> f64
pub fn total_inertia(&self) -> f64
Total inertia (sum of squared distances) across all clusters.
Sourcepub fn silhouette_score_approx(
&self,
embeddings: &[(String, Vec<f64>)],
) -> Result<f64, String>
pub fn silhouette_score_approx( &self, embeddings: &[(String, Vec<f64>)], ) -> Result<f64, String>
Approximate silhouette score.
For each point, computes (b - a) / max(a, b) where:
a= average Euclidean distance to other members of the same clusterb= average distance to the nearest other cluster centroid
Returns the mean silhouette across all points.
Sourcepub fn stats(&self) -> BatchClusterManagerStats
pub fn stats(&self) -> BatchClusterManagerStats
Return aggregate statistics about the current clustering state.
Auto Trait Implementations§
impl Freeze for BatchSemanticClusterManager
impl RefUnwindSafe for BatchSemanticClusterManager
impl Send for BatchSemanticClusterManager
impl Sync for BatchSemanticClusterManager
impl Unpin for BatchSemanticClusterManager
impl UnsafeUnpin for BatchSemanticClusterManager
impl UnwindSafe for BatchSemanticClusterManager
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.