Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IndexIVFFastScan reconstruct_from_offset method (#4095)
Summary: Resolves issue #4089 - IndexIVFPQFastScan crashes with certain nlist values The `reconstruct_from_offset` method in `IndexIVFFastScan` was incorrectly reconstructing vectors, causing crashes when the `nlist` parameter was not byte-aligned (e.g. 100 instead of 256). The root cause was that the `list_no` (Voronoi cell number) was not being properly encoded into the `code` vector before passing it to the `sa_decode` function. This resulted in invalid `list_no` values being read in `sa_decode`, triggering the assertion failure `'list_no >= 0 && list_no < nlist'` when `nlist` in some cases. This PR fixes the issue with the following changes to `reconstruct_from_offset`: 1. Encode the `list_no` into the beginning of the `code` vector using the existing `encode_listno` method 2. Start the `BitstringWriter` after the coarse code portion of `code` (shifted by `coarse_code_size()` bytes) 3. Remove the residual centroid addition logic, as it is already handled in `sa_decode` After these changes: - Crashes no longer occur for any `nlist` value - Reconstruction is now correct, matching the output of `IndexIVFPQ` Fixes #4089 Please review and let me know if any changes are needed. Thanks! Pull Request resolved: #4095 Reviewed By: asadoughi Differential Revision: D67937160 Pulled By: mdouze fbshipit-source-id: 4705106ba49c01c788b3c75c39c2260615f45764
- Loading branch information