HNSW

View as Markdown

Source header: cuvs/neighbors/hnsw.hpp

hnswlib index wrapper params

neighbors::hnsw::HnswHierarchy

Hierarchy for HNSW index when converting from CAGRA index

NOTE: When the value is NONE, the HNSW index is built as a base-layer-only index.

1enum class HnswHierarchy {
2 NONE
3};

Values

NameValue
NONE

neighbors::hnsw::[[deprecated

Create a CAGRA index parameters compatible with HNSW index

1[[deprecated("Use cagra::index_params::from_hnsw_params instead")]]
2cuvs::neighbors::cagra::index_params to_cagra_params(
3raft::matrix_extent<int64_t> dataset,
4int M,
5int ef_construction,
6cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Expanded);
  • IMPORTANT NOTE *

The reference HNSW index and the corresponding from-CAGRA generated HNSW index will NOT produce the same recalls and QPS for the same parameter ef. The graphs are different internally. For the same ef, the from-CAGRA index likely has a slightly higher recall and slightly lower QPS. However, the Recall-QPS curves should be similar (i.e. the points are just shifted along the curve).

Usage example:

Parameters

NameDirectionTypeDescription
arg1"Use cagra::index_params::from_hnsw_params instead"

Returns

void

hnswlib index wrapper

neighbors::hnsw::index

hnswlib index wrapper

1template <typename T>
2struct index;

neighbors::hnsw::index::index

load a base-layer-only hnswlib index originally saved from a built CAGRA index. This is a virtual class and it cannot be used directly. To create an index, use the factory function cuvs::neighbors::hnsw::from_cagra from the header cuvs/neighbors/hnsw.hpp

1index(int dim, cuvs::distance::DistanceType metric, HnswHierarchy hierarchy = HnswHierarchy::NONE);

Parameters

NameDirectionTypeDescription
diminintdimensions of the training dataset
metricincuvs::distance::DistanceTypedistance metric to search. Supported metrics (“L2Expanded”, “InnerProduct”)
hierarchyinHnswHierarchyhierarchy used for upper HNSW layers
Default: HnswHierarchy::NONE.

Returns

void

neighbors::hnsw::index::get_index

Get underlying index

1virtual void const* get_index() const = 0;

Returns

virtual void const*

neighbors::hnsw::index::set_ef

Set ef for search

1virtual void set_ef(int ef) const = 0;

Parameters

NameDirectionTypeDescription
efint

Returns

virtual void

neighbors::hnsw::index::file_path

Get file path for disk-backed index

1virtual std::string file_path() const;

Returns

virtual std::string

HNSW index extend parameters

neighbors::hnsw::extend_params

HNSW index extend parameters

1struct extend_params {
2 int num_threads;
3};

Fields

NameTypeDescription
num_threadsintNumber of host threads to use to add additional vectors to the index. Value of 0 automatically maximizes parallelism.

Build HNSW index on the GPU

neighbors::hnsw::build

Build an HNSW index on the GPU

1std::unique_ptr<index<float>> build(
2raft::resources const& res,
3const index_params& params,
4raft::host_matrix_view<const float, int64_t, raft::row_major> dataset);

The resulting graph is compatible for HNSW search, but is not an exact equivalent of the graph built by the HNSW.

The HNSW index construction parameters M and ef_construction are the main parameters to control the graph degree and graph quality. We have additional options that can be used to fine tune graph building on the GPU (see cuvs::neighbors::cagra::index_params). In case the index does not fit the host or GPU memory, we would use disk as temporary storage. In such cases it is important to set ace_params.build_dir to a fast disk with sufficient storage size.

NOTE: This function requires CUDA headers to be available at compile time.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters including ACE configuration
datasetinraft::host_matrix_view<const float, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, dim]

Returns

std::unique_ptr<index<float>>

Additional overload: neighbors::hnsw::build

Build an HNSW index on the GPU

1std::unique_ptr<index<half>> build(
2raft::resources const& res,
3const index_params& params,
4raft::host_matrix_view<const half, int64_t, raft::row_major> dataset);

The resulting graph is compatible for HNSW search, but is not an exact equivalent of the graph built by the HNSW.

The HNSW index construction parameters M and ef_construction are the main parameters to control the graph degree and graph quality. We have additional options that can be used to fine tune graph building on the GPU (see cuvs::neighbors::cagra::index_params). In case the index does not fit the host or GPU memory, we would use disk as temporary storage. In such cases it is important to set ace_params.build_dir to a fast disk with sufficient storage size.

NOTE: This function requires CUDA headers to be available at compile time.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters including ACE configuration
datasetinraft::host_matrix_view<const half, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, dim]

Returns

std::unique_ptr<index<half>>

Additional overload: neighbors::hnsw::build

Build an HNSW index on the GPU

1std::unique_ptr<index<uint8_t>> build(
2raft::resources const& res,
3const index_params& params,
4raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> dataset);

The resulting graph is compatible for HNSW search, but is not an exact equivalent of the graph built by the HNSW.

The HNSW index construction parameters M and ef_construction are the main parameters to control the graph degree and graph quality. We have additional options that can be used to fine tune graph building on the GPU (see cuvs::neighbors::cagra::index_params). In case the index does not fit the host or GPU memory, we would use disk as temporary storage. In such cases it is important to set ace_params.build_dir to a fast disk with sufficient storage size.

NOTE: This function requires CUDA headers to be available at compile time.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters including ACE configuration
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

std::unique_ptr<index<uint8_t>>

Additional overload: neighbors::hnsw::build

Build an HNSW index on the GPU

1std::unique_ptr<index<int8_t>> build(
2raft::resources const& res,
3const index_params& params,
4raft::host_matrix_view<const int8_t, int64_t, raft::row_major> dataset);

The resulting graph is compatible for HNSW search, but is not an exact equivalent of the graph built by the HNSW.

The HNSW index construction parameters M and ef_construction are the main parameters to control the graph degree and graph quality. We have additional options that can be used to fine tune graph building on the GPU (see cuvs::neighbors::cagra::index_params). In case the index does not fit the host or GPU memory, we would use disk as temporary storage. In such cases it is important to set ace_params.build_dir to a fast disk with sufficient storage size.

NOTE: This function requires CUDA headers to be available at compile time.

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters including ACE configuration
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

std::unique_ptr<index<int8_t>>

Load CAGRA index as hnswlib index

neighbors::hnsw::from_cagra

Construct an hnswlib index from a CAGRA index NOTE: When hnsw::index_params.hierarchy is:

  1. NONE: This method uses the filesystem to write the CAGRA index in /tmp/&lt;random_number&gt;.bin before reading it as an hnswlib index, then deleting the temporary file. The returned index is immutable and can only be searched by the hnswlib wrapper in cuVS, as the format is not compatible with the original hnswlib.
  2. CPU: The returned index is mutable and can be extended with additional vectors. The serialized index is also compatible with the original hnswlib library.
1std::unique_ptr<index<float>> from_cagra(
2raft::resources const& res,
3const index_params& params,
4const cuvs::neighbors::cagra::index<float, uint32_t>& cagra_index,
5std::optional<raft::host_matrix_view<const float, int64_t, raft::row_major>> dataset =
6std::nullopt);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
cagra_indexinconst cuvs::neighbors::cagra::index<float, uint32_t>&cagra index
datasetinstd::optional<raft::host_matrix_view<const float, int64_t, raft::row_major>>optional dataset to avoid extra memory copy when hierarchy is CPU

Default: std::nullopt.

Returns

std::unique_ptr<index<float>>

Additional overload: neighbors::hnsw::from_cagra

Construct an hnswlib index from a CAGRA index NOTE: When hnsw::index_params.hierarchy is:

  1. NONE: This method uses the filesystem to write the CAGRA index in /tmp/&lt;random_number&gt;.bin before reading it as an hnswlib index, then deleting the temporary file. The returned index is immutable and can only be searched by the hnswlib wrapper in cuVS, as the format is not compatible with the original hnswlib.
  2. CPU: The returned index is mutable and can be extended with additional vectors. The serialized index is also compatible with the original hnswlib library.
1std::unique_ptr<index<half>> from_cagra(
2raft::resources const& res,
3const index_params& params,
4const cuvs::neighbors::cagra::index<half, uint32_t>& cagra_index,
5std::optional<raft::host_matrix_view<const half, int64_t, raft::row_major>> dataset =
6std::nullopt);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
cagra_indexinconst cuvs::neighbors::cagra::index<half, uint32_t>&cagra index
datasetinstd::optional<raft::host_matrix_view<const half, int64_t, raft::row_major>>optional dataset to avoid extra memory copy when hierarchy is CPU

Default: std::nullopt.

Returns

std::unique_ptr<index<half>>

Additional overload: neighbors::hnsw::from_cagra

Construct an hnswlib index from a CAGRA index NOTE: When hnsw::index_params.hierarchy is:

  1. NONE: This method uses the filesystem to write the CAGRA index in /tmp/&lt;random_number&gt;.bin before reading it as an hnswlib index, then deleting the temporary file. The returned index is immutable and can only be searched by the hnswlib wrapper in cuVS, as the format is not compatible with the original hnswlib.
  2. CPU: The returned index is mutable and can be extended with additional vectors. The serialized index is also compatible with the original hnswlib library.
1std::unique_ptr<index<uint8_t>> from_cagra(
2raft::resources const& res,
3const index_params& params,
4const cuvs::neighbors::cagra::index<uint8_t, uint32_t>& cagra_index,
5std::optional<raft::host_matrix_view<const uint8_t, int64_t, raft::row_major>> dataset =
6std::nullopt);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
cagra_indexinconst cuvs::neighbors::cagra::index<uint8_t, uint32_t>&cagra index
datasetinstd::optional<raft::host_matrix_view<const uint8_t, int64_t, raft::row_major>>optional dataset to avoid extra memory copy when hierarchy is CPU

Default: std::nullopt.

Returns

std::unique_ptr<index<uint8_t>>

Additional overload: neighbors::hnsw::from_cagra

Construct an hnswlib index from a CAGRA index NOTE: When hnsw::index_params.hierarchy is:

  1. NONE: This method uses the filesystem to write the CAGRA index in /tmp/&lt;random_number&gt;.bin before reading it as an hnswlib index, then deleting the temporary file. The returned index is immutable and can only be searched by the hnswlib wrapper in cuVS, as the format is not compatible with the original hnswlib.
  2. CPU: The returned index is mutable and can be extended with additional vectors. The serialized index is also compatible with the original hnswlib library.
1std::unique_ptr<index<int8_t>> from_cagra(
2raft::resources const& res,
3const index_params& params,
4const cuvs::neighbors::cagra::index<int8_t, uint32_t>& cagra_index,
5std::optional<raft::host_matrix_view<const int8_t, int64_t, raft::row_major>> dataset =
6std::nullopt);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
cagra_indexinconst cuvs::neighbors::cagra::index<int8_t, uint32_t>&cagra index
datasetinstd::optional<raft::host_matrix_view<const int8_t, int64_t, raft::row_major>>optional dataset to avoid extra memory copy when hierarchy is CPU

Default: std::nullopt.

Returns

std::unique_ptr<index<int8_t>>

Extend HNSW index with additional vectors

neighbors::hnsw::extend

Add new vectors to an HNSW index NOTE: The HNSW index can only be extended when the hnsw::index_params.hierarchy is CPU when converting from a CAGRA index.

1void extend(raft::resources const& res,
2const extend_params& params,
3raft::host_matrix_view<const float, int64_t, raft::row_major> additional_dataset,
4index<float>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst extend_params&configure the extend
additional_datasetinraft::host_matrix_view<const float, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, index->dim()]
idxinoutindex<float>&HNSW index to extend

Returns

void

Additional overload: neighbors::hnsw::extend

Add new vectors to an HNSW index NOTE: The HNSW index can only be extended when the hnsw::index_params.hierarchy is CPU when converting from a CAGRA index.

1void extend(raft::resources const& res,
2const extend_params& params,
3raft::host_matrix_view<const half, int64_t, raft::row_major> additional_dataset,
4index<half>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst extend_params&configure the extend
additional_datasetinraft::host_matrix_view<const half, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, index->dim()]
idxinoutindex<half>&HNSW index to extend

Returns

void

Additional overload: neighbors::hnsw::extend

Add new vectors to an HNSW index NOTE: The HNSW index can only be extended when the hnsw::index_params.hierarchy is CPU when converting from a CAGRA index.

1void extend(raft::resources const& res,
2const extend_params& params,
3raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> additional_dataset,
4index<uint8_t>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst extend_params&configure the extend
additional_datasetinraft::host_matrix_view<const uint8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, index->dim()]
idxinoutindex<uint8_t>&HNSW index to extend

Returns

void

Additional overload: neighbors::hnsw::extend

Add new vectors to an HNSW index NOTE: The HNSW index can only be extended when the hnsw::index_params.hierarchy is CPU when converting from a CAGRA index.

1void extend(raft::resources const& res,
2const extend_params& params,
3raft::host_matrix_view<const int8_t, int64_t, raft::row_major> additional_dataset,
4index<int8_t>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst extend_params&configure the extend
additional_datasetinraft::host_matrix_view<const int8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_rows, index->dim()]
idxinoutindex<int8_t>&HNSW index to extend

Returns

void

Build CAGRA index and search with hnswlib

neighbors::hnsw::search_params

Build CAGRA index and search with hnswlib

1struct search_params : cuvs::neighbors::search_params {
2 int ef;
3 int num_threads;
4};

Fields

NameTypeDescription
efint
num_threadsint

Search hnswlib index

neighbors::hnsw::search

Search HNSW index constructed from a CAGRA index NOTE: The HNSW index can only be searched by the hnswlib wrapper in cuVS when the hierarchy is NONE, as the format is not compatible with the original hnswlib.

1void search(raft::resources const& res,
2const search_params& params,
3const index<float>& idx,
4raft::host_matrix_view<const float, int64_t, raft::row_major> queries,
5raft::host_matrix_view<uint64_t, int64_t, raft::row_major> neighbors,
6raft::host_matrix_view<float, int64_t, raft::row_major> distances);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst search_params&configure the search
idxinconst index<float>&cagra index
queriesinraft::host_matrix_view<const float, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_queries, index->dim()]
neighborsoutraft::host_matrix_view<uint64_t, int64_t, raft::row_major>a host matrix view to the indices of the neighbors in the source dataset [n_queries, k]
distancesoutraft::host_matrix_view<float, int64_t, raft::row_major>a host matrix view to the distances to the selected neighbors [n_queries, k]

Returns

void

Additional overload: neighbors::hnsw::search

Search HNSW index constructed from a CAGRA index NOTE: The HNSW index can only be searched by the hnswlib wrapper in cuVS when the hierarchy is NONE, as the format is not compatible with the original hnswlib.

1void search(raft::resources const& res,
2const search_params& params,
3const index<half>& idx,
4raft::host_matrix_view<const half, int64_t, raft::row_major> queries,
5raft::host_matrix_view<uint64_t, int64_t, raft::row_major> neighbors,
6raft::host_matrix_view<float, int64_t, raft::row_major> distances);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst search_params&configure the search
idxinconst index<half>&cagra index
queriesinraft::host_matrix_view<const half, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_queries, index->dim()]
neighborsoutraft::host_matrix_view<uint64_t, int64_t, raft::row_major>a host matrix view to the indices of the neighbors in the source dataset [n_queries, k]
distancesoutraft::host_matrix_view<float, int64_t, raft::row_major>a host matrix view to the distances to the selected neighbors [n_queries, k]

Returns

void

Additional overload: neighbors::hnsw::search

Search HNSWindex constructed from a CAGRA index NOTE: The HNSW index can only be searched by the hnswlib wrapper in cuVS when the hierarchy is NONE, as the format is not compatible with the original hnswlib.

1void search(raft::resources const& res,
2const search_params& params,
3const index<uint8_t>& idx,
4raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> queries,
5raft::host_matrix_view<uint64_t, int64_t, raft::row_major> neighbors,
6raft::host_matrix_view<float, int64_t, raft::row_major> distances);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst search_params&configure the search
idxinconst index<uint8_t>&cagra index
queriesinraft::host_matrix_view<const uint8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_queries, index->dim()]
neighborsoutraft::host_matrix_view<uint64_t, int64_t, raft::row_major>a host matrix view to the indices of the neighbors in the source dataset [n_queries, k]
distancesoutraft::host_matrix_view<float, int64_t, raft::row_major>a host matrix view to the distances to the selected neighbors [n_queries, k]

Returns

void

Additional overload: neighbors::hnsw::search

Search HNSW index constructed from a CAGRA index NOTE: The HNSW index can only be searched by the hnswlib wrapper in cuVS when the hierarchy is NONE, as the format is not compatible with the original hnswlib.

1void search(raft::resources const& res,
2const search_params& params,
3const index<int8_t>& idx,
4raft::host_matrix_view<const int8_t, int64_t, raft::row_major> queries,
5raft::host_matrix_view<uint64_t, int64_t, raft::row_major> neighbors,
6raft::host_matrix_view<float, int64_t, raft::row_major> distances);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst search_params&configure the search
idxinconst index<int8_t>&cagra index
queriesinraft::host_matrix_view<const int8_t, int64_t, raft::row_major>a host matrix view to a row-major matrix [n_queries, index->dim()]
neighborsoutraft::host_matrix_view<uint64_t, int64_t, raft::row_major>a host matrix view to the indices of the neighbors in the source dataset [n_queries, k]
distancesoutraft::host_matrix_view<float, int64_t, raft::row_major>a host matrix view to the distances to the selected neighbors [n_queries, k]

Returns

void

Deserialize CAGRA index as hnswlib index

neighbors::hnsw::serialize

Serialize the HNSW index to file NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void serialize(raft::resources const& res, const std::string& filename, const index<float>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
filenameinconst std::string&path to the file to save the serialized CAGRA index
idxinconst index<float>&cagra index

Returns

void

Additional overload: neighbors::hnsw::serialize

Serialize the HNSW index to file NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void serialize(raft::resources const& res, const std::string& filename, const index<half>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
filenameinconst std::string&path to the file to save the serialized CAGRA index
idxinconst index<half>&cagra index

Returns

void

Additional overload: neighbors::hnsw::serialize

Serialize the HNSW index to file NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void serialize(raft::resources const& res, const std::string& filename, const index<uint8_t>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
filenameinconst std::string&path to the file to save the serialized CAGRA index
idxinconst index<uint8_t>&cagra index

Returns

void

Additional overload: neighbors::hnsw::serialize

Serialize the HNSW index to file NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void serialize(raft::resources const& res, const std::string& filename, const index<int8_t>& idx);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
filenameinconst std::string&path to the file to save the serialized CAGRA index
idxinconst index<int8_t>&cagra index

Returns

void

neighbors::hnsw::deserialize

De-serialize a CAGRA index saved to a file as an hnswlib index NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void deserialize(raft::resources const& res,
2const index_params& params,
3const std::string& filename,
4int dim,
5cuvs::distance::DistanceType metric,
6index<float>** index);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
filenameinconst std::string&path to the file containing the serialized CAGRA index
diminintdimensions of the training dataset
metricincuvs::distance::DistanceTypedistance metric to search. Supported metrics (“L2Expanded”, “InnerProduct”)
indexoutindex<float>**hnsw index

Returns

void

Additional overload: neighbors::hnsw::deserialize

De-serialize a CAGRA index saved to a file as an hnswlib index NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void deserialize(raft::resources const& res,
2const index_params& params,
3const std::string& filename,
4int dim,
5cuvs::distance::DistanceType metric,
6index<half>** index);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
filenameinconst std::string&path to the file containing the serialized CAGRA index
diminintdimensions of the training dataset
metricincuvs::distance::DistanceTypedistance metric to search. Supported metrics (“L2Expanded”, “InnerProduct”)
indexoutindex<half>**hnsw index

Returns

void

Additional overload: neighbors::hnsw::deserialize

De-serialize a CAGRA index saved to a file as an hnswlib index NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void deserialize(raft::resources const& res,
2const index_params& params,
3const std::string& filename,
4int dim,
5cuvs::distance::DistanceType metric,
6index<uint8_t>** index);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
filenameinconst std::string&path to the file containing the serialized CAGRA index
diminintdimensions of the training dataset
metricincuvs::distance::DistanceTypedistance metric to search. Supported metrics (“L2Expanded”, “InnerProduct”)
indexoutindex<uint8_t>**hnsw index

Returns

void

Additional overload: neighbors::hnsw::deserialize

De-serialize a CAGRA index saved to a file as an hnswlib index NOTE: When hierarchy is NONE, the saved hnswlib index is immutable and can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib. However, when hierarchy is CPU, the saved hnswlib index is compatible with the original hnswlib library.

1void deserialize(raft::resources const& res,
2const index_params& params,
3const std::string& filename,
4int dim,
5cuvs::distance::DistanceType metric,
6index<int8_t>** index);

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft resources
paramsinconst index_params&hnsw index parameters
filenameinconst std::string&path to the file containing the serialized CAGRA index
diminintdimensions of the training dataset
metricincuvs::distance::DistanceTypedistance metric to search. Supported metrics (“L2Expanded”, “InnerProduct”)
indexoutindex<int8_t>**hnsw index

Returns

void