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

Method encode

nodedb-vector/src/quantize/pq_codec.rs:66–80  ·  view source on GitHub ↗

Encode an FP32 vector: one centroid index byte per subspace. # Panics `UnifiedQuantizedVector::new` fails only when the outlier bitmask does not match the provided outlier slice. With `outlier_bitmask = 0` and an empty slice this can never happen. The `expect` is therefore unreachable in practice.

(&self, v: &[f32])

Source from the content-addressed store, hash-verified

64 /// empty slice this can never happen. The `expect` is therefore unreachable
65 /// in practice.
66 fn encode(&self, v: &[f32]) -> Self::Quantized {
67 let codes = self.encode(v);
68 let header = QuantHeader {
69 quant_mode: QuantMode::Pq as u16,
70 dim: self.dim as u16,
71 global_scale: 0.0,
72 residual_norm: 0.0,
73 dot_quantized: 0.0,
74 outlier_bitmask: 0,
75 reserved: [0; 8],
76 };
77 let uqv = UnifiedQuantizedVector::new(header, &codes, &[])
78 .expect("PqCodec::encode: layout construction is infallible (no outliers)");
79 PqQuantized(uqv)
80 }
81
82 /// Prepare the query by precomputing the M×K asymmetric distance table.
83 ///

Callers 2

use_vector_codecFunction · 0.45

Calls 2

PqQuantizedClass · 0.85
expectMethod · 0.45

Tested by 1