Skip to content

Fix binary IVF reconstruct_n stride#5398

Draft
mmnhgo wants to merge 1 commit into
facebookresearch:mainfrom
mmnhgo:5386
Draft

Fix binary IVF reconstruct_n stride#5398
mmnhgo wants to merge 1 commit into
facebookresearch:mainfrom
mmnhgo:5386

Conversation

@mmnhgo

@mmnhgo mmnhgo commented Jul 10, 2026

Copy link
Copy Markdown

Fixes #5386.

Summary

Fix IndexBinaryIVF::reconstruct_n to write reconstructed binary codes using code_size as the byte stride instead of d, which is the binary dimension in bits.

This matches the documented IndexBinary output layout (ni * d / 8 bytes) and the Python wrapper allocation shape (ni, self.code_size).

Root cause

IndexBinaryIVF::reconstruct_n computed each output pointer as:

recons + (id - i0) * d

For binary indexes, d is measured in bits, so this skipped d bytes per row and left compact Python output rows unwritten, with possible writes past the caller-provided buffer.

Validation

  • Added a regression test for compact IndexBinaryIVF.reconstruct_n(0, 3) output.
  • Verified the new test fails against the pre-fix local extension with only the first row reconstructed.
  • Ran git diff --check -- faiss\IndexBinaryIVF.cpp tests\test_index_binary.py successfully.

I could not complete a local post-fix Python run because this checkout has no local FAISS build and the Python interpreter loads the installed Anaconda faiss package; this environment also lacks cmake and ninja commands for rebuilding the extension.

@meta-cla

meta-cla Bot commented Jul 10, 2026

Copy link
Copy Markdown

Hi @mmnhgo!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexBinaryIVF::reconstruct_n uses d instead of code_size and corrupts binary reconstruction output

2 participants