fix(index): stop appending a spurious byte in binary_quantization - #9029
Open
LuciferYang wants to merge 1 commit into
Open
fix(index): stop appending a spurious byte in binary_quantization#9029LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
binary_quantization chained one tail byte unconditionally, so an input whose length is a multiple of 8 produced floor(len/8)+1 bytes instead of ceil(len/8). Append the tail byte only when a tail exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
binary_quantizationappends the tail byte unconditionally, so an input whose length is a multiple of 8 producesfloor(len / 8) + 1bytes instead ofceil(len / 8). ThroughBinaryQuantization::transformthat is one extra zero byte per row for any dimension that is a multiple of 8.Fixes #9028.
What this changes
Compute the tail byte once and chain it only when
chunks_exact(8)left a remainder. The closure mapped over the full chunks is untouched, so the loop the "auto vectorized" comment refers to is the same code as before.BinaryQuantizationhas no callers in this repository, so no in-tree width changes. The old width also contradicted the crate's own sizing helper,rabit_binary_code_bytes, which isdiv_ceil(8). Deleting the type is the other option, sinceRabitQuantizeris what IVF_RQ uses, but it is public API and the behaviour is cheap to fix.Test plan
test_binary_quantization_length_multiple_of_eightpins the helper at 16 values, and two tests pin the public entry point on both branches: 3 rows of dimension 8, and 2 rows of dimension 12 where the tail byte must still appear. Restoring the old implementation makes them fail with[85, 85, 0]against[85, 85]and 6 bytes against 3. The existingtest_binary_quantizationcovers the remainder case at 11 values, so both branches stay asserted.cargo test -p lance-index --lib vector::bq233 passedcargo clippy --all --tests --benches -- -D warningscleancargo fmt --all --checkclean