Attach SQ8 quantization to the first sealed segment of `coll`.
(coll: &mut VectorCollection)
| 573 | |
| 574 | /// Attach SQ8 quantization to the first sealed segment of `coll`. |
| 575 | fn attach_sq8(coll: &mut VectorCollection) { |
| 576 | use crate::quantize::sq8::Sq8Codec; |
| 577 | |
| 578 | let sealed = &mut coll.sealed[0]; |
| 579 | let dim = sealed.index.dim(); |
| 580 | let n = sealed.index.len(); |
| 581 | let vecs: Vec<Vec<f32>> = (0..n) |
| 582 | .filter_map(|i| sealed.index.get_vector(i as u32).map(|v| v.to_vec())) |
| 583 | .collect(); |
| 584 | let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect(); |
| 585 | let codec = Sq8Codec::calibrate(&refs, dim); |
| 586 | let sq8_data: Vec<u8> = vecs.iter().flat_map(|v| codec.quantize(v)).collect(); |
| 587 | sealed.sq8 = Some((codec, sq8_data)); |
| 588 | } |
| 589 | |
| 590 | #[test] |
| 591 | fn sq8_search_returns_correct_nearest_neighbor() { |