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

Method exact_asymmetric_distance

nodedb-codec/src/vector_quant/bbq.rs:293–303  ·  view source on GitHub ↗

Exact asymmetric L2 distance using the dequantized stored vector. The query is exact centered FP32 (`q.centered`). The stored vector is reconstructed from its sign bits and `residual_norm` via [`BbqCodec::dequantize`]: each dimension ≈ ±residual_norm / √dim. This is the high-fidelity asymmetric path invoked during rerank on the `oversample × top_k` candidates returned by the coarse Hamming pass.

(&self, q: &BbqQuery, v: &BbqQuantized)

Source from the content-addressed store, hash-verified

291 /// This is the high-fidelity asymmetric path invoked during rerank on the
292 /// `oversample × top_k` candidates returned by the coarse Hamming pass.
293 fn exact_asymmetric_distance(&self, q: &BbqQuery, v: &BbqQuantized) -> f32 {
294 let header = v.0.header();
295 let recon = Self::dequantize(v.0.packed_bits(), header.residual_norm, self.dim);
296 // L2(q.centered, recon)
297 q.centered
298 .iter()
299 .zip(recon.iter())
300 .map(|(&a, &b)| (a - b) * (a - b))
301 .sum::<f32>()
302 .sqrt()
303 }
304}
305
306// ── Tests ────────────────────────────────────────────────────────────────────

Callers 1

Calls 3

packed_bitsMethod · 0.80
headerMethod · 0.45
iterMethod · 0.45

Tested by 1