Calibrate a new codec from a set of training vectors. - Computes the centroid as the coordinate-wise mean of `vectors`. - Stores `rotation_seed` for reproducible signed-diagonal generation. # Errors (none — returns Self directly) Returns a zero-centroid codec if `vectors` is empty.
(vectors: &[&[f32]], dim: usize, rotation_seed: u64)
| 138 | /// |
| 139 | /// Returns a zero-centroid codec if `vectors` is empty. |
| 140 | pub fn calibrate(vectors: &[&[f32]], dim: usize, rotation_seed: u64) -> Self { |
| 141 | let centroid = if vectors.is_empty() { |
| 142 | vec![0.0f32; dim] |
| 143 | } else { |
| 144 | let n = vectors.len() as f32; |
| 145 | let mut c = vec![0.0f32; dim]; |
| 146 | for v in vectors { |
| 147 | for (ci, &vi) in c.iter_mut().zip(v.iter()) { |
| 148 | *ci += vi; |
| 149 | } |
| 150 | } |
| 151 | c.iter_mut().for_each(|x| *x /= n); |
| 152 | c |
| 153 | }; |
| 154 | Self { |
| 155 | dim, |
| 156 | centroid, |
| 157 | rotation_seed, |
| 158 | bias_correct: false, |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /// On-disk magic for RaBitQ codec envelopes. |
| 163 | pub const ENVELOPE_MAGIC: &'static [u8; codec_envelope::MAGIC_LEN] = b"NDRBQ"; |