Skip to content

Add byte-packed IVF RaBitQ fast-scan layout for 4+ bit indexes#5084

Open
lyang24 wants to merge 1 commit intofacebookresearch:mainfrom
lyang24:opt/rabitq-bytepacked-layout-v2
Open

Add byte-packed IVF RaBitQ fast-scan layout for 4+ bit indexes#5084
lyang24 wants to merge 1 commit intofacebookresearch:mainfrom
lyang24:opt/rabitq-bytepacked-layout-v2

Conversation

@lyang24
Copy link
Copy Markdown
Contributor

@lyang24 lyang24 commented Apr 13, 2026

Summary

This PR adds an optional byte-packed multibit layout for IndexIVFRaBitQFastScan when nb_bits >= 4.

The new layout stores ex_code as one byte per dimension and uses dedicated byte-packed multibit distance kernels in the FastScan refinement path. Lower-bit configurations keep the existing bit-packed layout, so nbits=1/2/3 behavior is unchanged.

Format / compatibility

  • existing fast-scan formats Iwrn and Iwrf continue to read through the old bit-packed path
  • new byte-packed indexes use a new Iwrp fourcc
  • Iwrp roundtrip serialization was verified

Performance

On Cohere 1M, single-threaded search, nbits=4:

nprobe bit-packed byte-packed change
32 237 332 +40%
64 169 234 +38%
128 118 138 +17%

Recall is unchanged:

  • nprobe=32: 0.8847
  • nprobe=64: 0.9281
  • nprobe=128: 0.9501

nbits=2 is unchanged.

Notes

  • the byte-packed path is only used for nbits >= 4
  • distance_to_code() is explicitly rejected for byte-packed IVF FastScan indexes, rather than silently using the wrong multibit decoder

Introduce a new Iwrp serialization format for IndexIVFRaBitQFastScan and a byte-packed ex-code path for nb_bits >= 4. This switches multibit refinement to dedicated byte-packed SIMD kernels while leaving the existing bit-packed layout in place for lower-bit configurations.

The new path preserves recall, keeps nbits=2 behavior unchanged, and continues to read older Iwrn/Iwrf indexes. It also guards unsupported distance_to_code usage on byte-packed indexes so the optimization stays confined to the FastScan batch search path.
@meta-cla meta-cla bot added the CLA Signed label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant