Repository navigation
Add Int8 support to the QBit data type - #108105
Conversation
`QBit` previously supported only `BFloat16`, `Float32`, and `Float64` element types. This adds `Int8` (an 8-bit element stored as 8 bit planes), so `QBit` can hold quantized integer vectors and use the transposed distance functions over them. The change covers the full element-type machinery: - `DataTypeQBit` validation and `ColumnQBit` naming; - bit-transposition serialization in `SerializationQBit`; - `Array` to `QBit` conversion and `convertFieldToType`; - `L2DistanceTransposed` and `cosineDistanceTransposed`, including the `simsimd` `i8` kernels and the partial-reads optimization; - the query fuzzer. Note: the 8-bit transposition word is `uint8_t` rather than ClickHouse's `UInt8`, because `UInt8` is `char8_t`, which does not satisfy `std::countr_zero`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [22a7835] Summary: ✅
AI ReviewSummaryThis PR adds Missing context / blind spots
Final VerdictStatus: ✅ Approve |
- In `convertFieldToType`, convert numeric fields to `Int8` by truncating (wrapping), matching how `toInt8` / `CAST(... AS Int8)` and the `Array(Int8)` conversion handle out-of-range values (e.g. 128 -> -128). The previous `FieldVisitorConvertToNumber<Int8>` range-checked `Float64` but wrapped integers, which diverged from those types; now both wrap. - Add a regression to `04404_qbit_int8` covering out-of-range wrapping via `VALUES` and `CAST`, asserted equal to `Int8` / `Array(Int8)`. - Update the RowBinary `QBit` documentation (`RowBinary.md` and the source doc in `BinaryRowInputFormat.cpp`) to list `Int8` as a valid element type. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- In `convertFieldToType`, convert numeric fields to `Int8` via `accurate::convertNumeric` (with an explicit `isFinite` guard for `Float64`), rejecting out-of-range and non-finite values uniformly for integer and floating-point fields. This matches the accurate conversion `convertNumericType` already uses and removes the undefined behaviour of casting a non-finite or out-of-range `Float64` to a narrow integer. - Add `04404_qbit_int8` cases asserting `nan`/`inf` are rejected with `CANNOT_CONVERT_TYPE`, consistent with `Array(Int8)`. - Document `Int8` as a valid `QBit` element type in the vector-search guide (`annindexes.md`). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Make `convertFieldToType` truncate (wrap) numeric fields to `Int8`, so `QBit(Int8)` construction has a single contract across `VALUES`, `CAST`, and `convertFieldToType`: finite values wrap (e.g. 128 -> -128, matching `toInt8` / `Array(Int8)`), and non-finite or out-of-Int64-range `Float64` values are rejected explicitly (they cannot be wrapped, and casting them to a narrow integer would be undefined behaviour). This resolves the contract ambiguity raised in review while keeping the inf/nan guard: the earlier `accurate::convertNumeric` variant rejected in-range out-of-bounds values, diverging from the wrapping `VALUES`/`CAST` path. The stateless tests in `04404_qbit_int8` already pass on this path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
SimSIMD's `i8` `L2`/`cosine` kernels accumulate in `int32` (e.g. the serial `SIMSIMD_MAKE_L2SQ(serial, i8, i32, ...)`), which overflows for large but valid `QBit(Int8)` dimensions — `255^2 * 33026 > INT32_MAX` for `L2`, and `128^2 * 131072 > INT32_MAX` for `cosine` — producing wrong results (or UB). The scalar fallback accumulates in `Float64` and is correct. Gate the `i8` SimSIMD path by dimension: each kernel exposes the largest per-element term it accumulates, and beyond `INT32_MAX / term` elements we fall back to the scalar `Float64`-accumulator path. Small dimensions keep using the fast SIMD kernels. Add `04405_qbit_int8_distance` regressions: `L2DistanceTransposed` over `QBit(Int8, 33026)` and `cosineDistanceTransposed` over `QBit(Int8, 131072)` with worst-case values, checked against the exact `Float64` results. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 134/184 (72.83%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 3 line(s) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Everything looks clear.
Resolve conflicts between the QBit stride feature and the QBit(Int8) support that landed in master (#108105): - QueryFuzzer: keep Int8 in the element-type list and the strided branch. - convertFieldToType: combine the Int8 element conversion (with the wrap/reject contract) with the per-stride-group transpose. - ColumnQBit::getName, DataTypeQBit/qbit.md docs: list Int8 alongside the per-stride-group subcolumn counts. - distanceTransposed: accept Int8 reference vectors in the internal form and bound the int8 SimSIMD int32 accumulator by 'dims' (the number of dimensions actually read) instead of the removed 'qbit_size'.
Following the addition of `Int8` to the `QBit` data type (#108105), extend the new `dotProductTransposed` kernel to handle `Int8` `QBit` columns, the same way `L2DistanceTransposed` and `cosineDistanceTransposed` already do after merging `master`. The `DotProductTransposed` kernel gains the `Int8` scalar branch and the `max_int8_simd_term` overflow bound (max `|a * b|` is `128 * 128`, when both elements are `-128`). The rest of the `Int8` machinery - reference type acceptance, accumulator dispatch, SimSIMD `i8` kernel resolution, and the int32 overflow guard - is shared by `FunctionArrayDistance` and already applies once `master` is merged. Bump the documented `IntroducedIn` version to 26.7 to match the current development version, and add `Int8` coverage to 04403_dot_product_transposed: exact full-precision dot products, reduced precision, and a large-dimension case that exercises the int32-overflow fallback to the `Float64` scalar path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add Int8 support to the QBit data type
Following the addition of `Int8` to the `QBit` data type (ClickHouse#108105), extend the new `dotProductTransposed` kernel to handle `Int8` `QBit` columns, the same way `L2DistanceTransposed` and `cosineDistanceTransposed` already do after merging `master`. The `DotProductTransposed` kernel gains the `Int8` scalar branch and the `max_int8_simd_term` overflow bound (max `|a * b|` is `128 * 128`, when both elements are `-128`). The rest of the `Int8` machinery - reference type acceptance, accumulator dispatch, SimSIMD `i8` kernel resolution, and the int32 overflow guard - is shared by `FunctionArrayDistance` and already applies once `master` is merged. Bump the documented `IntroducedIn` version to 26.7 to match the current development version, and add `Int8` coverage to 04403_dot_product_transposed: exact full-precision dot products, reduced precision, and a large-dimension case that exercises the int32-overflow fallback to the `Float64` scalar path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve conflicts between the QBit stride feature and the QBit(Int8) support that landed in master (ClickHouse#108105): - QueryFuzzer: keep Int8 in the element-type list and the strided branch. - convertFieldToType: combine the Int8 element conversion (with the wrap/reject contract) with the per-stride-group transpose. - ColumnQBit::getName, DataTypeQBit/qbit.md docs: list Int8 alongside the per-stride-group subcolumn counts. - distanceTransposed: accept Int8 reference vectors in the internal form and bound the int8 SimSIMD int32 accumulator by 'dims' (the number of dimensions actually read) instead of the removed 'qbit_size'.
Adds
Int8as a supported element type for theQBitdata type. PreviouslyQBitaccepted onlyBFloat16,Float32, andFloat64. With this changeQBit(Int8, N)stores quantized 8-bit integer vectors (8 bit planes per element) and supports the transposed distance functionsL2DistanceTransposedandcosineDistanceTransposedover them, including the partial-reads (precision) optimization and thesimsimdi8SIMD kernels.The change touches the full element-type machinery:
DataTypeQBitvalidation,ColumnQBitnaming, the bit-transposition serialization inSerializationQBit,Array↔QBitconversion,convertFieldToType, the distance functions, and the query fuzzer. Documentation and tests are included.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added support for the
Int8element type in theQBitdata type, enabling storage and transposed-distance vector search (L2DistanceTransposed,cosineDistanceTransposed) over quantized 8-bit integer vectors.Version info
26.7.1.185(included in26.7and later)