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

Function build_collection_codec

nodedb-vector/src/collection/codec_dispatch.rs:69–100  ·  view source on GitHub ↗

Build a `CollectionCodec` from a quantization tag and training vectors. Returns `None` for unsupported or unrecognised tags (e.g. "sq8", "pq", "none") — those variants use separate per-segment code paths.

(
    quantization: &str,
    vectors: &[Vec<f32>],
    dim: usize,
    m: usize,
    ef_construction: usize,
    seed: u64,
)

Source from the content-addressed store, hash-verified

67/// Returns `None` for unsupported or unrecognised tags (e.g. "sq8", "pq",
68/// "none") — those variants use separate per-segment code paths.
69pub fn build_collection_codec(
70 quantization: &str,
71 vectors: &[Vec<f32>],
72 dim: usize,
73 m: usize,
74 ef_construction: usize,
75 seed: u64,
76) -> Option<CollectionCodec> {
77 if vectors.is_empty() {
78 return None;
79 }
80 let refs: Vec<&[f32]> = vectors.iter().map(|v| v.as_slice()).collect();
81 match quantization {
82 "rabitq" => {
83 let codec = RaBitQCodec::calibrate(&refs, dim, seed);
84 let mut idx = HnswCodecIndex::new(dim, m, ef_construction, codec, seed);
85 for (i, v) in vectors.iter().enumerate() {
86 idx.insert(i as u32, v);
87 }
88 Some(CollectionCodec::RaBitQ(idx))
89 }
90 "bbq" => {
91 let codec = BbqCodec::calibrate(&refs, dim, 3);
92 let mut idx = HnswCodecIndex::new(dim, m, ef_construction, codec, seed);
93 for (i, v) in vectors.iter().enumerate() {
94 idx.insert(i as u32, v);
95 }
96 Some(CollectionCodec::Bbq(idx))
97 }
98 _ => None,
99 }
100}
101
102#[cfg(test)]
103mod tests {

Callers 8

build_bbq_returns_someFunction · 0.85
sq8_tag_returns_noneFunction · 0.85
len_and_is_emptyFunction · 0.85
quantization_tagFunction · 0.85
build_codec_dispatchMethod · 0.85

Calls 5

collectMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45
insertMethod · 0.45

Tested by 7

build_bbq_returns_someFunction · 0.68
sq8_tag_returns_noneFunction · 0.68
len_and_is_emptyFunction · 0.68
quantization_tagFunction · 0.68