Scann

View as Markdown

Source header: cuvs/neighbors/scann.hpp

ScaNN index build parameters

neighbors::experimental::scann::index_params

ANN parameters used by ScaNN to build index

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

Fields

NameTypeDescription
n_leavesuint32_tthe number of leaves in the tree *
kmeans_n_rows_trainint64_tthe number of rows for training the tree structures *
kmeans_n_itersuint32_tthe max number of iterations for training the tree structure *
partitioning_etafloatthe value of eta for AVQ adjustment during partitioning *
soar_lambdafloatthe value of lambda for SOAR spilling *
pq_dimuint32_tthe dimension of pq subspaces (must divide dataset dimension)*
pq_bitsuint32_tthe number of bits for pq codes (must be 4 or 8, for 16 and 256 codes respectively) *
pq_n_rows_trainint64_tthe number of rows for PQ training (internally capped to 100k) *
pq_train_itersuint32_tthe max number of iterations for PQ training *
reordering_bf16boolwhether to apply bf16 quantization of dataset vectors *
reordering_noise_shaping_thresholdfloatThreshold T for computing AVQ eta = (dim - 1) ( T^2 / || x ||^2) / ( 1 - T^2 / || x ||^2) When quantizing a vector x to x_q, AVQ minimizes the loss function L(x, x_q) = eta * || r_para ||^2 + || r_perp ||^2, where r = x - x_q, r_para = <r, x> * x / || x ||^2, r_perp = r - r_para Compared to L2 loss, This produces an x_q which better approximates the dot product of a query vector with x If the threshold is NAN, AVQ is not performed during bfloat16 quant

ScaNN index type

neighbors::experimental::scann::index

ScaNN index.

The index stores the dataset and the ScaNN graph in device memory.

1template <typename T, typename IdxT>
2struct index : cuvs::neighbors::index { ... };

neighbors::experimental::scann::index::metric

Distance metric used for clustering.

1[[nodiscard]] constexpr inline auto metric() const noexcept -> cuvs::distance::DistanceType;

Returns

cuvs::distance::DistanceType

neighbors::experimental::scann::index::size

Total length of the index (number of vectors).

1IdxT size() const noexcept;

Returns

IdxT

neighbors::experimental::scann::index::dim

Dimensionality of the data.

1[[nodiscard]] constexpr inline auto dim() const noexcept -> uint32_t;

Returns

uint32_t

ScaNN index build functions

neighbors::experimental::scann::build

Build the index from the dataset for efficient search.

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

Parameters

NameDirectionTypeDescription
handleraft::resources const&
paramsconst cuvs::neighbors::experimental::scann::index_params&
datasetraft::device_matrix_view<const float, int64_t, raft::row_major>

Returns

cuvs::neighbors::experimental::scann::index<float, int64_t>

neighbors::experimental::scann::serialize

Save the index to files in a directory

1void serialize(raft::resources const& handle,
2const std::string& file_prefix,
3const cuvs::neighbors::experimental::scann::index<float, int64_t>& index);

This serializes the index into a list of files for integration into OSS ScaNN for use with search

NOTE: the implementation of ScaNN index build is EXPERIMENTAL and currently not subject to comprehensive, automated testing. Accuracy and performance are not guaranteed, and could diverge without warning.

Parameters

NameDirectionTypeDescription
handleraft::resources const&
file_prefixconst std::string&
indexconst cuvs::neighbors::experimental::scann::index<float, int64_t>&

Returns

void

ScaNN serialize functions

Additional overload: neighbors::experimental::scann::serialize

Save the index to files in a directory

1void serialize(raft::resources const& handle,
2const std::string& file_prefix,
3const cuvs::neighbors::experimental::scann::index<float, int64_t>& index);

This serializes the index into a list of files for integration into OSS ScaNN for use with search

NOTE: the implementation of ScaNN index build is EXPERIMENTAL and currently not subject to comprehensive, automated testing. Accuracy and performance are not guaranteed, and could diverge without warning.

Parameters

NameDirectionTypeDescription
handleraft::resources const&
file_prefixconst std::string&
indexconst cuvs::neighbors::experimental::scann::index<float, int64_t>&

Returns

void