IVF PQ

View as Markdown

Source header: cuvs/neighbors/ivf_pq.hpp

IVF-PQ index build parameters

neighbors::ivf_pq::codebook_gen

A type for specifying how PQ codebooks are created.

1enum class codebook_gen { ... };

neighbors::ivf_pq::list_layout

A type for specifying the memory layout of PQ codes in IVF lists.

1enum class list_layout { ... };

neighbors::ivf_pq::index_params::from_dataset

Creates index_params based on shape of the input dataset.

1static index_params from_dataset(
2raft::matrix_extent<int64_t> dataset,
3cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Expanded);

Usage example:

Parameters

NameDirectionTypeDescription
datasetraft::matrix_extent<int64_t>
metriccuvs::distance::DistanceTypeDefault: cuvs::distance::DistanceType::L2Expanded.

Returns

static index_params

IVF-PQ index search parameters

neighbors::ivf_pq::search_params

IVF-PQ index search parameters

1struct search_params : cuvs::neighbors::search_params { ... };

Fields

NameTypeDescription
n_probesuint32_tThe number of clusters to search.
lut_dtypecudaDataType_tData type of look up table to be created dynamically at search time. Possible values: [CUDA_R_32F, CUDA_R_16F, CUDA_R_8U] The use of low-precision types reduces the amount of shared memory required at search time, so fast shared memory kernels can be used even for datasets with large dimansionality. Note that the recall is slightly degraded when low-precision type is selected.
internal_distance_dtypecudaDataType_tStorage data type for distance/similarity computed at search time. Possible values: [CUDA_R_16F, CUDA_R_32F] If the performance limiter at search time is device memory access, selecting FP16 will improve performance slightly.
preferred_shmem_carveoutdoublePreferred fraction of SM’s unified memory / L1 cache to be used as shared memory. Possible values: [0.0 - 1.0] as a fraction of the sharedMemPerMultiprocessor. One wants to increase the carveout to make sure a good GPU occupancy for the main search kernel, but not to keep it too high to leave some memory to be used as L1 cache. Note, this value is interpreted only as a hint. Moreover, a GPU usually allows only a fixed set of cache configurations, so the provided value is rounded up to the nearest configuration. Refer to the NVIDIA tuning guide for the target GPU architecture. Note, this is a low-level tuning parameter that can have drastic negative effects on the search performance if tweaked incorrectly.
coarse_search_dtypecudaDataType_t[Experimental] The data type to use as the GEMM element type when searching the clusters to probe. Possible values: [CUDA_R_8I, CUDA_R_16F, CUDA_R_32F].
- Legacy default: CUDA_R_32F (float)
- Recommended for performance: CUDA_R_16F (half)
- Experimental/low-precision: CUDA_R_8I (int8_t) (WARNING: int8_t variant degrades recall unless data is normalized and low-dimensional)
max_internal_batch_sizeuint32_tSet the internal batch size to improve GPU utilization at the cost of larger memory footprint.

Types

list_extents

PQ-encoded data stored in the interleaved format:

1using list_extents = raft::
2extents<SizeT, raft::dynamic_extent, raft::dynamic_extent, kIndexGroupSize, kIndexGroupVecLen>;

neighbors::ivf_pq::list_spec_flat

Flat (non-interleaved) storage specification for PQ-encoded data.

This stores each vector’s PQ codes contiguously: [n_rows, bytes_per_vector] where bytes_per_vector = ceildiv(pq_dim * pq_bits, 8)

1template <typename SizeT, typename IdxT>
2struct list_spec_flat { ... };

Fields

NameTypeDescription
align_maxSizeT
align_minSizeT
pq_bitsuint32_t
pq_dimuint32_t

neighbors::graph_build_params::ivf_pq_params

Specialized parameters utilizing IVF-PQ to build knn graph

1struct ivf_pq_params { ... };

Fields

NameTypeDescription
build_paramscuvs::neighbors::ivf_pq::index_params
search_paramscuvs::neighbors::ivf_pq::
refinement_ratefloat

IVF-PQ index

neighbors::ivf_pq::index

IVF-PQ index.

In the IVF-PQ index, a database vector y is approximated with two level quantization:

y = Q_1(y) + Q_2(y - Q_1(y))

The first level quantizer (Q_1), maps the vector y to the nearest cluster center. The number of clusters is n_lists.

The second quantizer encodes the residual, and it is defined as a product quantizer [1].

A product quantizer encodes a dim dimensional vector with a pq_dim dimensional vector. First we split the input vector into pq_dim subvectors (denoted by u), where each u vector contains pq_len distinct components of y

y_1, y_2, … y_{pq_len}, y_{pq_len+1}, … y_{2*pq_len}, … y_{dim-pq_len+1} … y_{dim} u_1 u_2 u_{pq_dim}

Then each subvector encoded with a separate quantizer q_i, end the results are concatenated

Q_2(y) = q_1(u_1),q_2(u_2),…,q_{pq_dim}(u_pq_dim})

Each quantizer q_i outputs a code with pq_bit bits. The second level quantizers are also defined by k-means clustering in the corresponding sub-space: the reproduction values are the centroids, and the set of reproduction values is the codebook.

When the data dimensionality dim is not multiple of pq_dim, the feature space is transformed using a random orthogonal matrix to have rot_dim = pq_dim * pq_len dimensions (rot_dim &gt;= dim).

The second-level quantizers are trained either for each subspace or for each cluster: (a) codebook_gen::PER_SUBSPACE: creates pq_dim second-level quantizers - one for each slice of the data along features; (b) codebook_gen::PER_CLUSTER: creates n_lists second-level quantizers - one for each first-level cluster. In either case, the centroids are again found using k-means clustering interpreting the data as having pq_len dimensions.

[1] Product quantization for nearest neighbor search Herve Jegou, Matthijs Douze, Cordelia Schmid

1template <typename IdxT>
2class index : public index_iface<IdxT>, cuvs::neighbors::index { ... };

neighbors::ivf_pq::index::index

Construct an empty index.

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

Constructs an empty index. This index will either need to be trained with build or loaded from a saved copy with deserialize

Parameters

NameDirectionTypeDescription
handleraft::resources const&

Returns

void

Additional overload: neighbors::ivf_pq::index::index

Construct an index with specified parameters.

1index(raft::resources const& handle,
2cuvs::distance::DistanceType metric,
3codebook_gen codebook_kind,
4uint32_t n_lists,
5uint32_t dim,
6uint32_t pq_bits = 8,
7uint32_t pq_dim = 0,
8bool conservative_memory_allocation = false);

This constructor creates an owning index with the given parameters.

Parameters

NameDirectionTypeDescription
handleraft::resources const&RAFT resources handle
metriccuvs::distance::DistanceTypeDistance metric for clustering
codebook_kindcodebook_genHow PQ codebooks are created
n_listsuint32_tNumber of inverted lists (clusters)
dimuint32_tDimensionality of the input data
pq_bitsuint32_tBit length of vector elements after PQ compression Default: 8.
pq_dimuint32_tDimensionality after PQ compression (0 = auto-select) Default: 0.
conservative_memory_allocationboolMemory allocation strategy Default: false.

Returns

void

Additional overload: neighbors::ivf_pq::index::index

Construct an index from index parameters.

1index(raft::resources const& handle, const index_params& params, uint32_t dim);

Parameters

NameDirectionTypeDescription
handleraft::resources const&RAFT resources handle
paramsconst index_params&Index parameters
dimuint32_tDimensionality of the input data

Returns

void

neighbors::ivf_pq::index::size

Total length of the index.

1IdxT size() const noexcept override;

Returns

IdxT

neighbors::ivf_pq::index::dim

Dimensionality of the input data.

1uint32_t dim() const noexcept override;

Returns

uint32_t

neighbors::ivf_pq::index::dim_ext

Dimensionality of the cluster centers:

1uint32_t dim_ext() const noexcept;

input data dim extended with vector norms and padded to 8 elems.

Returns

uint32_t

neighbors::ivf_pq::index::rot_dim

Dimensionality of the data after transforming it for PQ processing

1uint32_t rot_dim() const noexcept;

(rotated and augmented to be muplitple of pq_dim).

Returns

uint32_t

neighbors::ivf_pq::index::pq_bits

The bit length of an encoded vector element after compression by PQ.

1uint32_t pq_bits() const noexcept override;

Returns

uint32_t

neighbors::ivf_pq::index::pq_dim

The dimensionality of an encoded vector after compression by PQ.

1uint32_t pq_dim() const noexcept override;

Returns

uint32_t

neighbors::ivf_pq::index::pq_len

Dimensionality of a subspace, i.e. the number of vector components mapped to a subspace

1uint32_t pq_len() const noexcept;

Returns

uint32_t

neighbors::ivf_pq::index::pq_book_size

The number of vectors in a PQ codebook (1 &lt;&lt; pq_bits).

1uint32_t pq_book_size() const noexcept;

Returns

uint32_t

neighbors::ivf_pq::index::metric

Distance metric used for clustering.

1cuvs::distance::DistanceType metric() const noexcept override;

Returns

cuvs::distance::DistanceType

neighbors::ivf_pq::index::codebook_kind

How PQ codebooks are created.

1codebook_gen codebook_kind() const noexcept override;

Returns

codebook_gen

neighbors::ivf_pq::index::codes_layout

Memory layout of PQ codes in IVF lists.

1list_layout codes_layout() const noexcept override;

Returns

list_layout

neighbors::ivf_pq::index::n_lists

Number of clusters/inverted lists (first level quantization).

1uint32_t n_lists() const noexcept;

Returns

uint32_t

neighbors::ivf_pq::index::conservative_memory_allocation

Whether to use conservative memory allocation when extending the list (cluster) data

1bool conservative_memory_allocation() const noexcept override;

(see index_params.conservative_memory_allocation).

Returns

bool

neighbors::ivf_pq::index::pq_centers

PQ cluster centers

1raft::device_mdspan<const float, pq_centers_extents, raft::row_major> pq_centers()
2const noexcept override;
  • codebook_gen::PER_SUBSPACE: [pq_dim , pq_len, pq_book_size]
  • codebook_gen::PER_CLUSTER: [n_lists, pq_len, pq_book_size]

Returns

raft::device_mdspan<const float, pq_centers_extents, raft::row_major>

neighbors::ivf_pq::index::lists

Lists’ data and indices (polymorphic, works for both FLAT and INTERLEAVED layouts).

1std::vector<std::shared_ptr<list_data_base<IdxT>>>& lists() noexcept override;

Returns

std::vector<std::shared_ptr<list_data_base<IdxT>>>&

neighbors::ivf_pq::index::data_ptrs

Pointers to the inverted lists (clusters) data [n_lists].

1raft::device_vector_view<uint8_t*, uint32_t, raft::row_major> data_ptrs() noexcept override;

Returns

raft::device_vector_view<uint8_t*, uint32_t, raft::row_major>

neighbors::ivf_pq::index::inds_ptrs

Pointers to the inverted lists (clusters) indices [n_lists].

1raft::device_vector_view<IdxT*, uint32_t, raft::row_major> inds_ptrs() noexcept override;

Returns

raft::device_vector_view<IdxT*, uint32_t, raft::row_major>

neighbors::ivf_pq::index::rotation_matrix

The transform matrix (original space -> rotated padded space) [rot_dim, dim]

1raft::device_matrix_view<const float, uint32_t, raft::row_major> rotation_matrix()
2const noexcept override;

Returns

raft::device_matrix_view<const float, uint32_t, raft::row_major>

neighbors::ivf_pq::index::accum_sorted_sizes

Accumulated list sizes, sorted in descending order [n_lists + 1].

1raft::host_vector_view<IdxT, uint32_t, raft::row_major> accum_sorted_sizes() noexcept override;

The last value contains the total length of the index. The value at index zero is always zero.

That is, the content of this span is as if the list_sizes was sorted and then accumulated.

This span is used during search to estimate the maximum size of the workspace.

Returns

raft::host_vector_view<IdxT, uint32_t, raft::row_major>

neighbors::ivf_pq::index::list_sizes

Sizes of the lists [n_lists].

1raft::device_vector_view<uint32_t, uint32_t, raft::row_major> list_sizes() noexcept override;

Returns

raft::device_vector_view<uint32_t, uint32_t, raft::row_major>

neighbors::ivf_pq::index::centers

Cluster centers corresponding to the lists in the original space [n_lists, dim_ext]

1raft::device_matrix_view<const float, uint32_t, raft::row_major> centers()
2const noexcept override;

Returns

raft::device_matrix_view<const float, uint32_t, raft::row_major>

neighbors::ivf_pq::index::centers_rot

Cluster centers corresponding to the lists in the rotated space [n_lists, rot_dim]

1raft::device_matrix_view<const float, uint32_t, raft::row_major> centers_rot()
2const noexcept override;

Returns

raft::device_matrix_view<const float, uint32_t, raft::row_major>

neighbors::ivf_pq::index::get_list_size_in_bytes

fetch size of a particular IVF list in bytes using the list extents.

1uint32_t get_list_size_in_bytes(uint32_t label) const override;

Usage example:

Parameters

NameDirectionTypeDescription
labelinuint32_tlist ID

Returns

uint32_t

Additional overload: neighbors::ivf_pq::index::index

Construct index from implementation pointer.

1explicit index(std::unique_ptr<index_iface<IdxT>> impl);

This constructor is used internally by build/extend/deserialize functions.

Parameters

NameDirectionTypeDescription
implstd::unique_ptr<index_iface<IdxT>>Implementation pointer (owning or view)

Returns

explicit

IVF-PQ index build

neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
index_paramsinconst cuvs::neighbors::ivf_pq::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_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::device_matrix_view<const float, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::device_matrix_view<const half, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::device_matrix_view<const int8_t, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
index_paramsinconst cuvs::neighbors::ivf_pq::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_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::host_matrix_view<const float, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::host_matrix_view<const half, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::host_matrix_view<const int8_t, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

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

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

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

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build the index from the dataset for efficient search.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> dataset,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

NB: Currently, the following distance metrics are supported:

  • L2Expanded
  • L2Unexpanded
  • InnerProduct
  • CosineExpanded

Note, if index_params.add_data_on_build is set to true, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

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

Returns

void

Additional overload: neighbors::ivf_pq::build

Build a view-type IVF-PQ index from device memory centroids and codebook.

1auto build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3const uint32_t dim,
4raft::device_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major> pq_centers,
5raft::device_matrix_view<const float, uint32_t, raft::row_major> centers,
6raft::device_matrix_view<const float, uint32_t, raft::row_major> centers_rot,
7raft::device_matrix_view<const float, uint32_t, raft::row_major> rotation_matrix)
8-> cuvs::neighbors::ivf_pq::index<int64_t>;

This function creates a non-owning index that stores a reference to the provided device data. All parameters must be provided with correct extents. The caller is responsible for ensuring the lifetime of the input data exceeds the lifetime of the returned index.

The index_params must be consistent with the provided matrices. Specifically:

  • index_params.codebook_kind determines the expected shape of pq_centers
  • index_params.metric will be stored in the index
  • index_params.conservative_memory_allocation will be stored in the index The function will verify consistency between index_params, dim, and the matrix extents.

dim]

Parameters

NameDirectionTypeDescription
handleinraft::resources const&raft resources handle
index_paramsinconst cuvs::neighbors::ivf_pq::index_params&configure the index (metric, codebook_kind, etc.). Must be consistent with the provided matrices.
diminconst uint32_tdimensionality of the input data
pq_centersinraft::device_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major>PQ codebook on device memory with required extents:
- codebook_gen::PER_SUBSPACE: [pq_dim, pq_len, pq_book_size]
- codebook_gen::PER_CLUSTER: [n_lists, pq_len, pq_book_size]
centersinraft::device_matrix_view<const float, uint32_t, raft::row_major>Cluster centers in the original space [n_lists, dim_ext] where dim_ext = round_up(dim + 1, 8)
centers_rotinraft::device_matrix_view<const float, uint32_t, raft::row_major>Rotated cluster centers [n_lists, rot_dim] where rot_dim = pq_len * pq_dim
rotation_matrixinraft::device_matrix_view<const float, uint32_t, raft::row_major>Transform matrix (original space -> rotated padded space) [rot_dim,

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build an IVF-PQ index from device memory centroids and codebook.

1void build(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index_params& index_params,
3const uint32_t dim,
4raft::device_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major> pq_centers,
5raft::device_matrix_view<const float, uint32_t, raft::row_major> centers,
6raft::device_matrix_view<const float, uint32_t, raft::row_major> centers_rot,
7raft::device_matrix_view<const float, uint32_t, raft::row_major> rotation_matrix,
8cuvs::neighbors::ivf_pq::index<int64_t>* idx);

This function creates a non-owning index that references the provided device data directly. All parameters must be provided with correct extents. The caller is responsible for ensuring the lifetime of the input data exceeds the lifetime of the returned index.

The index_params must be consistent with the provided matrices. Specifically:

  • index_params.codebook_kind determines the expected shape of pq_centers
  • index_params.metric will be stored in the index
  • index_params.conservative_memory_allocation will be stored in the index The function will verify consistency between index_params, dim, and the matrix extents.

dim]

Parameters

NameDirectionTypeDescription
handleinraft::resources const&raft resources handle
index_paramsinconst cuvs::neighbors::ivf_pq::index_params&configure the index (metric, codebook_kind, etc.). Must be consistent with the provided matrices.
diminconst uint32_tdimensionality of the input data
pq_centersinraft::device_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major>PQ codebook on device memory with required extents:
- codebook_gen::PER_SUBSPACE: [pq_dim, pq_len, pq_book_size]
- codebook_gen::PER_CLUSTER: [n_lists, pq_len, pq_book_size]
centersinraft::device_matrix_view<const float, uint32_t, raft::row_major>Cluster centers in the original space [n_lists, dim_ext] where dim_ext = round_up(dim + 1, 8)
centers_rotinraft::device_matrix_view<const float, uint32_t, raft::row_major>Rotated cluster centers [n_lists, rot_dim] where rot_dim = pq_len * pq_dim
rotation_matrixinraft::device_matrix_view<const float, uint32_t, raft::row_major>Transform matrix (original space -> rotated padded space) [rot_dim,
idxoutcuvs::neighbors::ivf_pq::index<int64_t>*pointer to ivf_pq::index

Returns

void

Additional overload: neighbors::ivf_pq::build

Build an IVF-PQ index from host memory centroids and codebook (in-place).

1auto build(
2raft::resources const& handle,
3const cuvs::neighbors::ivf_pq::index_params& index_params,
4const uint32_t dim,
5raft::host_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major> pq_centers,
6raft::host_matrix_view<const float, uint32_t, raft::row_major> centers,
7std::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>> centers_rot,
8std::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>> rotation_matrix)
9-> cuvs::neighbors::ivf_pq::index<int64_t>;

Parameters

NameDirectionTypeDescription
handleinraft::resources const&raft resources handle
index_paramsinconst cuvs::neighbors::ivf_pq::index_params&configure the index building
diminconst uint32_tdimensionality of the input data
pq_centersinraft::host_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major>PQ codebook
centersinraft::host_matrix_view<const float, uint32_t, raft::row_major>Cluster centers
centers_rotinstd::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>>Optional rotated cluster centers
rotation_matrixinstd::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>>Optional rotation matrix

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::build

Build an IVF-PQ index from host memory centroids and codebook (in-place).

1void build(
2raft::resources const& handle,
3const cuvs::neighbors::ivf_pq::index_params& index_params,
4const uint32_t dim,
5raft::host_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major> pq_centers,
6raft::host_matrix_view<const float, uint32_t, raft::row_major> centers,
7std::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>> centers_rot,
8std::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>> rotation_matrix,
9cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&raft resources handle
index_paramsinconst cuvs::neighbors::ivf_pq::index_params&configure the index building
diminconst uint32_tdimensionality of the input data
pq_centersinraft::host_mdspan<const float, raft::extent_3d<uint32_t>, raft::row_major>PQ codebook on host memory
centersinraft::host_matrix_view<const float, uint32_t, raft::row_major>Cluster centers on host memory
centers_rotinstd::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>>Optional rotated cluster centers on host
rotation_matrixinstd::optional<raft::host_matrix_view<const float, uint32_t, raft::row_major>>Optional rotation matrix on host
idxoutcuvs::neighbors::ivf_pq::index<int64_t>*pointer to IVF-PQ index to be built

Returns

void

IVF-PQ index extend

neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::device_matrix_view<const float, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const float, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::device_matrix_view<const float, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const float, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::device_matrix_view<const half, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const half, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::device_matrix_view<const half, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const half, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::device_matrix_view<const int8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const int8_t, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::device_matrix_view<const int8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const int8_t, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const uint8_t, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::device_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::device_matrix_view<const uint8_t, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::device_vector_view<const int64_t, int64_t>>a device vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::host_matrix_view<const float, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const float, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::host_matrix_view<const float, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const float, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::host_matrix_view<const half, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const half, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::host_matrix_view<const half, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const half, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::host_matrix_view<const int8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const int8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::host_matrix_view<const int8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const int8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1auto extend(raft::resources const& handle,
2raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4const cuvs::neighbors::ivf_pq::index<int64_t>& idx)
5-> cuvs::neighbors::ivf_pq::index<int64_t>;

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const uint8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutconst cuvs::neighbors::ivf_pq::index<int64_t>&

Returns

cuvs::neighbors::ivf_pq::index<int64_t>

Additional overload: neighbors::ivf_pq::extend

Extend the index with the new data.

1void extend(raft::resources const& handle,
2raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> new_vectors,
3std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices,
4cuvs::neighbors::ivf_pq::index<int64_t>* idx);

Note, the user can set a stream pool in the input raft::resource with at least one stream to enable kernel and copy overlapping.

Usage example:

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
new_vectorsinraft::host_matrix_view<const uint8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, idx.dim()]
new_indicesinstd::optional<raft::host_vector_view<const int64_t, int64_t>>a host vector view to a vector of indices [n_rows]. If the original index is empty (idx.size() == 0), you can pass std::nullopt here to imply a continuous range [0...n_rows).
idxinoutcuvs::neighbors::ivf_pq::index<int64_t>*

Returns

void

IVF-PQ index transform

neighbors::ivf_pq::transform

Transform a dataset by applying pq-encoding to each vector

1void transform(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index<int64_t>& index,
3raft::device_matrix_view<const float, int64_t, raft::row_major> dataset,
4raft::device_vector_view<uint32_t, int64_t> output_labels,
5raft::device_matrix_view<uint8_t, int64_t> output_dataset);

cluster ids (labels) for each vector in the input dataset index.pq_bits(), 8)]] that will get populated with the pq-encoded dataset

Parameters

NameDirectionTypeDescription
handleinraft::resources const&
indexinconst cuvs::neighbors::ivf_pq::index<int64_t>&ivf-pq constructed index
datasetinraft::device_matrix_view<const float, int64_t, raft::row_major>a device matrix view to a row-major matrix [n_rows, index.dim()]
output_labelsoutraft::device_vector_view<uint32_t, int64_t>a device vector view [n_rows] that will get populaterd with the
output_datasetoutraft::device_matrix_view<uint8_t, int64_t>a device matrix view [n_rows, ceildiv(index.pq_dim() *

Returns

void

Additional overload: neighbors::ivf_pq::transform

1void transform(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index<int64_t>& index,
3raft::device_matrix_view<const half, int64_t, raft::row_major> dataset,
4raft::device_vector_view<uint32_t, int64_t> output_labels,
5raft::device_matrix_view<uint8_t, int64_t> output_dataset);

Parameters

NameDirectionTypeDescription
handleraft::resources const&
indexconst cuvs::neighbors::ivf_pq::index<int64_t>&
datasetraft::device_matrix_view<const half, int64_t, raft::row_major>
output_labelsraft::device_vector_view<uint32_t, int64_t>
output_datasetraft::device_matrix_view<uint8_t, int64_t>

Returns

void

Additional overload: neighbors::ivf_pq::transform

1void transform(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index<int64_t>& index,
3raft::device_matrix_view<const int8_t, int64_t, raft::row_major> dataset,
4raft::device_vector_view<uint32_t, int64_t> output_labels,
5raft::device_matrix_view<uint8_t, int64_t> output_dataset);

Parameters

NameDirectionTypeDescription
handleraft::resources const&
indexconst cuvs::neighbors::ivf_pq::index<int64_t>&
datasetraft::device_matrix_view<const int8_t, int64_t, raft::row_major>
output_labelsraft::device_vector_view<uint32_t, int64_t>
output_datasetraft::device_matrix_view<uint8_t, int64_t>

Returns

void

Additional overload: neighbors::ivf_pq::transform

1void transform(raft::resources const& handle,
2const cuvs::neighbors::ivf_pq::index<int64_t>& index,
3raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> dataset,
4raft::device_vector_view<uint32_t, int64_t> output_labels,
5raft::device_matrix_view<uint8_t, int64_t> output_dataset);

Parameters

NameDirectionTypeDescription
handleraft::resources const&
indexconst cuvs::neighbors::ivf_pq::index<int64_t>&
datasetraft::device_matrix_view<const uint8_t, int64_t, raft::row_major>
output_labelsraft::device_vector_view<uint32_t, int64_t>
output_datasetraft::device_matrix_view<uint8_t, int64_t>

Returns

void

IVF-PQ index serialize

neighbors::ivf_pq::serialize

Write the index to an output stream

1void serialize(raft::resources const& handle,
2std::ostream& os,
3const cuvs::neighbors::ivf_pq::index<int64_t>& index);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&the raft handle
osinstd::ostream&output stream
indexinconst cuvs::neighbors::ivf_pq::index<int64_t>&IVF-PQ index

Returns

void

Additional overload: neighbors::ivf_pq::serialize

Save the index to file.

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

Parameters

NameDirectionTypeDescription
handleinraft::resources const&the raft handle
filenameinconst std::string&the file name for saving the index
indexinconst cuvs::neighbors::ivf_pq::index<int64_t>&IVF-PQ index

Returns

void

neighbors::ivf_pq::deserialize

Load index from input stream

1void deserialize(raft::resources const& handle,
2std::istream& str,
3cuvs::neighbors::ivf_pq::index<int64_t>* index);

Parameters

NameDirectionTypeDescription
handleinraft::resources const&the raft handle
strinstd::istream&the name of the file that stores the index
indexoutcuvs::neighbors::ivf_pq::index<int64_t>*IVF-PQ index

Returns

void

Additional overload: neighbors::ivf_pq::deserialize

Load index from file.

1void deserialize(raft::resources const& handle,
2const std::string& filename,
3cuvs::neighbors::ivf_pq::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_pq::index<int64_t>*IVF-PQ index

Returns

void

IVF-PQ helper methods

neighbors::ivf_pq::helpers::codepacker::unpack

Unpack n_take consecutive records of a single list (cluster) in the compressed index

1void unpack(raft::resources const& res,
2raft::device_mdspan<const uint8_t,
3list_spec_interleaved<uint32_t, uint32_t>::list_extents,
4raft::row_major> list_data,
5uint32_t pq_bits,
6uint32_t offset,
7raft::device_matrix_view<uint8_t, uint32_t, raft::row_major> codes);

starting at given offset.

Bit compression is removed, which means output will have pq_dim dimensional vectors (one code per byte, instead of ceildiv(pq_dim * pq_bits, 8) bytes of pq codes).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
list_datainraft::device_mdspan<const uint8_t, list_spec_interleaved<uint32_t, uint32_t>::list_extents, raft::row_major>block to read from
pq_bitsinuint32_tbit length of encoded vector elements
offsetinuint32_tHow many records in the list to skip.
codesoutraft::device_matrix_view<uint8_t, uint32_t, raft::row_major>the destination buffer [n_take, index.pq_dim()]. The length n_take defines how many records to unpack, it must be smaller than the list size.

Returns

void

neighbors::ivf_pq::helpers::codepacker::unpack_contiguous

Unpack n_rows consecutive records of a single list (cluster) in the compressed index

1void unpack_contiguous(raft::resources const& res,
2raft::device_mdspan<const uint8_t,
3list_spec_interleaved<uint32_t, uint32_t>::list_extents,
4raft::row_major> list_data,
5uint32_t pq_bits,
6uint32_t offset,
7uint32_t n_rows,
8uint32_t pq_dim,
9uint8_t* codes);

starting at given offset. The output codes of a single vector are contiguous, not expanded to one code per byte, which means the output has ceildiv(pq_dim * pq_bits, 8) bytes per PQ encoded vector.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
list_datainraft::device_mdspan<const uint8_t, list_spec_interleaved<uint32_t, uint32_t>::list_extents, raft::row_major>block to read from
pq_bitsinuint32_tbit length of encoded vector elements
offsetinuint32_tHow many records in the list to skip.
n_rowsinuint32_tHow many records to unpack
pq_diminuint32_tThe dimensionality of the PQ compressed records
codesoutuint8_t*the destination buffer [n_rows, ceildiv(pq_dim * pq_bits, 8)]. The length n_rows defines how many records to unpack, it must be smaller than the list size.

Returns

void

neighbors::ivf_pq::helpers::codepacker::pack

Write flat PQ codes into an existing list by the given offset.

1void pack(raft::resources const& res,
2raft::device_matrix_view<const uint8_t, uint32_t, raft::row_major> codes,
3uint32_t pq_bits,
4uint32_t offset,
5raft::device_mdspan<uint8_t,
6list_spec_interleaved<uint32_t, uint32_t>::list_extents,
7raft::row_major> list_data);

NB: no memory allocation happens here; the list must fit the data (offset + n_vec).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
codesinraft::device_matrix_view<const uint8_t, uint32_t, raft::row_major>flat PQ codes, one code per byte [n_vec, pq_dim]
pq_bitsinuint32_tbit length of encoded vector elements
offsetinuint32_thow many records to skip before writing the data into the list
list_datainraft::device_mdspan<uint8_t, list_spec_interleaved<uint32_t, uint32_t>::list_extents, raft::row_major>block to write into

Returns

void

neighbors::ivf_pq::helpers::codepacker::pack_contiguous

Write flat PQ codes into an existing list by the given offset. The input codes of a single vector

1void pack_contiguous(raft::resources const& res,
2const uint8_t* codes,
3uint32_t n_rows,
4uint32_t pq_dim,
5uint32_t pq_bits,
6uint32_t offset,
7raft::device_mdspan<uint8_t,
8list_spec_interleaved<uint32_t, uint32_t>::list_extents,
9raft::row_major> list_data);

are contiguous (not expanded to one code per byte).

NB: no memory allocation happens here; the list must fit the data (offset + n_rows records).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
codesinconst uint8_t*flat PQ codes, [n_vec, ceildiv(pq_dim * pq_bits, 8)]
n_rowsinuint32_tnumber of records
pq_diminuint32_t
pq_bitsinuint32_tbit length of encoded vector elements
offsetinuint32_thow many records to skip before writing the data into the list
list_datainraft::device_mdspan<uint8_t, list_spec_interleaved<uint32_t, uint32_t>::list_extents, raft::row_major>block to write into

Returns

void

neighbors::ivf_pq::helpers::codepacker::pack_list_data

Write flat PQ codes into an existing list by the given offset.

1void pack_list_data(raft::resources const& res,
2index<int64_t>* index,
3raft::device_matrix_view<const uint8_t, uint32_t, raft::row_major> codes,
4uint32_t label,
5uint32_t offset);

The list is identified by its label.

NB: no memory allocation happens here; the list must fit the data (offset + n_vec).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
indexinoutindex<int64_t>*IVF-PQ index.
codesinraft::device_matrix_view<const uint8_t, uint32_t, raft::row_major>flat PQ codes, one code per byte [n_rows, pq_dim]
labelinuint32_tThe id of the list (cluster) into which we write.
offsetinuint32_thow many records to skip before writing the data into the list

Returns

void

neighbors::ivf_pq::helpers::codepacker::pack_contiguous_list_data

Write flat PQ codes into an existing list by the given offset. Use this when the input

1void pack_contiguous_list_data(raft::resources const& res,
2index<int64_t>* index,
3uint8_t* codes,
4uint32_t n_rows,
5uint32_t label,
6uint32_t offset);

vectors are PQ encoded and not expanded to one code per byte.

The list is identified by its label.

NB: no memory allocation happens here; the list into which the vectors are packed must fit offset + n_rows rows.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
indexinoutindex<int64_t>*pointer to IVF-PQ index
codesinuint8_t*flat contiguous PQ codes [n_rows, ceildiv(pq_dim * pq_bits, 8)]
n_rowsinuint32_thow many records to pack
labelinuint32_tThe id of the list (cluster) into which we write.
offsetinuint32_thow many records to skip before writing the data into the list

Returns

void

neighbors::ivf_pq::helpers::codepacker::unpack_list_data

Unpack n_take consecutive records of a single list (cluster) in the compressed index

1void unpack_list_data(raft::resources const& res,
2const index<int64_t>& index,
3raft::device_matrix_view<uint8_t, uint32_t, raft::row_major> out_codes,
4uint32_t label,
5uint32_t offset);

starting at given offset, one code per byte (independently of pq_bits).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinconst index<int64_t>&
out_codesoutraft::device_matrix_view<uint8_t, uint32_t, raft::row_major>the destination buffer [n_take, index.pq_dim()]. The length n_take defines how many records to unpack, it must be smaller than the list size.
labelinuint32_tThe id of the list (cluster) to decode.
offsetinuint32_tHow many records in the list to skip.

Returns

void

Additional overload: neighbors::ivf_pq::helpers::codepacker::unpack_list_data

Unpack a series of records of a single list (cluster) in the compressed index

1void unpack_list_data(raft::resources const& res,
2const index<int64_t>& index,
3raft::device_vector_view<const uint32_t> in_cluster_indices,
4raft::device_matrix_view<uint8_t, uint32_t, raft::row_major> out_codes,
5uint32_t label);

by their in-list offsets, one code per byte (independently of pq_bits).

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
indexinconst index<int64_t>&IVF-PQ index (passed by reference)
in_cluster_indicesinraft::device_vector_view<const uint32_t>The offsets of the selected indices within the cluster.
out_codesoutraft::device_matrix_view<uint8_t, uint32_t, raft::row_major>the destination buffer [n_take, index.pq_dim()]. The length n_take defines how many records to unpack, it must be smaller than the list size.
labelinuint32_tThe id of the list (cluster) to decode.

Returns

void

neighbors::ivf_pq::helpers::codepacker::unpack_contiguous_list_data

Unpack n_rows consecutive PQ encoded vectors of a single list (cluster) in the

1void unpack_contiguous_list_data(raft::resources const& res,
2const index<int64_t>& index,
3uint8_t* out_codes,
4uint32_t n_rows,
5uint32_t label,
6uint32_t offset);

compressed index starting at given offset, not expanded to one code per byte. Each code in the output buffer occupies ceildiv(index.pq_dim() * index.pq_bits(), 8) bytes.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
indexinconst index<int64_t>&IVF-PQ index (passed by reference)
out_codesoutuint8_t*the destination buffer [n_rows, ceildiv(index.pq_dim() * index.pq_bits(), 8)]. The length n_rows defines how many records to unpack, offset + n_rows must be smaller than or equal to the list size.
n_rowsinuint32_thow many codes to unpack
labelinuint32_tThe id of the list (cluster) to decode.
offsetinuint32_tHow many records in the list to skip.

Returns

void

neighbors::ivf_pq::helpers::codepacker::reconstruct_list_data

Decode n_take consecutive records of a single list (cluster) in the compressed index

1void reconstruct_list_data(raft::resources const& res,
2const index<int64_t>& index,
3raft::device_matrix_view<float, uint32_t, raft::row_major> out_vectors,
4uint32_t label,
5uint32_t offset);

starting at given offset.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinconst index<int64_t>&
out_vectorsoutraft::device_matrix_view<float, uint32_t, raft::row_major>the destination buffer [n_take, index.dim()]. The length n_take defines how many records to reconstruct, it must be smaller than the list size.
labelinuint32_tThe id of the list (cluster) to decode.
offsetinuint32_tHow many records in the list to skip.

Returns

void

Additional overload: neighbors::ivf_pq::helpers::codepacker::reconstruct_list_data

Decode a series of records of a single list (cluster) in the compressed index

1void reconstruct_list_data(raft::resources const& res,
2const index<int64_t>& index,
3raft::device_vector_view<const uint32_t> in_cluster_indices,
4raft::device_matrix_view<float, uint32_t, raft::row_major> out_vectors,
5uint32_t label);

by their in-list offsets.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinconst index<int64_t>&
in_cluster_indicesinraft::device_vector_view<const uint32_t>The offsets of the selected indices within the cluster.
out_vectorsoutraft::device_matrix_view<float, uint32_t, raft::row_major>the destination buffer [n_take, index.dim()]. The length n_take defines how many records to reconstruct, it must be smaller than the list size.
labelinuint32_tThe id of the list (cluster) to decode.

Returns

void

neighbors::ivf_pq::helpers::codepacker::extend_list_with_codes

Extend one list of the index in-place, by the list label, skipping the classification and

1void extend_list_with_codes(
2raft::resources const& res,
3index<int64_t>* index,
4raft::device_matrix_view<const uint8_t, uint32_t, raft::row_major> new_codes,
5raft::device_vector_view<const int64_t, uint32_t, raft::row_major> new_indices,
6uint32_t label);

encoding steps.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinoutindex<int64_t>*
new_codesinraft::device_matrix_view<const uint8_t, uint32_t, raft::row_major>flat PQ codes, one code per byte [n_rows, index.pq_dim()]
new_indicesinraft::device_vector_view<const int64_t, uint32_t, raft::row_major>source indices [n_rows]
labelinuint32_tthe id of the target list (cluster).

Returns

void

neighbors::ivf_pq::helpers::codepacker::extend_list_with_contiguous_codes

Extend one list of the index in-place, by the list label, skipping the classification and

1void extend_list_with_contiguous_codes(
2raft::resources const& res,
3index<int64_t>* index,
4raft::device_matrix_view<const uint8_t, uint32_t, raft::row_major> new_codes,
5raft::device_vector_view<const int64_t, uint32_t, raft::row_major> new_indices,
6uint32_t label);

encoding steps. Uses contiguous/packed codes format.

This is similar to extend_list_with_codes but takes codes in contiguous packed format [n_rows, ceildiv(pq_dim * pq_bits, 8)] instead of unpacked format [n_rows, pq_dim]. This works correctly with any pq_bits value.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinoutindex<int64_t>*
new_codesinraft::device_matrix_view<const uint8_t, uint32_t, raft::row_major>flat contiguous PQ codes [n_rows, ceildiv(pq_dim * pq_bits, 8)]
new_indicesinraft::device_vector_view<const int64_t, uint32_t, raft::row_major>source indices [n_rows]
labelinuint32_tthe id of the target list (cluster).

Returns

void

neighbors::ivf_pq::helpers::codepacker::extend_list

Extend one list of the index in-place, by the list label, skipping the classification

1void extend_list(raft::resources const& res,
2index<int64_t>* index,
3raft::device_matrix_view<const float, uint32_t, raft::row_major> new_vectors,
4raft::device_vector_view<const int64_t, uint32_t, raft::row_major> new_indices,
5uint32_t label);

step.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinoutindex<int64_t>*
new_vectorsinraft::device_matrix_view<const float, uint32_t, raft::row_major>data to encode [n_rows, index.dim()]
new_indicesinraft::device_vector_view<const int64_t, uint32_t, raft::row_major>source indices [n_rows]
labelinuint32_tthe id of the target list (cluster).

Returns

void

neighbors::ivf_pq::helpers::erase_list

Remove all data from a single list (cluster) in the index.

1void erase_list(raft::resources const& res, index<int64_t>* index, uint32_t label);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&
indexinoutindex<int64_t>*
labelinuint32_tthe id of the target list (cluster).

Returns

void

neighbors::ivf_pq::helpers::reset_index

Public helper API to reset the data and indices ptrs, and the list sizes. Useful for

1void reset_index(const raft::resources& res, index<int64_t>* index);

externally modifying the index without going through the build stage. The data and indices of the IVF lists will be lost.

Usage example:

Parameters

NameDirectionTypeDescription
resinconst raft::resources&raft resource
indexinoutindex<int64_t>*pointer to IVF-PQ index

Returns

void

neighbors::ivf_pq::helpers::pad_centers_with_norms

Pad cluster centers with their L2 norms for efficient GEMM operations.

1void pad_centers_with_norms(
2raft::resources const& res,
3raft::device_matrix_view<const float, uint32_t, raft::row_major> centers,
4raft::device_matrix_view<float, uint32_t, raft::row_major> padded_centers);

This function takes cluster centers and pads them with their L2 norms to create extended centers suitable for coarse search operations. The output has dimensions [n_centers, dim_ext] where dim_ext = round_up(dim + 1, 8).

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
centersinraft::device_matrix_view<const float, uint32_t, raft::row_major>cluster centers [n_centers, dim]
padded_centersoutraft::device_matrix_view<float, uint32_t, raft::row_major>padded centers with norms [n_centers, dim_ext]

Returns

void

Additional overload: neighbors::ivf_pq::helpers::pad_centers_with_norms

Pad cluster centers with their L2 norms for efficient GEMM operations.

1void pad_centers_with_norms(
2raft::resources const& res,
3raft::host_matrix_view<const float, uint32_t, raft::row_major> centers,
4raft::device_matrix_view<float, uint32_t, raft::row_major> padded_centers);

This function takes cluster centers and pads them with their L2 norms to create extended centers suitable for coarse search operations. The output has dimensions [n_centers, dim_ext] where dim_ext = round_up(dim + 1, 8).

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
centersinraft::host_matrix_view<const float, uint32_t, raft::row_major>cluster centers [n_centers, dim]
padded_centersoutraft::device_matrix_view<float, uint32_t, raft::row_major>padded centers with norms [n_centers, dim_ext]

Returns

void

neighbors::ivf_pq::helpers::rotate_padded_centers

Rotate padded centers with the rotation matrix.

1void rotate_padded_centers(
2raft::resources const& res,
3raft::device_matrix_view<const float, uint32_t, raft::row_major> padded_centers,
4raft::device_matrix_view<const float, uint32_t, raft::row_major> rotation_matrix,
5raft::device_matrix_view<float, uint32_t, raft::row_major> rotated_centers);

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
padded_centersinraft::device_matrix_view<const float, uint32_t, raft::row_major>padded centers [n_centers, dim_ext]
rotation_matrixinraft::device_matrix_view<const float, uint32_t, raft::row_major>rotation matrix [rot_dim, dim]
rotated_centersoutraft::device_matrix_view<float, uint32_t, raft::row_major>rotated centers [n_centers, rot_dim]

Returns

void

neighbors::ivf_pq::helpers::extract_centers

Public helper API for fetching a trained index’s IVF centroids

1void extract_centers(raft::resources const& res,
2const index<int64_t>& index,
3raft::device_matrix_view<float, int64_t, raft::row_major> cluster_centers);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
indexinconst index<int64_t>&IVF-PQ index (passed by reference)
cluster_centersoutraft::device_matrix_view<float, int64_t, raft::row_major>IVF cluster centers [index.n_lists(), index.dim]

Returns

void

Additional overload: neighbors::ivf_pq::helpers::extract_centers

1void extract_centers(raft::resources const& res,
2const index<int64_t>& index,
3raft::host_matrix_view<float, uint32_t, raft::row_major> cluster_centers);

Parameters

NameDirectionTypeDescription
resraft::resources const&
indexconst index<int64_t>&
cluster_centersraft::host_matrix_view<float, uint32_t, raft::row_major>

Returns

void

neighbors::ivf_pq::helpers::recompute_internal_state

Helper exposing the re-computation of list sizes and related arrays if IVF lists have been

1void recompute_internal_state(const raft::resources& res, index<int64_t>* index);

modified externally.

Usage example:

Parameters

NameDirectionTypeDescription
resinconst raft::resources&raft resource
indexinoutindex<int64_t>*pointer to IVF-PQ index

Returns

void

neighbors::ivf_pq::helpers::make_rotation_matrix

Generate a rotation matrix into user-provided buffer (standalone version).

1void make_rotation_matrix(
2raft::resources const& res,
3raft::device_matrix_view<float, uint32_t, raft::row_major> rotation_matrix,
4bool force_random_rotation);

This standalone helper generates a rotation matrix without requiring an index object. Users can call this to prepare a rotation matrix before building from precomputed data.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
rotation_matrixoutraft::device_matrix_view<float, uint32_t, raft::row_major>Output buffer [rot_dim, dim] for the rotation matrix
force_random_rotationinboolIf false and rot_dim == dim, creates identity matrix. If true or rot_dim != dim, creates random orthogonal matrix.

Returns

void

neighbors::ivf_pq::helpers::resize_list

Resize an IVF-PQ list with flat layout.

1void resize_list(raft::resources const& res,
2std::shared_ptr<list_data_base<int64_t, uint32_t>>& orig_list,
3const list_spec_flat<uint32_t, int64_t>& spec,
4uint32_t new_used_size,
5uint32_t old_used_size);

This helper resizes an IVF list that uses the flat (non-interleaved) PQ code layout. If the new size exceeds the current capacity, a new list is allocated and existing data is copied. The function handles the type casting internally.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
orig_listinoutstd::shared_ptr<list_data_base<int64_t, uint32_t>>&the list to resize (may be replaced with a new allocation)
specinconst list_spec_flat<uint32_t, int64_t>&the list specification containing pq_bits, pq_dim, and allocation settings
new_used_sizeinuint32_tthe new size of the list (number of vectors)
old_used_sizeinuint32_tthe current size of the list (data up to this size is preserved)

Returns

void

Additional overload: neighbors::ivf_pq::helpers::resize_list

Resize an IVF-PQ list with interleaved layout.

1void resize_list(raft::resources const& res,
2std::shared_ptr<list_data_base<int64_t, uint32_t>>& orig_list,
3const list_spec_interleaved<uint32_t, int64_t>& spec,
4uint32_t new_used_size,
5uint32_t old_used_size);

This helper resizes an IVF list that uses the interleaved PQ code layout (default). If the new size exceeds the current capacity, a new list is allocated and existing data is copied. The function handles the type casting internally.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resource
orig_listinoutstd::shared_ptr<list_data_base<int64_t, uint32_t>>&the list to resize (may be replaced with a new allocation)
specinconst list_spec_interleaved<uint32_t, int64_t>&the list specification containing pq_bits, pq_dim, and allocation settings
new_used_sizeinuint32_tthe new size of the list (number of vectors)
old_used_sizeinuint32_tthe current size of the list (data up to this size is preserved)

Returns

void