| 311 | } |
| 312 | |
| 313 | fn prepare_query(&self, q: &[f32]) -> Self::Query { |
| 314 | let dim = self.dim; |
| 315 | let residual: Vec<f32> = q |
| 316 | .iter() |
| 317 | .zip(self.centroid.iter()) |
| 318 | .map(|(&qi, &ci)| qi - ci) |
| 319 | .collect(); |
| 320 | let query_norm = residual.iter().map(|x| x * x).sum::<f32>().sqrt(); |
| 321 | let rotated = self.apply_rotation(&residual); |
| 322 | let rotated_signs = sign_pack(&rotated, dim); |
| 323 | RaBitQQuery { |
| 324 | rotated_signs, |
| 325 | query_norm, |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /// Symmetric distance estimate: both `q` and `v` are quantized. |
| 330 | /// |