(&self, query: &[f32], candidate: &[u8])
| 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] |
no outgoing calls