IVF RaBitQ

View as Markdown

Source header: cuvs/neighbors/ivf_rabitq.hpp

IVF-RaBitQ index build parameters

neighbors::ivf_rabitq::index_params

IVF-RaBitQ index build parameters

1struct index_params : cuvs::neighbors::index_params {
2 uint32_t n_lists;
3 uint32_t bits_per_dim;
4 uint32_t kmeans_n_iters;
5 uint32_t max_train_points_per_cluster;
6 bool fast_quantize_flag;
7 size_t streaming_batch_size;
8 bool force_streaming;
9};

Fields

NameTypeDescription
n_listsuint32_tThe number of inverted lists (clusters)

Hint: Increasing this parameter may alleviate shared memory pressure.
bits_per_dimuint32_tThe total number of bits per dimension (single bit required for the binary RaBitQ algorithm + additional bits for extended RaBitQ).

Supported values: [1, 2, 3, 4, 5, 6, 7, 8, 9].

Hint: the smaller the ‘bits_per_dim’, the smaller the index size and the better the search performance, but the lower the recall.
kmeans_n_itersuint32_tThe number of iterations searching for kmeans centers (index building).
max_train_points_per_clusteruint32_tThe number of data vectors (per cluster) to use during iterative kmeans building.
fast_quantize_flagboolFlag for using the fast quantize method
streaming_batch_sizesize_tMaximum number of vectors per batch when using streaming construction.

This parameter controls the batch size during streaming construction from host memory. Batches contain complete clusters only (no partial clusters across batch boundaries).

Note: Streaming construction is automatically used when the dataset doesn’t fit comfortably in GPU memory (determined by available workspace and kTolerableRatio).
force_streamingboolForce streaming construction regardless of dataset size.

When set to true, streaming construction will be used even if the dataset would fit in GPU memory. This is useful for testing or when you want explicit control over the construction method.

Note: This parameter only applies when the input dataset is in host memory. If the dataset is already in device memory, streaming construction is not applicable and this parameter has no effect.

Default: false (auto-detect based on available memory)

IVF-RaBitQ index search parameters

neighbors::ivf_rabitq::search_mode

A type for specifying the mode for searching the RaBitQ index.

1enum class search_mode {
2 LUT16 = 0,
3 LUT32 = 1,
4 QUANT4 = 2,
5 QUANT8 = 3
6};

Values

NameValue
LUT160
LUT321
QUANT42
QUANT83

IVF-RaBitQ index

neighbors::ivf_rabitq::index

IVF-RaBitQ index.

1template <typename IdxT>
2struct index;

neighbors::ivf_rabitq::index::index

Construct an empty index yet to be populated.

1index(raft::resources const& handle);

Parameters

NameDirectionTypeDescription
handleraft::resources const&

Returns

void

Additional overload: neighbors::ivf_rabitq::index::index

Construct an empty index yet to be populated.

1index(raft::resources const& handle,
2size_t n_rows,
3uint32_t dim,
4uint32_t n_lists,
5uint32_t bits_per_dim);

Parameters

NameDirectionTypeDescription
handleraft::resources const&
n_rowssize_t
dimuint32_t
n_listsuint32_t
bits_per_dimuint32_t

Returns

void

neighbors::ivf_rabitq::index::dim

Dimensionality of the input data.

1uint32_t dim() const noexcept;

Returns

uint32_t

neighbors::ivf_rabitq::index::size

Total length of the index.

1IdxT size() const noexcept;

Returns

IdxT

neighbors::ivf_rabitq::index::rabitq_index

Accessor for underlying RaBitQ index

1detail::IVFGPU& rabitq_index() noexcept;

Returns

detail::IVFGPU&

IVF-RaBitQ index build

neighbors::ivf_rabitq::build

Build the index from the dataset for efficient search.

1auto build(raft::resources const& handle,
2const cuvs::neighbors::ivf_rabitq::index_params& index_params,
3raft::device_matrix_view<const float, int64_t, raft::row_major> dataset)
4-> cuvs::neighbors::ivf_rabitq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
index_paramsinconst cuvs::neighbors::ivf_rabitq::index_params&configure the index building
datasetinraft::device_matrix_view<const float, int64_t, raft::row_major>a device_matrix_view to a row-major matrix [n_rows, dim]

Returns

cuvs::neighbors::ivf_rabitq::index<int64_t>

Additional overload: neighbors::ivf_rabitq::build

Build the index from the dataset for efficient search.

1auto build(raft::resources const& handle,
2const cuvs::neighbors::ivf_rabitq::index_params& index_params,
3raft::host_matrix_view<const float, int64_t, raft::row_major> dataset)
4-> cuvs::neighbors::ivf_rabitq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
index_paramsinconst cuvs::neighbors::ivf_rabitq::index_params&configure the index building
datasetinraft::host_matrix_view<const float, int64_t, raft::row_major>a host_matrix_view to a row-major matrix [n_rows, dim]

Returns

cuvs::neighbors::ivf_rabitq::index<int64_t>

neighbors::ivf_rabitq::search

Search ANN using the constructed index.

1void search(raft::resources const& handle,
2const cuvs::neighbors::ivf_rabitq::search_params& search_params,
3cuvs::neighbors::ivf_rabitq::index<int64_t>& index,
4raft::device_matrix_view<const float, int64_t, raft::row_major> queries,
5raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
6raft::device_matrix_view<float, int64_t, raft::row_major> distances);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
search_paramsinconst cuvs::neighbors::ivf_rabitq::search_params&configure the search
indexincuvs::neighbors::ivf_rabitq::index<int64_t>&ivf-rabitq constructed index
queriesinraft::device_matrix_view<const float, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_queries, index->dim()]
neighborsoutraft::device_matrix_view<int64_t, int64_t, raft::row_major>a device matrix view to the indices of the neighbors in the source dataset [n_queries, k]
distancesoutraft::device_matrix_view<float, int64_t, raft::row_major>a device matrix view to the distances to the selected neighbors [n_queries, k]

Returns

void

IVF-RaBitQ index serialize

neighbors::ivf_rabitq::serialize

Save the index to file.

1void serialize(raft::resources const& handle,
2const std::string& filename,
3cuvs::neighbors::ivf_rabitq::index<int64_t>& index);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&the raft handle
filenameinconst std::string&the file name for saving the index
indexincuvs::neighbors::ivf_rabitq::index<int64_t>&IVF-RaBitQ index

Returns

void

neighbors::ivf_rabitq::deserialize

Load index from file.

1void deserialize(raft::resources const& handle,
2const std::string& filename,
3cuvs::neighbors::ivf_rabitq::index<int64_t>* index);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&the raft handle
filenameinconst std::string&the name of the file that stores the index
indexoutcuvs::neighbors::ivf_rabitq::index<int64_t>*IVF-PQ index

Returns

void