pub struct CoarseCentroids {
pub num_clusters: u32,
pub dim: usize,
pub centroids: Vec<f32>,
pub version: u64,
pub soar_config: Option<SoarConfig>,
/* private fields */
}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>],
index_label: &str,
) -> Self
pub fn train( config: &CoarseConfig, vectors: &[Vec<f32>], index_label: &str, ) -> Self
Train coarse centroids using k-means algorithm
Uses deterministic adaptive D² seeding and Lloyd refinement.
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 probe(
&self,
vector: &[f32],
k: usize,
mode: IvfRoutingMode,
) -> IvfProbePlan
pub fn probe( &self, vector: &[f32], k: usize, mode: IvfRoutingMode, ) -> IvfProbePlan
Build a versioned probe plan using flat or two-level routing.
The returned leaf IDs are independent of segment contents and can be reused across every segment built from this global codebook.
pub fn validate_routing(&self, mode: IvfRoutingMode) -> Result<(), String>
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_routing(
&self,
vector: &[f32],
routing: IvfRoutingMode,
) -> MultiAssignment
pub fn assign_with_routing( &self, vector: &[f32], routing: IvfRoutingMode, ) -> MultiAssignment
Assign during segment construction through the same persisted router used at query time. Large codebooks therefore avoid an O(K) scan for every indexed vector.
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: balance secondary distortion and residual orthogonality
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 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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
Auto Trait Implementations§
impl Freeze for CoarseCentroids
impl RefUnwindSafe for CoarseCentroids
impl Send for CoarseCentroids
impl Sync for CoarseCentroids
impl Unpin for CoarseCentroids
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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 more