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

Function attach_sq8

nodedb-vector/src/collection/search.rs:575–588  ·  view source on GitHub ↗

Attach SQ8 quantization to the first sealed segment of `coll`.

(coll: &mut VectorCollection)

Source from the content-addressed store, hash-verified

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() {

Calls 8

collectMethod · 0.80
quantizeMethod · 0.80
dimMethod · 0.45
lenMethod · 0.45
get_vectorMethod · 0.45
to_vecMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45