For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
GitHubCUDA-X
    • Home
    • Installation
  • Getting Started
    • Introduction
    • Integrations
    • Use-cases
  • User Guide
    • API Guide
    • Benchmarking Guide
    • Field Guide
    • References
  • Developer Guide
    • Coding Guidelines
    • Contributing
  • API Reference
    • C API Documentation
    • Cpp API Documentation
      • Cluster Agglomerative
      • Cluster Kmeans
      • Cluster Spectral
      • Common Types
      • Distance Distance
      • Distance Grammian
      • Neighbors All Neighbors
      • Neighbors Ball Cover
      • Neighbors Brute Force
      • Neighbors Cagra
      • Neighbors Common
      • Neighbors Dynamic Batching
      • Neighbors Epsilon Neighborhood
      • Neighbors HNSW
      • Neighbors Composite Index
      • Neighbors IVF Flat
      • Neighbors IVF PQ
      • Neighbors IVF SQ
      • Neighbors NN Descent
      • Neighbors Refine
      • Neighbors Scann
      • Neighbors Tiered Index
      • Neighbors Vamana
      • Preprocessing Quantize Binary
      • Preprocessing PCA
      • Preprocessing Quantize PQ
      • Preprocessing Quantize Scalar
      • Preprocessing Spectral Embedding
      • Selection Select K
      • Stats Silhouette Score
      • Stats Trustworthiness Score
      • Util Cutlass Utils
      • Util File Io
    • Python API Documentation
    • Java API Documentation
    • Rust API Documentation
    • Go API Documentation
NVIDIANVIDIA
Developer-friendly docs for your API
Privacy Policy | Your Privacy Choices | Terms of Service | Accessibility | Corporate Policies | Product Security | Contact

Copyright © 2026, NVIDIA Corporation.

LogoLogocuVS
GitHubCUDA-X
On this page
  • The nn-descent algorithm parameters.
  • neighbors::nn_descent::DIST_COMP_DTYPE
  • neighbors::nn_descent::index_params
  • neighbors::nn_descent::index_params::index_params
  • nn-descent index
  • neighbors::nn_descent::index
  • neighbors::nn_descent::index::index
  • neighbors::nn_descent::index::metric
  • neighbors::nn_descent::index::size
  • neighbors::nn_descent::index::graph_degree
  • neighbors::nn_descent::index::graph
  • neighbors::nn_descent::index::distances
  • nn-descent index build
  • neighbors::nn_descent::build
API ReferenceCpp API Documentation

NN Descent

||View as Markdown|
Previous

Neighbors IVF SQ

Next

Neighbors Refine

Source header: cuvs/neighbors/nn_descent.hpp

The nn-descent algorithm parameters.

neighbors::nn_descent::DIST_COMP_DTYPE

Dtype to use for distance computation

1enum class DIST_COMP_DTYPE {
2 AUTO = 0,
3 FP32 = 1,
4 FP16 = 2
5};

Values

NameValueDescription
AUTO0Automatically determine the best dtype for distance computation based on the dataset dimensions.
FP321Use fp32 distance computation for better precision at the cost of performance and memory usage.
FP162Use fp16 distance computation.

neighbors::nn_descent::index_params

Parameters used to build an nn-descent index

1struct index_params : cuvs::neighbors::index_params {
2 size_t graph_degree;
3 size_t intermediate_graph_degree;
4 size_t max_iterations;
5 float termination_threshold;
6 bool return_distances;
7 DIST_COMP_DTYPE dist_comp_dtype;
8};

Fields

NameTypeDescription
graph_degreesize_tFor an input dataset of dimensions (N, D), determines the final dimensions of the all-neighbors knn graph which turns out to be of dimensions (N, graph_degree)
intermediate_graph_degreesize_tInternally, nn-descent builds an all-neighbors knn graph of dimensions (N, intermediate_graph_degree) before selecting the final graph_degree neighbors. It’s recommended that intermediate_graph_degree >= 1.5 * graph_degree
max_iterationssize_tThe number of iterations that nn-descent will refine the graph for. More iterations produce a better quality graph at cost of performance
termination_thresholdfloatThe delta at which nn-descent will terminate its iterations
return_distancesboolBoolean to decide whether to return distances array
dist_comp_dtypeDIST_COMP_DTYPEdtype to use for distance computation.
Defaults to AUTO which automatically determines the best dtype for distance computation based on the dataset dimensions.
Use FP32 for better precision at the cost of performance and memory usage. This option is only valid when data type is fp32.
Use FP16 for better performance and memory usage at the cost of precision.

neighbors::nn_descent::index_params::index_params

Construct NN descent parameters for a specific kNN graph degree

1index_params(size_t graph_degree = 64,
2cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Expanded);

Parameters

NameDirectionTypeDescription
graph_degreesize_toutput graph degree
Default: 64.
metriccuvs::distance::DistanceTypedistance metric to use
Default: cuvs::distance::DistanceType::L2Expanded.

Returns

void

nn-descent index

neighbors::nn_descent::index

nn-descent Build an nn-descent index The index contains an all-neighbors graph of the input dataset stored in host memory of dimensions (n_rows, n_cols)

Reference: Hui Wang, Wan-Lei Zhao, Xiangxiang Zeng, and Jianye Yang. 2021. Fast k-NN Graph Construction by GPU based NN-Descent. In Proceedings of the 30th ACM International Conference on Information & Knowledge Management (CIKM ‘21). Association for Computing Machinery, New York, NY, USA, 1929–1938. https://doi.org/10.1145/3459637.3482344

1template <typename IdxT>
2struct index;

neighbors::nn_descent::index::index

Construct a new index object

1index(raft::resources const& res,
2int64_t n_rows,
3int64_t n_cols,
4bool return_distances = false,
5cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Expanded);

This constructor creates an nn-descent index which is a knn-graph in host memory. The type of the knn-graph is a dense raft::host_matrix and dimensions are (n_rows, n_cols).

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
n_rowsint64_tnumber of rows in knn-graph
n_colsint64_tnumber of cols in knn-graph
return_distancesboolwhether to return distances
Default: false.
metriccuvs::distance::DistanceTypedistance metric to use
Default: cuvs::distance::DistanceType::L2Expanded.

Returns

void

Additional overload: neighbors::nn_descent::index::index

Construct a new index object

1index(raft::resources const& res,
2raft::host_matrix_view<IdxT, int64_t, raft::row_major> graph_view,
3std::optional<raft::device_matrix_view<float, int64_t, row_major>> distances_view =
4std::nullopt,
5cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Expanded);

This constructor creates an nn-descent index using a user allocated host memory knn-graph. The type of the knn-graph is a dense raft::host_matrix and dimensions are (n_rows, n_cols).

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
graph_viewraft::host_matrix_view<IdxT, int64_t, raft::row_major>raft::host_matrix_view<IdxT, int64_t, raft::row_major> for storing knn-graph
distances_viewstd::optional<raft::device_matrix_view<float, int64_t, row_major>>optional raft::device_matrix_view<float, int64_t, row_major> for storing distances
Default: std::nullopt.
metriccuvs::distance::DistanceTypedistance metric to use
Default: cuvs::distance::DistanceType::L2Expanded.

Returns

void

neighbors::nn_descent::index::metric

Distance metric used for clustering.

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

Returns

cuvs::distance::DistanceType

neighbors::nn_descent::index::size

Total length of the index (number of vectors).

1[[nodiscard]] constexpr inline auto size() const noexcept -> IdxT;

Returns

IdxT

neighbors::nn_descent::index::graph_degree

Graph degree

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

Returns

uint32_t

neighbors::nn_descent::index::graph

neighborhood graph [size, graph-degree]

1[[nodiscard]] inline auto graph() noexcept
2-> raft::host_matrix_view<IdxT, int64_t, raft::row_major>;

Returns

raft::host_matrix_view<IdxT, int64_t, raft::row_major>

neighbors::nn_descent::index::distances

neighborhood graph distances [size, graph-degree]

1[[nodiscard]] inline auto distances() noexcept
2-> std::optional<device_matrix_view<float, int64_t, row_major>>;

Returns

std::optional<device_matrix_view<float, int64_t, row_major>>

nn-descent index build

neighbors::nn_descent::build

Build nn-descent Index with dataset in device memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::device_matrix_view<const float, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::device_matrix_view<const float, int64_t, raft::row_major>raft::device_matrix_view input dataset expected to be located in device memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in host memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::host_matrix_view<const float, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1

Usage example:

Template Parameters

NameTypeDescription
T“data-type of the input dataset
IdxT“data-type for the output index

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::host_matrix_view<const float, int64_t, raft::row_major>raft::host_matrix_view input dataset expected to be located in host memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in device memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::device_matrix_view<const half, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::device_matrix_view<const half, int64_t, raft::row_major>raft::device_matrix_view input dataset expected to be located in device memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in host memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::host_matrix_view<const half, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1

Usage example:

Template Parameters

NameTypeDescription
T“data-type of the input dataset
IdxT“data-type for the output index

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::host_matrix_view<const half, int64_t, raft::row_major>raft::host_matrix_view input dataset expected to be located in host memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in device memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::device_matrix_view<const int8_t, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1
  • BitwiseHamming

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::device_matrix_view<const int8_t, int64_t, raft::row_major>raft::device_matrix_view input dataset expected to be located in device memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in host memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::host_matrix_view<const int8_t, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1
  • BitwiseHamming

Usage example:

Template Parameters

NameTypeDescription
T“data-type of the input dataset
IdxT“data-type for the output index

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::host_matrix_view<const int8_t, int64_t, raft::row_major>raft::host_matrix_view input dataset expected to be located in host memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in device memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::device_matrix_view<const uint8_t, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1
  • BitwiseHamming

Usage example:

Parameters

NameDirectionTypeDescription
resinraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::device_matrix_view<const uint8_t, int64_t, raft::row_major>raft::device_matrix_view input dataset expected to be located in device memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>

Additional overload: neighbors::nn_descent::build

Build nn-descent Index with dataset in host memory

1auto build(raft::resources const& res,
2index_params const& params,
3raft::host_matrix_view<const uint8_t, int64_t, raft::row_major> dataset,
4std::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>> graph =
5std::nullopt) -> cuvs::neighbors::nn_descent::index<uint32_t>;

The following distance metrics are supported:

  • L2Expanded
  • L2SqrtExpanded
  • CosineExpanded
  • InnerProduct
  • L1
  • BitwiseHamming

Usage example:

Template Parameters

NameTypeDescription
T“data-type of the input dataset
IdxT“data-type for the output index

Parameters

NameDirectionTypeDescription
resraft::resources const&raft::resources is an object managing resources
paramsinindex_params const&an instance of nn_descent::index_params that are parameters to run the nn-descent algorithm
datasetinraft::host_matrix_view<const uint8_t, int64_t, raft::row_major>raft::host_matrix_view input dataset expected to be located in host memory
graphinstd::optional<raft::host_matrix_view<uint32_t, int64_t, raft::row_major>>optional raft::host_matrix_view<uint32_t, int64_t, raft::row_major> for owning the output graph
Default: std::nullopt.

Returns

cuvs::neighbors::nn_descent::index<uint32_t>