#knn #ann #optimization


Rust wrappers for NGT nearest neighbor search

14 unstable releases (5 breaking)

0.6.1 Sep 1, 2023
0.5.0 Aug 25, 2023
0.4.5 Sep 4, 2022
0.4.3 Jul 16, 2022
0.2.0 May 27, 2020

#116 in Science

Download history 63/week @ 2023-06-04 74/week @ 2023-06-11 29/week @ 2023-06-18 25/week @ 2023-06-25 32/week @ 2023-07-02 19/week @ 2023-07-09 25/week @ 2023-07-16 19/week @ 2023-07-23 31/week @ 2023-07-30 14/week @ 2023-08-06 39/week @ 2023-08-13 140/week @ 2023-08-20 122/week @ 2023-08-27 86/week @ 2023-09-03 41/week @ 2023-09-10 78/week @ 2023-09-17

352 downloads per month


15K SLoC

C++ 12K SLoC // 0.0% comments Rust 2.5K SLoC // 0.0% comments Python 513 SLoC // 0.2% comments Shell 15 SLoC


crate doc

Rust wrappers for NGT, which provides high-speed approximate nearest neighbor searches against a large volume of data in high dimensional vector data space (several ten to several thousand dimensions). The vector data can be f32, u8, or f16.

This crate provides the following indexes:

  • NgtIndex: Graph and tree based index[^1]
  • QgIndex: Quantized graph based index[^2]
  • QbgIndex: Quantized blob graph based index

Both quantized indexes are available through the quantized Cargo feature. Note that they rely on BLAS and LAPACK which thus have to be installed locally. Furthermore, QgIndex performances can be improved by using the qg_optim Cargo feature.

The NgtIndex default implementation is an ANNG. It can be optimized[^3] or converted to an ONNG through the optim module.

By default ngt-rs will be built dynamically, which requires CMake to build NGT. This means that you'll have to make the build artifact libngt.so available to your final binary (see an example in the CI). However the static feature will build and link NGT statically. Note that OpenMP will also be linked statically. If the quantized feature is used, then BLAS and LAPACK libraries will also be linked statically.

NGT's shared memory and large dataset features are available through the Cargo features shared_mem and large_data respectively.

[^1]: Graph and tree based method explanation

[^2]: Quantized graph based method explanation

[^3]: NGT index optimizations in Python