Skip to main content

ScaNN

ScaNN (Scalable Nearest Neighbors) is a method for efficient vector similarity search at scale. This code implements [1, 2], which includes search space pruning and quantization for Maximum Inner Product Search and also supports other distance functions such as Euclidean distance. The implementation is optimized for x86 processors with AVX support. ScaNN achieves state-of-the-art performance on ann-benchmarks.com as shown on the glove-100-angular dataset below:

glove-100-angular

ScaNN can be configured to fit datasets with different sizes and distributions. It has both TensorFlow and Python APIs. The library shows strong performance with large datasets [1, 2]. The code is released for research purposes. For more details on the academic description of algorithms, please see below.

References:

  1. @inproceedings{avq_2020,
      title={Accelerating Large-Scale Inference with Anisotropic Vector Quantization},
      author={Guo, Ruiqi and Sun, Philip and Lindgren, Erik and Geng, Quan and Simcha, David and Chern, Felix and Kumar, Sanjiv},
      booktitle={International Conference on Machine Learning},
      year={2020},
      URL={https://arxiv.org/abs/1908.10396}
    }
    
  2. @inproceedings{soar_2023,
      title={SOAR: Improved Indexing for Approximate Nearest Neighbor Search},
      author={Sun, Philip and Simcha, David and Dopson, Dave and Guo, Ruiqi and Kumar, Sanjiv},
      booktitle={Neural Information Processing Systems},
      year={2023},
      URL={https://arxiv.org/abs/2404.00774}
    }
    

Installation

manylinux_2_27-compatible wheels are available on PyPI:

pip install scann

ScaNN supports Linux environments running Python versions 3.9-3.12. See docs/releases.md for release notes; the page also contains download links for ScaNN wheels prior to version 1.1.0, which were not released on PyPI. The x86 wheels require AVX and FMA instruction set support, while the ARM wheels require NEON.

In accordance with the manylinux_2_27 specification, ScaNN requires libstdc++ version 3.4.23 or above from the operating system. See here for an example of how to find your system's libstdc++ version; it can generally be upgraded by installing a newer version of g++.

Using ScaNN with TensorFlow

ScaNN has optional TensorFlow op bindings that allow ScaNN's nearest neighbor search functionality to be embedded into a TensorFlow SavedModel. As of ScaNN 1.4.0, this functionality is no longer enabled by default, and pip install scann[tf] is now needed to enable the TensorFlow integration.

If scann[tf] is installed, the TensorFlow ops can be accessed via scann.scann_ops, and the API is almost identical to scann.scann_ops_pybind. For users not already in the TensorFlow ecosystem, the native Python bindings in scann.scann_ops_pybind are a better fit, which is why the TensorFlow ops are an optional extra.

Integration with TensorFlow Serving

We provide custom Docker images of TF Serving that are linked to the ScaNN TF ops. See the tf_serving directory for further information.

Usage

See the example in docs/example.ipynb. For a more in-depth explanation of ScaNN techniques, see docs/algorithms.md.

Building from source

To build ScaNN from source, first install the build tool bazel (use version 7.x), Clang 18, and libstdc++ headers for C++17 (which are provided with GCC 9). Additionally, ScaNN requires a modern version of Python (3.9.x or later) and Tensorflow 2.19 installed on that version of Python. Once these prerequisites are satisfied, run the following command in the root directory of the repository:

python configure.py
CC=clang-18 bazel build -c opt --features=thin_lto --copt=-mavx --copt=-mfma --cxxopt="-std=c++17" --copt=-fsized-deallocation --copt=-w :build_pip_pkg
./bazel-bin/build_pip_pkg

To build an ARM binary from an ARM machine, the prerequisites are the same, but the compile flags are slightly modified:

python configure.py
CC=clang-18 bazel build -c opt --features=thin_lto --copt=-march=armv8-a+simd --cxxopt="-std=c++17" --copt=-fsized-deallocation --copt=-w :build_pip_pkg
./bazel-bin/build_pip_pkg

A .whl file should appear in the root of the repository upon successful completion of these commands. This .whl can be installed via pip.

Release files for scann 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for scann 1.4.0
File
scann-1.4.0-cp312-cp312-manylinux_2_27_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64 Details
scann-1.4.0-cp312-cp312-manylinux_2_27_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ ARM64 Details
scann-1.4.0-cp311-cp311-manylinux_2_27_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64 Details
scann-1.4.0-cp311-cp311-manylinux_2_27_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ ARM64 Details
scann-1.4.0-cp310-cp310-manylinux_2_27_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64 Details
scann-1.4.0-cp310-cp310-manylinux_2_27_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ ARM64 Details
scann-1.4.0-cp39-cp39-manylinux_2_27_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.27+ x86-64 Details
scann-1.4.0-cp39-cp39-manylinux_2_27_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.27+ ARM64 Details

Total release size: 85.2 MB

Release files / scann-1.4.0-cp312-cp312-manylinux_2_27_x86_64.whl

Download URL scann-1.4.0-cp312-cp312-manylinux_2_27_x86_64.whl
Size 11.8 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
674d4946c1fd657998cb6c95a37b337f0b48e5d72f28fdff3d0f01a2de028080
BLAKE2b-256 checksum
How to use checksums
96b524b82f84cd772aab41283278690c9ea15c2c96cead1f50ce683d676ad850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp312-cp312-manylinux_2_27_aarch64.whl

Download URL scann-1.4.0-cp312-cp312-manylinux_2_27_aarch64.whl
Size 9.5 MB
Tags CPython 3.12 Linux glibc 2.27+ ARM64
SHA-256 checksum
How to use checksums
a1e7c845d96ed11095bc4fdbb54449f44057de6cb5438b7df7ed2ff36c9ef957
BLAKE2b-256 checksum
How to use checksums
eb893a66a11750d5ad6382dfe5ac15d5b2f0a5e3bb4bd0976974277083f3a2d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp311-cp311-manylinux_2_27_x86_64.whl

Download URL scann-1.4.0-cp311-cp311-manylinux_2_27_x86_64.whl
Size 11.8 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
24b4d7ce4f056a4ac2cabe026662ce02795263ab3457d98703a40d9d08e63807
BLAKE2b-256 checksum
How to use checksums
0d77cdaefa00942fd24c1fd7915617d9117cece6ee0f18cdad44506f215f5aab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp311-cp311-manylinux_2_27_aarch64.whl

Download URL scann-1.4.0-cp311-cp311-manylinux_2_27_aarch64.whl
Size 9.5 MB
Tags CPython 3.11 Linux glibc 2.27+ ARM64
SHA-256 checksum
How to use checksums
2324bf37daef28bf611e1d309c76c7de224611db0b29abc2f50be79ed7b601b2
BLAKE2b-256 checksum
How to use checksums
1aeb50a8c25a72c4a583686b865c47e49b4780ae047d35cd767d8e1984822eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp310-cp310-manylinux_2_27_x86_64.whl

Download URL scann-1.4.0-cp310-cp310-manylinux_2_27_x86_64.whl
Size 11.8 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
c80630ba8628d6e151571de779f60a3089df02576acac7d20c6f1d381433b7f4
BLAKE2b-256 checksum
How to use checksums
8133e31bd4a7523c483ca4768e8a3e62ba68d4e4d0e14c74eafaeae70a1e517e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp310-cp310-manylinux_2_27_aarch64.whl

Download URL scann-1.4.0-cp310-cp310-manylinux_2_27_aarch64.whl
Size 9.5 MB
Tags CPython 3.10 Linux glibc 2.27+ ARM64
SHA-256 checksum
How to use checksums
0b5a4a47abcf861f9bd7354ece8ab317bf63afe107f9c79bcac5df07fed8f7f0
BLAKE2b-256 checksum
How to use checksums
92bb55fac6a9eb29cd6ced9861130cfcaf9174409c781ede7da975ce03755abe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp39-cp39-manylinux_2_27_x86_64.whl

Download URL scann-1.4.0-cp39-cp39-manylinux_2_27_x86_64.whl
Size 11.8 MB
Tags CPython 3.9 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
86b36eecfe9d109ee09066ba6969e51589585056e6f5066e63af78e255367e98
BLAKE2b-256 checksum
How to use checksums
ca0e11665f1e047302b081d80714202b41b62cb13913da18b823788c8f487c03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / scann-1.4.0-cp39-cp39-manylinux_2_27_aarch64.whl

Download URL scann-1.4.0-cp39-cp39-manylinux_2_27_aarch64.whl
Size 9.5 MB
Tags CPython 3.9 Linux glibc 2.27+ ARM64
SHA-256 checksum
How to use checksums
5caef92a28e34d8104fda0d291e922b3bdc272c225345d5b617f3215775a7ce2
BLAKE2b-256 checksum
How to use checksums
8afefaf3a6ae6f37f74dbde7d4e102c8388cdc713874ca18703cd606db97acce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

1.4.2

10 release files

1.4.1

4 release files

This release

1.4.0 This release

8 release files

1.3.5

8 release files

1.3.4

4 release files

1.3.3

4 release files

1.3.2

4 release files

1.3.1

4 release files

1.3.0

3 release files

1.2.9

4 release files

1.2.8

4 release files

1.2.7

4 release files

1.2.6

3 release files

1.2.5

3 release files

1.2.4

3 release files

1.2.3

4 release files

1.2.2

4 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.1

4 release files

1.1.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page