Skip to content

Add QT_0bit to ScalarQuantizer for centroid-only IVF distance (#5079)#5079

Open
mnorris11 wants to merge 1 commit intofacebookresearch:mainfrom
mnorris11:export-D100348052
Open

Add QT_0bit to ScalarQuantizer for centroid-only IVF distance (#5079)#5079
mnorris11 wants to merge 1 commit intofacebookresearch:mainfrom
mnorris11:export-D100348052

Conversation

@mnorris11
Copy link
Copy Markdown
Contributor

@mnorris11 mnorris11 commented Apr 10, 2026

Summary:

Adds a new ScalarQuantizer::QT_0bit type that encodes 0 bits per component, enabling IndexIVFScalarQuantizer to operate in centroid-only distance mode (code_size=0). In this mode, distance_to_code() returns the coarse distance from the quantizer, no per-vector data is stored, and reconstruction returns the centroid vector.

This is useful for IVF configurations where only query-to-centroid distances are needed (e.g., Unicorn's SQ0 use case).

Changes:

  • Add QT_0bit enum to ScalarQuantizer::QuantizerType
  • Add IVFCoarseDistanceScanner that returns coarse_dis from set_list()
  • Handle code_size=0 in encode/decode/reconstruct/add paths
  • Add 'SQ0' to index_factory
  • Force by_residual=false for QT_0bit
  • Guard memcpy in ArrayInvertedLists for code_size=0
  • Handle QT_0bit in index_read.cpp validation switch
  • Add tests for L2, IP, and index_factory

Differential Revision: D100348052

@meta-cla meta-cla bot added the CLA Signed label Apr 10, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Apr 10, 2026

@mnorris11 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100348052.

@meta-codesync meta-codesync bot changed the title Add QT_0bit to ScalarQuantizer for centroid-only IVF distance Add QT_0bit to ScalarQuantizer for centroid-only IVF distance (#5079) Apr 11, 2026
mnorris11 pushed a commit to mnorris11/faiss that referenced this pull request Apr 11, 2026
…okresearch#5079)

Summary:

Adds a new ScalarQuantizer::QT_0bit type that encodes 0 bits per component, enabling IndexIVFScalarQuantizer to operate in centroid-only distance mode (code_size=0). In this mode, distance_to_code() returns the coarse distance from the quantizer, no per-vector data is stored, and reconstruction returns the centroid vector.

This is useful for IVF configurations where only query-to-centroid distances are needed (e.g., Unicorn's SQ0 use case).

Changes:
- Add QT_0bit enum to ScalarQuantizer::QuantizerType
- Add IVFCoarseDistanceScanner that returns coarse_dis from set_list()
- Handle code_size=0 in encode/decode/reconstruct/add paths
- Add 'SQ0' to index_factory
- Force by_residual=false for QT_0bit
- Guard memcpy in ArrayInvertedLists for code_size=0
- Handle QT_0bit in index_read.cpp validation switch
- Add tests for L2, IP, and index_factory
---

Differential Revision: D100348052
@mnorris11 mnorris11 force-pushed the export-D100348052 branch 2 times, most recently from 6b9279c to 98e1c63 Compare April 13, 2026 16:30
mnorris11 pushed a commit to mnorris11/faiss that referenced this pull request Apr 13, 2026
…okresearch#5079)

Summary:

Adds a new ScalarQuantizer::QT_0bit type that encodes 0 bits per component, enabling IndexIVFScalarQuantizer to operate in centroid-only distance mode (code_size=0). In this mode, distance_to_code() returns the coarse distance from the quantizer, no per-vector data is stored, and reconstruction returns the centroid vector.

This is useful for IVF configurations where only query-to-centroid distances are needed (e.g., Unicorn's SQ0 use case).

Changes:
- Add QT_0bit enum to ScalarQuantizer::QuantizerType
- Add IVFCoarseDistanceScanner that returns coarse_dis from set_list()
- Handle code_size=0 in encode/decode/reconstruct/add paths
- Add 'SQ0' to index_factory
- Force by_residual=false for QT_0bit
- Guard memcpy in ArrayInvertedLists for code_size=0
- Handle QT_0bit in index_read.cpp validation switch
- Add tests for L2, IP, and index_factory
---

Differential Revision: D100348052
…okresearch#5079)

Summary:
Pull Request resolved: facebookresearch#5079

Adds a new ScalarQuantizer::QT_0bit type that encodes 0 bits per component, enabling IndexIVFScalarQuantizer to operate in centroid-only distance mode (code_size=0). In this mode, distance_to_code() returns the coarse distance from the quantizer, no per-vector data is stored, and reconstruction returns the centroid vector.

This is useful for IVF configurations where only query-to-centroid distances are needed (e.g., Unicorn's SQ0 use case).

Changes:
- Add QT_0bit enum to ScalarQuantizer::QuantizerType
- Add IVFCoarseDistanceScanner that returns coarse_dis from set_list()
- Handle code_size=0 in encode/decode/reconstruct/add paths
- Add 'SQ0' to index_factory
- Force by_residual=false for QT_0bit
- Guard memcpy in ArrayInvertedLists for code_size=0
- Handle QT_0bit in index_read.cpp validation switch
- Add tests for L2, IP, and index_factory
 ---

Differential Revision: D100348052
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