pub struct CoarseCentroids {
pub num_clusters: u32,
pub dim: usize,
pub centroids: Vec<f32>,
pub version: u64,
}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
Implementations§
Source§impl CoarseCentroids
impl CoarseCentroids
Sourcepub fn train(
vectors: &[Vec<f32>],
num_clusters: usize,
max_iters: usize,
_seed: u64,
) -> Self
pub fn train( vectors: &[Vec<f32>], num_clusters: usize, max_iters: usize, _seed: u64, ) -> 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 get_centroid(&self, cluster_id: u32) -> &[f32]
pub fn get_centroid(&self, cluster_id: u32) -> &[f32]
Get centroid for a cluster
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
pub fn from_bytes(data: &[u8]) -> Result<Self>
Deserialize from 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 more