Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

alibeklfc
Copy link
Contributor

Summary:
Introduction

This diff implements IndexIVFRaBitQFastScan, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

Implementation

  • New Source and Header Files: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

  • Batched Processing: The new index inherits from IndexIVFFastScan. It processes 32 database vectors simultaneously using SIMD operations.

  • Specialized Post-processing Handler: Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

  • LUT: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.

  • Centered parameter: Implements both centered and non-centered query quantization modes

  • Query Offset Parameter: Added a query offset parameter similarly as in D81787307

Testing

  • Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

  • All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

Results
ivfrabitq2
ivfrabitq1

  • Performance Dependency: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335

@meta-cla meta-cla bot added the CLA Signed label Sep 30, 2025
@facebook-github-bot
Copy link
Contributor

@alibeklfc has exported this pull request. If you are a Meta employee, you can view the originating diff in D83264335.

@alibeklfc alibeklfc changed the title Implementation of IndexIVFRaBitQFastScan IndexIVFRaBitQFastScan and IndexRaBitQFastScan Sep 30, 2025
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

@alibeklfc has exported this pull request. If you are a Meta employee, you can view the originating diff in D83264335.

@alibeklfc alibeklfc changed the title IndexIVFRaBitQFastScan and IndexRaBitQFastScan Implementation of IndexIVFRaBitQFastScan Sep 30, 2025
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

@alibeklfc has exported this pull request. If you are a Meta employee, you can view the originating diff in D83264335.

facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Contributor

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

alibeklfc added a commit that referenced this pull request Sep 30, 2025
Summary:
Pull Request resolved: #4596

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Contributor

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

alibeklfc added a commit that referenced this pull request Sep 30, 2025
Summary:
Pull Request resolved: #4596

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Contributor

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

alibeklfc added a commit that referenced this pull request Sep 30, 2025
Summary:
Pull Request resolved: #4596

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

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

alibeklfc added a commit that referenced this pull request Sep 30, 2025
Summary:
Pull Request resolved: #4596

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
using accu_t = typename C::T;

// Check if this is RaBitQ for specialized distance computation
const IndexRaBitQFastScan* rabitq_index =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This totally violates the fundamentals of object-oriented programming. The base class IndexFastScan must know nothing about a derived class IndexRaBitQFastScan. Please consider reorganizing this.

if (rabitq_index != nullptr) {
// Use RaBitQHeapHandler for RaBitQ (direct processing, no
// post-processing needed)
RaBitQHeapHandler<C> rabitq_handler(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same story here and below

idx_t query_offset = 0) {
// Check if this is IndexIVFRaBitQFastScan and create specialized handler
if (index) {
auto* rabitq_index = dynamic_cast<const IndexIVFRaBitQFastScan*>(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same story about IndexIVFFastScan and IndexIVFRaBitQFastScan

float v_min = std::numeric_limits<float>::max();
float v_max = std::numeric_limits<float>::lowest();

if (centered) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do I get it correct that this is a copy-pasted code from impl/RaBitQuantizer.cpp? This creates a need to synchronize the changes between this code and impl/RaBitQuantizer.cpp. Please reorganize the code to have only 1 instance of these facilities, if possible

@alexanderguzhva
Copy link
Contributor

@alibeklfc I would strongly recommend refactoring the candidate code

facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@facebook-github-bot
Copy link
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Oct 2, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
Copy link

meta-codesync bot commented Oct 2, 2025

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

@alibeklfc
Copy link
Contributor Author

@alexanderguzhva Thank you for your valuable feedback!

I have addressed your comments. The IndexFastScan and IndexIVFFastScan do not know anything about the child classes now. I have made the make_knn_handler function part of the main class and we override it in the child classes.

I have also created the RaBitQUtils namespace to eliminate code duplication.

facebook-github-bot pushed a commit that referenced this pull request Oct 2, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
facebook-github-bot pushed a commit that referenced this pull request Oct 2, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
facebook-github-bot pushed a commit that referenced this pull request Oct 2, 2025
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
Summary:

**Introduction**

This diff adds a new index called the IndexRaBitQFastScan algorithm. The algorithm is based on the existing IndexRaBitQ but achieves higher speed as it processes batches of 32 data vectors concurrently. It leverages the established IndexFastScan architecture to enable efficient batch processing and parallelism.

**Implementation**

* **New Source and Header Files**: Added implementations for IndexRaBitQFastScan, following a similar interface to IndexRaBitQ.

* **Batched Processing**: The search operation processes multiple (32) data vectors in a single batch, taking advantage of low-level parallelism to improve throughput.

* **Specialized Post-processing Handler**:  A dedicated handler was added for IndexRaBitQFastScan to perform necessary post-processing during search because the LUT accumulates only partial distances. Unlike AQ Fast Scan's simple scalar post-processing, RaBitQ requires complex distance adjustments depending on both query and database vector factors.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexRaBitQ due to an extra quantization step in the IndexFastScan architecture. Specifically:
  * The LUT computes a float value as c1 * inner_product + c2 * popcount, which is then quantized. This quantization can cause the results to differ slightly from those of IndexRaBitQ.
  * It is possible to avoid this by storing only the inner_product in the LUT, but doing so would require calculating all data vector popcounts during search, introducing a tradeoff between speed and accuracy.
  * With the idea proposed in diff D80904214, the algorithm can be modified in the future to eliminate the popcount calculation step, potentially improving both efficiency and accuracy.
* **Query Offset Parameter**: RaBitQ uses query factors in distance calculations that should be computed in `compute_float_LUT` method (the most efficient place since we are calculating `rotated_qq` anyways) and used for final distance calculations in handlers. However, the previous version of `compute_quantized_LUT` that calls `compute_float_LUT` did not know the query_offset, preventing proper storage of query factors at their global indices. To solve this, I added the extra parameter `query_offset` to both `compute_quantized_LUT` and `compute_float_LUT` methods. After this change, computed query factors can be accessed by the correct global query index during distance calculations, avoiding expensive recalculation.

**Testing**

* Conducted comprehensive tests in the test_rabitq suite covering accuracy comparisons with IndexRaBitQ for L2 and Inner Product metrics, encoding/decoding consistency, query quantization bit settings, small dataset functionality, performance against PQFastScan, serialization, memory management, error handling, and thread safety.
* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
results_rabitq
* **Performance Dependency**: Performance measurements confirm that IndexRaBitQFastScan is notably faster than IndexRaBitQ when the qb value is high. While the original IndexRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.
* **Parallelized Training Loop**: The training loop is parallelized, greatly reducing training time. This parallelism should also be added to the original IndexRaBitQ.
* **Consistency Across Metrics**: The performance advantages of IndexRaBitQFastScan hold true for both L2 and Inner Product metrics, demonstrating robustness across different distance measures.
* One of the next steps is to benchmark IndexRaBitQFastScan against other algorithms to evaluate its performance in a broader context.

Differential Revision: D81787307
Summary:

**Introduction**

This diff implements `IndexIVFRaBitQFastScan`, a high-performance approximate nearest neighbor search index that combines Inverted File (IVF) partitioning, RaBitQ quantization, and FastScan batch processing for significant performance improvements in vector similarity search.

**Implementation**
* **New Source and Header Files**: Added implementations for IndexIVFRaBitQFastScan, following a similar interface to IndexIVFRaBitQ.

* **Batched Processing**: The new index inherits from `IndexIVFFastScan`. It processes 32 database vectors simultaneously using SIMD operations.

* **Specialized Post-processing Handler**:  Extends the FastScan framework with RaBitQ-aware handler factories that automatically detect and optimize for RaBitQ indices, maintaining compatibility with existing IVF search parameters while enabling specialized optimizations.

* **LUT**: IndexRaBitQFastScan produces slightly different results than IndexIVFRaBitQ due to an extra quantization step in the IndexFastScan architecture. Computes lookup tables using query residuals (query minus coarse centroid) with probe-specific query factors, ensuring accurate distance calculations across different inverted list probes.
* **Centered parameter**: Implements both centered and non-centered query quantization modes

* **Query Offset Parameter**: Added a query offset parameter similarly as in D81787307

**Testing**
* Includes extensive test suite covering performance benchmarks, distance calculation correctness, recall measurements, and cross-validation against reference implementations

* All tests passed successfully, validating the correctness and robustness of IndexRaBitQFastScan.

**Results**
 ivfrabitq2
 ivfrabitq1
* **Performance Dependency**: Performance measurements confirm that IndexIVFRaBitQFastScan is notably faster than IndexIVFRaBitQ when the qb value is high. While the original IndexIVFRaBitQ experiences increased runtime with higher qb values, the fast scan variant maintains consistent runtime regardless of qb.

Differential Revision: D83264335
@alexanderguzhva
Copy link
Contributor

@alibeklfc thanks, let me go through both diffs carefully. Would you like to have #4595 commited prior to #4596?

@alibeklfc
Copy link
Contributor Author

@alexanderguzhva #4595 should be committed before #4596, but I want both of them to commit as soon as possible for benchmarking and internal usage. Thank you!

@alexanderguzhva
Copy link
Contributor

@alibeklfc let's deal with #4595 first, because might need some work

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.

3 participants