scann-core 0.2.1

Rust bindings for scann-core: ScaNN's approximate nearest-neighbour vector search core as a standalone library (derived from Google's ScaNN; not an official Google product)
Documentation

scann-core (Rust)

Rust bindings for scann-core: the nearest-neighbour search core of Google's ScaNN, as a standalone library.

scann-core is a derived work of ScaNN. It is not an official Google product and is not affiliated with or endorsed by Google.

use scann_core::{AhOptions, ConfigBuilder, DistanceMeasure, ReorderOptions,
                 SearchOptions, TreeOptions};

let index = ConfigBuilder::new(10, DistanceMeasure::DotProduct, dim)
    .tree(TreeOptions::new(2000, 100))
    .score_ah(AhOptions::new(2).anisotropic_quantization_threshold(0.2))
    .reorder(ReorderOptions::new(100))
    .build_index(&dataset)?;            // &[f32], row-major n x dim
let nn = index.search(query, SearchOptions::default())?;
println!("{:?} {:?}", nn.indices, nn.distances);

ScannIndex supports single, batched and parallel batched search, adding, updating and deleting points, retraining, and saving and loading. Indexes are interchangeable with scann-core's C++ and Python APIs (and upstream ScaNN's Python package). It is Send + Sync: search from as many threads as you like; changing the index takes &mut self.

Building

The crate builds the C++ library with CMake the first time it compiles, so you need:

  • CMake ≥ 3.27 and clang ≥ 19 or GCC ≥ 13 (clang is preferred when CXX isn't set);
  • Linux on x86-64 or aarch64 (both tested in CI);
  • network access to download the C++ dependencies (abseil, protobuf, highway, Eigen, zlib). To build offline, point CMake at local copies: SCANN_CORE_CMAKE_ARGS="-DFETCHCONTENT_SOURCE_DIR_ABSL=/src/abseil-cpp ..." (see the repository README).

The first build takes a few minutes; later builds in the same target directory reuse it. Each target directory (another project, CI, cargo install) builds the C++ library again; a compiler cache makes those rebuilds cheap, since CMake picks up the launcher from the environment:

export CMAKE_C_COMPILER_LAUNCHER=ccache CMAKE_CXX_COMPILER_LAUNCHER=ccache
export CCACHE_BASEDIR=$HOME   # hits across different target directories

(sccache works the same way.) The baseline instruction set is AVX + FMA on x86-64 and Armv8 Neon on aarch64; faster kernels (AVX2/AVX-512, SVE) are picked at run time when the CPU has them. SCANN_CORE_CMAKE_ARGS="-DSCANN_ARCH_FLAGS=-march=native" also lets the compiler use everything your CPU has for the rest of the code.

Documentation

License

Apache 2.0. ScaNN is Copyright The Google Research Authors; scann-core's additions and modifications are Copyright 2026 Elias Benali (@ebenali) and TheCleaners. See NOTICE.