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

Method encode

nodedb-vector/src/quantize/sq8_codec.rs:51–65  ·  view source on GitHub ↗

Encode a single FP32 vector into an SQ8 `UnifiedQuantizedVector`. # Panics The `UnifiedQuantizedVector::new` call will only fail if the outlier count mismatches the bitmask, or an outlier dim_index ≥ 64. Neither condition can arise here: `outlier_bitmask` is 0 and `outliers` is empty. The `expect` is therefore unreachable in practice.

(&self, v: &[f32])

Source from the content-addressed store, hash-verified

49 /// condition can arise here: `outlier_bitmask` is 0 and `outliers` is
50 /// empty. The `expect` is therefore unreachable in practice.
51 fn encode(&self, v: &[f32]) -> Self::Quantized {
52 let codes = self.quantize(v);
53 let header = QuantHeader {
54 quant_mode: QuantMode::Sq8 as u16,
55 dim: self.dim as u16,
56 global_scale: 0.0,
57 residual_norm: 0.0,
58 dot_quantized: 0.0,
59 outlier_bitmask: 0,
60 reserved: [0; 8],
61 };
62 let uqv = UnifiedQuantizedVector::new(header, &codes, &[])
63 .expect("Sq8Codec::encode: layout construction is infallible (no outliers)");
64 Sq8Quantized(uqv)
65 }
66
67 /// Prepare the FP32 query for asymmetric distance computations.
68 ///

Callers 1

use_vector_codecFunction · 0.45

Calls 3

Sq8QuantizedClass · 0.85
quantizeMethod · 0.80
expectMethod · 0.45

Tested by

no test coverage detected