@@ -26,18 +26,20 @@ use crate::vector::storage::CODES_FIELD;
2626use crate :: vector:: storage:: NORMS_FIELD ;
2727use crate :: vector:: tq_padded_dim;
2828
29- /// TurboQuant logical extension type.
29+ /// TurboQuant logical extension type. Per-array configuration lives in [`TurboQuantMetadata`].
3030#[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
3131pub struct TurboQuant ;
3232
33- /// Serialized metadata for a TurboQuant extension array.
33+ /// Serialized metadata for a TurboQuant extension array. The fields together suffice to
34+ /// reconstruct the SORF transform and centroid codebook at decode time.
3435#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
3536pub struct TurboQuantMetadata {
36- /// Original vector element type and stored norm type.
37+ /// Original vector element ptype and stored row-norm ptype. Restricted to `f16` / `f32` /
38+ /// `f64`.
3739 pub element_ptype : PType ,
38- /// Original vector dimension before SORF padding.
40+ /// Original vector dimension before SORF padding to the next power of two .
3941 pub dimensions : u32 ,
40- /// Bits per coordinate in the scalar quantizer codebook.
42+ /// Bits per coordinate in the scalar quantizer codebook (`1..=8`) .
4143 pub bit_width : u8 ,
4244 /// Seed used to derive the deterministic SORF transform.
4345 pub seed : u64 ,
@@ -106,6 +108,8 @@ impl ExtVTable for TurboQuant {
106108 }
107109}
108110
111+ /// Wire-format representation of [`TurboQuantMetadata`]. Field tags MUST NOT change once
112+ /// shipped; new fields must use unused tags and remain optional.
109113#[ derive( Clone , PartialEq , Message ) ]
110114struct TurboQuantMetadataProto {
111115 #[ prost( enumeration = "PType" , tag = "1" ) ]
@@ -158,6 +162,8 @@ pub(crate) fn tq_storage_dtype(
158162 ) )
159163}
160164
165+ /// Validate [`TurboQuantMetadata`] invariants. Called on both serialize and deserialize so a
166+ /// corrupted on-disk metadata block errors out rather than decoding into nonsense.
161167fn validate_tq_metadata ( metadata : & TurboQuantMetadata ) -> VortexResult < ( ) > {
162168 vortex_ensure ! (
163169 metadata. dimensions >= MIN_DIMENSION ,
@@ -175,6 +181,8 @@ fn validate_tq_metadata(metadata: &TurboQuantMetadata) -> VortexResult<()> {
175181 TurboQuantConfig :: try_new ( metadata. bit_width , metadata. seed , metadata. num_rounds ) . map ( |_| ( ) )
176182}
177183
184+ /// Validate that `dtype` matches the storage shape produced by [`tq_storage_dtype`] for
185+ /// `metadata`. Called from [`TurboQuant::validate_dtype`].
178186fn validate_tq_storage_dtype ( metadata : & TurboQuantMetadata , dtype : & DType ) -> VortexResult < ( ) > {
179187 let DType :: Struct ( fields, _) = dtype else {
180188 vortex_bail ! ( "TurboQuant storage dtype must be a Struct, got {dtype}" ) ;
0 commit comments