pub struct CoarseCentroids {
pub num_clusters: u32,
pub dim: usize,
pub centroids: Vec<f32>,
pub version: u64,
pub soar_config: Option<SoarConfig>,
}Expand description
Coarse centroids for IVF - trained once, shared across all segments
Fields§
§num_clusters: u32Number of clusters
dim: usizeVector dimension
centroids: Vec<f32>Centroids stored as flat array (num_clusters × dim)
version: u64Version for compatibility checking during merge
soar_config: Option<SoarConfig>SOAR configuration (if enabled)
Implementations§
Source§impl CoarseCentroids
impl CoarseCentroids
Sourcepub fn train(config: &CoarseConfig, vectors: &[Vec<f32>]) -> Self
pub fn train(config: &CoarseConfig, vectors: &[Vec<f32>]) -> Self
Train coarse centroids using k-means algorithm
Uses kmeans crate with SIMD acceleration (native feature).
Sourcepub fn find_nearest(&self, vector: &[f32]) -> u32
pub fn find_nearest(&self, vector: &[f32]) -> u32
Find nearest cluster for a query vector
Sourcepub fn find_k_nearest(&self, vector: &[f32], k: usize) -> Vec<u32>
pub fn find_k_nearest(&self, vector: &[f32], k: usize) -> Vec<u32>
Find k nearest clusters for a query vector
Sourcepub fn find_k_nearest_with_distances(
&self,
vector: &[f32],
k: usize,
) -> Vec<(u32, f32)>
pub fn find_k_nearest_with_distances( &self, vector: &[f32], k: usize, ) -> Vec<(u32, f32)>
Find k nearest clusters with their distances
Sourcepub fn assign(&self, vector: &[f32]) -> MultiAssignment
pub fn assign(&self, vector: &[f32]) -> MultiAssignment
Assign vector with SOAR (if configured) or standard assignment
Sourcepub fn assign_with_soar(
&self,
vector: &[f32],
config: &SoarConfig,
) -> MultiAssignment
pub fn assign_with_soar( &self, vector: &[f32], config: &SoarConfig, ) -> MultiAssignment
SOAR-style assignment: find secondary clusters with orthogonal residuals
Sourcepub fn get_centroid(&self, cluster_id: u32) -> &[f32]
pub fn get_centroid(&self, cluster_id: u32) -> &[f32]
Get centroid for a cluster
Sourcepub fn compute_residual(&self, vector: &[f32], cluster_id: u32) -> Vec<f32>
pub fn compute_residual(&self, vector: &[f32], cluster_id: u32) -> Vec<f32>
Compute residual vector (vector - centroid)
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
pub fn from_bytes(data: &[u8]) -> Result<Self>
Deserialize from bytes
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Memory usage in bytes
Trait Implementations§
Source§impl Clone for CoarseCentroids
impl Clone for CoarseCentroids
Source§fn clone(&self) -> CoarseCentroids
fn clone(&self) -> CoarseCentroids
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CoarseCentroids
impl Debug for CoarseCentroids
Source§impl<'de> Deserialize<'de> for CoarseCentroids
impl<'de> Deserialize<'de> for CoarseCentroids
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for CoarseCentroids
impl RefUnwindSafe for CoarseCentroids
impl Send for CoarseCentroids
impl Sync for CoarseCentroids
impl Unpin for CoarseCentroids
impl UnwindSafe for CoarseCentroids
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.