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

Method add

nodedb-vector/src/ivf.rs:102–120  ·  view source on GitHub ↗

Add a vector to the index. Returns the assigned ID.

(&mut self, vector: &[f32])

Source from the content-addressed store, hash-verified

100
101 /// Add a vector to the index. Returns the assigned ID.
102 pub fn add(&mut self, vector: &[f32]) -> u32 {
103 assert_eq!(vector.len(), self.dim);
104 let pq = self
105 .pq
106 .as_ref()
107 .expect("index must be trained before add()");
108
109 let cell = self.nearest_centroid(vector);
110 let residual: Vec<f32> = vector
111 .iter()
112 .zip(&self.centroids[cell])
113 .map(|(a, b)| a - b)
114 .collect();
115 let code = pq.encode(&residual);
116 let id = self.count;
117 self.cells[cell].push((id, code));
118 self.count += 1;
119 id
120 }
121
122 /// Batch add vectors.
123 pub fn add_batch(&mut self, vectors: &[&[f32]]) {

Callers 15

writeMethod · 0.45
zero_tailFunction · 0.45
prefetch_nodeMethod · 0.45
add_batchMethod · 0.45
l2_implFunction · 0.45
cosine_implFunction · 0.45
ip_implFunction · 0.45
l2_squared_implFunction · 0.45
cosine_implFunction · 0.45
ip_implFunction · 0.45
bf16_l2_implFunction · 0.45
bf16_cosine_implFunction · 0.45

Calls 7

collectMethod · 0.80
expectMethod · 0.45
as_refMethod · 0.45
nearest_centroidMethod · 0.45
iterMethod · 0.45
encodeMethod · 0.45
pushMethod · 0.45