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

Method asymmetric_l2

nodedb-vector/src/quantize/sq8.rs:134–144  ·  view source on GitHub ↗
(&self, query: &[f32], candidate: &[u8])

Source from the content-addressed store, hash-verified

132 /// The query stays in full precision; only the candidate is quantized.
133 #[inline]
134 pub fn asymmetric_l2(&self, query: &[f32], candidate: &[u8]) -> f32 {
135 debug_assert_eq!(query.len(), self.dim);
136 debug_assert_eq!(candidate.len(), self.dim);
137 let mut sum = 0.0f32;
138 for d in 0..self.dim {
139 let dequant = self.mins[d] + candidate[d] as f32 * self.scales[d];
140 let diff = query[d] - dequant;
141 sum += diff * diff;
142 }
143 sum
144 }
145
146 /// Asymmetric cosine distance: query (FP32) vs candidate (INT8).
147 #[inline]

Callers 4

sq8_scoreFunction · 0.80
distance_preparedMethod · 0.80

Calls

no outgoing calls

Tested by 1