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

Method fast_symmetric_distance

nodedb-vector/src/quantize/sq8_codec.rs:85–97  ·  view source on GitHub ↗
(&self, q: &Self::Quantized, v: &Self::Quantized)

Source from the content-addressed store, hash-verified

83 /// INT8-INT8 Hamming estimate but SQ8 has no faster bitwise symmetric form.
84 #[inline]
85 fn fast_symmetric_distance(&self, q: &Self::Quantized, v: &Self::Quantized) -> f32 {
86 let qa = packed_bits_of(q);
87 let qb = packed_bits_of(v);
88 let dq_a = self.dequantize(qa);
89 let dq_b = self.dequantize(qb);
90 dq_a.iter()
91 .zip(dq_b.iter())
92 .map(|(&a, &b)| {
93 let d = a - b;
94 d * d
95 })
96 .sum()
97 }
98
99 /// Asymmetric L2 squared distance: FP32 query vs INT8 candidate.
100 ///

Calls 4

sumMethod · 0.80
packed_bits_ofFunction · 0.70
dequantizeMethod · 0.45
iterMethod · 0.45