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

Method encode

nodedb-vector/src/quantize/pq.rs:123–133  ·  view source on GitHub ↗

Encode a vector: for each subvector, find the nearest centroid index. This is a per-vector hot-path operation. Governor charging is intentionally skipped here to avoid atomic overhead on every candidate during search; use [`encode_batch`] for bulk encoding with budget enforcement.

(&self, vector: &[f32])

Source from the content-addressed store, hash-verified

121 /// during search; use [`encode_batch`] for bulk encoding with budget
122 /// enforcement.
123 pub fn encode(&self, vector: &[f32]) -> Vec<u8> {
124 debug_assert_eq!(vector.len(), self.dim);
125 let mut code = Vec::with_capacity(self.m);
126 for sub in 0..self.m {
127 let offset = sub * self.sub_dim;
128 let sub_vec = &vector[offset..offset + self.sub_dim];
129 let nearest = self.nearest_centroid(sub, sub_vec);
130 code.push(nearest as u8);
131 }
132 code
133 }
134
135 /// Batch encode all vectors into a contiguous byte array.
136 ///

Callers 7

addMethod · 0.45
insertMethod · 0.45
searchMethod · 0.45
encode_batchMethod · 0.45
encode_decode_roundtripFunction · 0.45

Calls 2

nearest_centroidMethod · 0.45
pushMethod · 0.45