MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / nearest_centroid

Method nearest_centroid

nodedb-vector/src/quantize/pq.rs:245–256  ·  view source on GitHub ↗
(&self, subspace: usize, sub_vec: &[f32])

Source from the content-addressed store, hash-verified

243 }
244
245 fn nearest_centroid(&self, subspace: usize, sub_vec: &[f32]) -> usize {
246 let mut best_idx = 0;
247 let mut best_dist = f32::MAX;
248 for (i, centroid) in self.codebooks[subspace].iter().enumerate() {
249 let d = l2_sub(sub_vec, centroid);
250 if d < best_dist {
251 best_dist = d;
252 best_idx = i;
253 }
254 }
255 best_idx
256 }
257}
258
259/// L2 squared distance for sub-vectors (used in k-means and encoding).

Callers 1

encodeMethod · 0.45

Calls 2

l2_subFunction · 0.85
iterMethod · 0.45

Tested by

no test coverage detected