You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(python): preserve PQ num_bits in model training (#7583)
## Background
While building vector indexes through Ray-based distributed indexing, we
found that the PQ `num_bits` option could be ignored by the global PQ
training path. The codebook is parameterized by this value: for example,
4-bit PQ should train 16 centroids per sub-vector, while 8-bit PQ trains
256.
Before this change, Python/PyO3 PQ training always used 8 bits
internally. That can produce a PQ codebook whose bit width does not
match the later index build settings, which can make pre-trained PQ
artifacts inconsistent with segment construction and hurt
quantization/index quality.
## Summary
- expose `num_bits` on Python PQ training helpers and keep the default
at 8 bits
- pass `num_bits` through the PyO3 PQ training path instead of
hard-coding 8
- persist `num_bits` in saved `PqModel` metadata and reuse it when
building from pre-trained PQ models
## Tests
- `make build PYTHON=3.12`
- `uv run --frozen pytest python/tests/test_indices.py::test_gen_pq
python/tests/test_indices.py::test_indices_builder_multivector_distributed_dimensions`
- `uv run --frozen ruff check python/tests/test_indices.py`
- `uv run --frozen ruff format --check python/tests/test_indices.py`
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Added configurable Product Quantization (PQ) bit width via a new
`num_bits` option (default: 8), including 4-bit models.
- PQ training, vector transformation, and relevant index-building flows
now use the selected bit width end-to-end.
- PQ models now save and reload the chosen `num_bits` for consistent
behavior and backward compatibility.
- **Bug Fixes**
- Improved PQ training validation to use the codebook size implied by
the selected `num_bits`.
- **Tests**
- Extended PQ coverage to validate 4-bit codebooks and verify correct
save/reload of `num_bits`.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
0 commit comments