nodedb_vector/collection/
codec_build.rs1use super::codec_dispatch::{CollectionCodec, build_collection_codec};
9use super::lifecycle::VectorCollection;
10
11impl VectorCollection {
12 pub(crate) fn gather_all_vectors_fp32(&self) -> Vec<Vec<f32>> {
16 let total = self.len();
17 let mut out = Vec::with_capacity(total);
18
19 for i in 0..self.growing.len() as u32 {
20 if let Some(v) = self.growing.get_vector(i) {
21 out.push(v.to_vec());
22 }
23 }
24
25 for seg in &self.building {
26 for i in 0..seg.flat.len() as u32 {
27 if let Some(v) = seg.flat.get_vector(i) {
28 out.push(v.to_vec());
29 }
30 }
31 }
32
33 for seg in &self.sealed {
34 let n = seg.index.len();
35 for i in 0..n as u32 {
36 if !seg.index.is_deleted(i)
37 && let Some(v) = seg.index.get_vector(i)
38 {
39 out.push(v.to_vec());
40 }
41 }
42 }
43
44 out
45 }
46
47 pub fn build_codec_dispatch(&mut self, quantization: &str) -> Option<&CollectionCodec> {
55 let vectors = self.gather_all_vectors_fp32();
56 let dim = self.dim;
57 let m = self.params.m;
58 let ef_construction = self.params.ef_construction;
59 let seed = 42_u64;
60 self.codec_dispatch =
61 build_collection_codec(quantization, &vectors, dim, m, ef_construction, seed);
62 self.codec_dispatch.as_ref()
63 }
64}