IVF PQ
Python module: cuvs.neighbors.ivf_pq
Index
IvfPq index object. This object stores the trained IvfPq index state which can be used to perform nearest neighbors searches.
Members
trained
n_lists
The number of inverted lists (clusters)
dim
dimensionality of the cluster centers
pq_dim
The dimensionality of an encoded vector after compression by PQ
pq_len
The dimensionality of a subspace, i.e. the number of vector components mapped to a subspace
pq_bits
The bit length of an encoded vector element after compression by PQ.
centers
Get the cluster centers corresponding to the lists in the original space
centers_padded
Get the padded cluster centers [n_lists, dim_ext] where dim_ext = round_up(dim + 1, 8). This returns contiguous data suitable for build_precomputed.
pq_centers
Get the PQ cluster centers
centers_rot
Get the rotated cluster centers [n_lists, rot_dim] where rot_dim = pq_len * pq_dim
rotation_matrix
Get the rotation matrix [rot_dim, dim] Transform matrix (original space -> rotated padded space)
list_sizes
Get the sizes of each list
lists
Iterates through the pq-encoded list data
This function returns an iterator over each list, with each value being the pq-encoded data for the entire list
Parameters
list_data
Gets unpacked list data for a single list (cluster)
Parameters
list_indices
Gets indices for a single cluster (list)
Parameters
IndexParams
Parameters to build index for IvfPq nearest neighbor search
Parameters
Constructor
Members
get_handle
metric
metric_arg
add_data_on_build
n_lists
kmeans_n_iters
kmeans_trainset_fraction
pq_bits
pq_dim
codebook_kind
force_random_rotation
add_data_on_build
conservative_memory_allocation
max_train_points_per_pq_code
codes_layout
get_handle
SearchParams
Supplemental parameters to search IVF-Pq index
Parameters
Constructor
Members
get_handle
n_probes
lut_dtype
internal_distance_dtype
coarse_search_dtype
max_internal_batch_size
get_handle
build
@auto_sync_resources
Build the IvfPq index from the dataset for efficient search.
The input dataset array can be either CUDA array interface compliant matrix or an array interface compliant matrix in host memory.
Parameters
Returns
Examples
build_precomputed
@auto_sync_resources
Build a view-type IVF-PQ index from precomputed centroids and codebook.
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
Parameters
Returns
Examples
extend
@auto_sync_resources
Extend an existing index with new vectors.
The input array can be either CUDA array interface compliant matrix or array interface compliant matrix in host memory.
Parameters
Returns
Examples
load
@auto_sync_resources
Loads index from file.
Saving / loading the index is experimental. The serialization format is subject to change, therefore loading an index saved with a previous version of cuvs is not guaranteed to work.
Parameters
Returns
save
@auto_sync_resources
Saves the index to a file.
Saving / loading the index is experimental. The serialization format is subject to change.
Parameters
Examples
search
@auto_sync_resources
@auto_convert_output
Find the k nearest neighbors for each query.
Parameters
Examples
transform
@auto_sync_resources
Transform a dataset by applying pq-encoding to the vectors.
Parameters
Returns