Common

View as Markdown

Source header: cuvs/neighbors/common.hpp

Approximate Nearest Neighbors Types

neighbors::index

The base for approximate KNN index structures.

1struct index { ... };

neighbors::index_params

The base for KNN index parameters.

1struct index_params { ... };

Fields

NameTypeDescription
metriccuvs::distance::DistanceTypeDistance type.
metric_argfloatThe argument used by some distance metrics.

neighbors::MergeStrategy

Strategy for merging indices.

This enum is declared separately to avoid namespace pollution when including common.hpp. It provides a generic merge strategy that can be used across different index types.

1enum class MergeStrategy { ... };

Values

NameValue
MERGE_STRATEGY_PHYSICAL0
MERGE_STRATEGY_LOGICAL1

Types

neighbors::dataset

Two-dimensional dataset; maybe owning, maybe compressed, maybe strided.

1template <typename IdxT>
2struct dataset { ... };

neighbors::vpq_dataset

VPQ compressed dataset.

The dataset is compressed using two level quantization

  1. Vector Quantization
  2. Product Quantization of residuals
1template <typename MathT, typename IdxT>
2struct vpq_dataset : public dataset<IdxT> { ... };

Fields

NameTypeDescription
vq_code_bookraft::device_matrix<math_type, uint32_t, raft::row_major>Vector Quantization codebook - “coarse cluster centers”.
pq_code_bookraft::device_matrix<math_type, uint32_t, raft::row_major>Product Quantization codebook - “fine cluster centers”.
dataraft::device_matrix<uint8_t, index_type, raft::row_major>Compressed dataset.

neighbors::ivf::list_base

Abstract base class for IVF list data.

This allows polymorphic access to list data regardless of the underlying layout.

TODO: Make this struct internal (tracking issue: https://github.com/rapidsai/cuvs/issues/1726)

1template <typename ValueT, typename IdxT, typename SizeT = uint32_t>
2struct list_base { ... };

neighbors::ivf::list

The data for a single IVF list.

1template <template <typename, typename...> typename SpecT,
2typename SizeT,
3typename... SpecExtraArgs>
4struct list : public list_base<typename SpecT<SizeT, SpecExtraArgs...>::value_type,
5typename SpecT<SizeT, SpecExtraArgs...>::index_type,
6SizeT> { ... };

Fields

NameTypeDescription
dataraft::device_mdarray<value_type, list_extents, raft::row_major>Possibly encoded data; it’s layout is defined by SpecT.
indicesraft::device_mdarray<index_type, raft::extent_1d<size_type>, raft::row_major>Source indices.
sizestd::atomic<size_type>The actual size of the content.

Filtering for ANN Types

neighbors::filtering::FilterType

Filtering for ANN Types

1enum class FilterType { ... };

Values

NameValue
None
Bitmap
Bitset

neighbors::filtering::none_sample_filter::operator

1constexpr __forceinline__ _RAFT_HOST_DEVICE bool operator()(
2// query index
3const uint32_t query_ix,
4// the current inverted list index
5const uint32_t cluster_ix,
6// the index of the current sample inside the current inverted list
7const uint32_t sample_ix) const;

Returns

constexpr __forceinline__ _RAFT_HOST_DEVICE bool

neighbors::filtering::none_sample_filter::get_filter_type

1FilterType get_filter_type() const override;

Returns

FilterType

neighbors::filtering::ivf_to_sample_filter

Filter used to convert the cluster index and sample index

of an IVF search into a sample index. This can be used as an intermediate filter.

1template <typename index_t, typename filter_t>
2struct ivf_to_sample_filter : public base_filter { ... };

Fields

NameTypeDescription
inds_ptrs_const index_t* const*
next_filter_const filter_t

neighbors::filtering::ivf_to_sample_filter::operator

If the original filter takes three arguments, then don’t modify the arguments.

1inline _RAFT_HOST_DEVICE bool operator()(
2// query index
3const uint32_t query_ix,
4// the current inverted list index
5const uint32_t cluster_ix,
6// the index of the current sample inside the current inverted list
7const uint32_t sample_ix) const;

If the original filter takes two arguments, then we are using inds_ptr_ to obtain the sample index.

Returns

inline _RAFT_HOST_DEVICE bool

neighbors::filtering::bitmap_filter

Filter an index with a bitmap

1template <typename bitmap_t, typename index_t>
2struct bitmap_filter : public base_filter { ... };

Fields

NameTypeDescription
bitmap_view_const view_t

neighbors::filtering::bitmap_filter::operator

1inline _RAFT_HOST_DEVICE bool operator()(
2// query index
3const uint32_t query_ix,
4// the index of the current sample
5const uint32_t sample_ix) const;

Returns

inline _RAFT_HOST_DEVICE bool

neighbors::filtering::bitmap_filter::get_filter_type

1FilterType get_filter_type() const override;

Returns

FilterType

neighbors::filtering::bitset_filter

Filter an index with a bitset

1template <typename bitset_t, typename index_t>
2struct bitset_filter : public base_filter { ... };

Fields

NameTypeDescription
bitset_view_const view_t

neighbors::filtering::bitset_filter::bitset_filter

1_RAFT_HOST_DEVICE bitset_filter(const view_t bitset_for_filtering);

Parameters

NameDirectionTypeDescription
bitset_for_filteringconst view_t

Returns

_RAFT_HOST_DEVICE

neighbors::filtering::bitset_filter::get_filter_type

1FilterType get_filter_type() const override;

Returns

FilterType

ANN MG index build parameters

neighbors::distribution_mode

1enum distribution_mode { ... };

neighbors::mg_index_params

1template <typename Upstream>
2struct mg_index_params : public Upstream { ... };

Fields

NameTypeDescription
modecuvs::neighbors::distribution_modeDistribution mode

ANN MG search parameters

neighbors::replicated_search_mode

1enum replicated_search_mode { ... };

Values

NameValue
LOAD_BALANCER
ROUND_ROBIN

neighbors::sharded_merge_mode

1enum sharded_merge_mode { ... };

Values

NameValue
MERGE_ON_ROOT_RANK
TREE_MERGE

neighbors::mg_search_params

1template <typename Upstream>
2struct mg_search_params : public Upstream { ... };

Fields

NameTypeDescription
search_modecuvs::neighbors::replicated_search_modeReplicated search mode
merge_modecuvs::neighbors::sharded_merge_modeSharded merge mode
n_rows_per_batchint64_tNumber of rows per batch