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

Method decode

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

Decode a PQ code back to an approximate FP32 vector. Charges `dim * size_of:: ()` bytes to the governor (if set) before allocating the output buffer.

(&self, code: &[u8])

Source from the content-addressed store, hash-verified

191 /// Charges `dim * size_of::<f32>()` bytes to the governor (if set)
192 /// before allocating the output buffer.
193 pub fn decode(&self, code: &[u8]) -> Result<Vec<f32>, VectorError> {
194 debug_assert_eq!(code.len(), self.m);
195 let _g = try_reserve_or_skip(&self.governor, self.dim * size_of::<f32>())?;
196 let mut out = Vec::with_capacity(self.dim);
197 for (sub, &c) in code.iter().enumerate() {
198 out.extend_from_slice(&self.codebooks[sub][c as usize]);
199 }
200 Ok(out)
201 }
202
203 /// Serialize the codec to bytes with a versioned magic header.
204 ///

Callers 2

encode_decode_roundtripFunction · 0.45

Calls 2

try_reserve_or_skipFunction · 0.85
iterMethod · 0.45

Tested by 1

encode_decode_roundtripFunction · 0.36