Skip to main content

RaBitQ Library

Compact vectors. Accurate distances. Fast ANN search.

A research-backed C++17 library with Python bindings for 1-bit and multi-bit
vector quantization, IVF, HNSW, and SymphonyQG.

PyPI Python versions Documentation Paper DOI License

Documentation · Python package · Paper · Releases

News

  • September 2026 — Quantized SymphonyQG: SymphonyQG now supports optional 4-bit and 8-bit RaBitQ vector storage. Select QG-quant with quantization_bits=4 or quantization_bits=8; vanilla raw-vector QG remains the default. See the SymphonyQG documentation for details.

Install

pip install rabitqlib

Prebuilt wheels support Linux x86-64 and CPython 3.11–3.14. AVX2 + FMA is the portable CPU baseline; supported AVX-512 kernels are selected at runtime.

RaBitQ across the vector-search ecosystem

Milvus logo
Milvus
Faiss logo
Faiss
NVIDIA cuVS logo
NVIDIA cuVS
Microsoft DiskANN logo
Microsoft DiskANN
VSAG logo
VSAG
VectorChord logo
VectorChord
Volcengine OpenSearch logo
Volcengine OpenSearch
CockroachDB logo
CockroachDB
Elasticsearch logo
Elasticsearch
Apache Lucene logo
Apache Lucene
turbopuffer logo
turbopuffer
Zvec logo
Zvec
LanceDB logo
LanceDB
Databricks logo
Databricks
ClickHouse logo
ClickHouse
Qdrant logo
Qdrant
Weaviate logo
Weaviate

Accuracy at a glance

RaBitQ estimation error benchmark across MSong, YouTube, OpenAI embeddings, Word2Vec, and GIST

Average and maximum relative estimation error across six datasets; lower is better. Results from the SIGMOD camera-ready paper.

Why RaBitQ?

Compact by design Choose 1-bit or multi-bit codes to match your memory and accuracy target.
Accurate estimates An asymptotically optimal theoretical error bound supports reliable ordering and reranking.
Fast on x86-64 Dedicated AVX2 and AVX-512 kernels are selected through runtime CPU dispatch.
Ready for ANN search Use the quantizer directly or build complete IVF, HNSW, and SymphonyQG indexes.

The library supports Euclidean distance and inner product. Cosine search is available by normalizing vectors before using inner product.

RaBitQ is developed by the VectorDB group at Nanyang Technological University, Singapore. A GPU implementation is also available in cuvs_rabitq.

Python quick start

The following complete example builds a small IVF index and searches it. It uses deterministic synthetic data, so no dataset download is required.

import numpy as np
from rabitqlib import IvfIndex

rng = np.random.default_rng(42)
data = rng.standard_normal((500, 64)).astype(np.float32)
queries = rng.standard_normal((5, 64)).astype(np.float32)

# Assign vectors to five clusters and calculate their centroids.
cluster_ids = (np.arange(len(data)) % 5).astype(np.uint32)
centroids = np.stack(
    [data[cluster_ids == cluster].mean(axis=0) for cluster in range(5)]
).astype(np.float32)

index = IvfIndex(
    dim=64,
    max_elements=len(data),
    num_clusters=5,
    nbits=4,
    metric="l2",
)
index.build(data, centroids, cluster_ids)

ids, distances = index.search(queries, k=10, nprobe=5)
print(ids.shape, distances.shape)  # (5, 10) (5, 10)
print(ids[0])

Python bindings are also available for HnswIndex and SymqgIndex. See the Python examples for index construction, querying, and index persistence.

Build the Python bindings from source

Source builds require a C++17 compiler, CMake 3.15 or newer, and OpenMP. On Ubuntu or Debian:

sudo apt-get update
sudo apt-get install -y build-essential cmake libomp-dev
git clone https://github.com/VectorDB-NTU/RaBitQ-Library.git
cd RaBitQ-Library
python -m pip install .

C++ quick start

Requirements

  • CMake 3.15 or newer
  • a C++17 compiler with OpenMP support
  • an x86-64 CPU supported by the selected kernels: most paths accept either AVX2 with FMA or AVX-512F/BW/DQ with FMA
CPU dispatch details

Most SIMD entry points select AVX-512 kernels when AVX-512F, AVX-512BW, and AVX-512DQ are detected; otherwise they use AVX2 when AVX2 and FMA are available. AVX-512 VPOPCNTDQ enables additional popcount kernels. The HNSW AVX-512 core path also checks for AVX2 and FMA. AVX-512 translation units are compiled with FMA enabled.

Clone and build the library and example programs:

git clone https://github.com/VectorDB-NTU/RaBitQ-Library.git
cd RaBitQ-Library

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel

Release builds enable native CPU tuning by default. To build a binary that can be moved between AVX2- and AVX-512-capable machines, configure with -DRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF; the ISA-specific kernels will still be selected at runtime.

Use RaBitQ-Library in another C++ project

The C++ API and ABI are still evolving. For reproducible builds, pin a release or commit and include RaBitQ-Library as a Git submodule:

git submodule add https://github.com/VectorDB-NTU/RaBitQ-Library.git third_party/rabitqlib
git submodule update --init --recursive

Add the library and link its namespaced target in the consuming project's CMakeLists.txt:

set(RABITQ_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(third_party/rabitqlib)

target_link_libraries(my_program PRIVATE rabitqlib::rabitqlib)

Update the pinned revision deliberately when you are ready to adopt upstream changes:

git -C third_party/rabitqlib fetch
git -C third_party/rabitqlib checkout <release-or-commit>
git add third_party/rabitqlib
Optional: install the C++ library

Installation is useful for package managers, container images, and shared server environments. Disable native optimization when the installed library may run on a different CPU from the build machine:

cmake -S . -B build \
  -DRABITQ_BUILD_SAMPLES=OFF \
  -DRABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX="$HOME/.local"
cmake --build build --parallel
cmake --install build

Consume the installed package with:

find_package(rabitqlib CONFIG REQUIRED)
target_link_libraries(my_program PRIVATE rabitqlib::rabitqlib)

For a non-system prefix, point CMake to the installation when configuring the consumer:

cmake -S . -B build -DCMAKE_PREFIX_PATH="$HOME/.local"
cmake --build build --parallel

The downstream consumer test provides a minimal complete example of the installed-package workflow.

Both integration methods require OpenMP on the consuming system.

The index example executables are written to bin/. Their source code shows the complete indexing and querying workflows:

A separate RaBitQ quantization example demonstrates the lower-level quantizer API; it is provided as source and is not currently a CMake target.

To build and run the C++ test suite:

cmake -S . -B build -DRABITQ_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure

GoogleTest is downloaded during test configuration. For a full benchmark on the GIST dataset, see example.sh. More detailed API and algorithm guidance is available in the documentation.

Choose the right building block

Component Best fit Storage and search profile
Quantizer Integrating RaBitQ into an existing system Low-level 1-bit or multi-bit encoding and distance estimation.
IVF Memory-efficient partitioned search Stores quantized codes without retaining the raw dataset.
HNSW Graph search with compact vectors Adds graph links and searches directly from quantized codes.
SymphonyQG Fast graph search with a configurable memory/accuracy tradeoff Uses raw vectors by default, or optional packed 4-bit/8-bit RaBitQ vectors, alongside per-neighborhood quantization data.

IVF and SymphonyQG use FastScan for batched estimates, while HNSW uses single-code AVX2 or AVX-512 kernels.

In typical workloads, 4-bit, 5-bit, and 7-bit quantization can achieve roughly 90%, 95%, and 99% recall, respectively, without reranking. Actual results depend on the dataset, index configuration, and search parameters.

Citation

If RaBitQ helps your research or system, please cite:

Jianyang Gao, Yutong Gou, Yuexuan Xu, Yongyi Yang, Cheng Long, and Raymond Chi-Wing Wong. “Practical and Asymptotically Optimal Quantization of High-Dimensional Vectors in Euclidean Space for Approximate Nearest Neighbor Search.” Proceedings of the ACM on Management of Data 3, 3, Article 202 (June 2025), 26 pages. https://doi.org/10.1145/3725413.

Yutong Gou, Jianyang Gao, Yuexuan Xu, and Cheng Long. “SymphonyQG: Towards Symphonious Integration of Quantization and Graph for Approximate Nearest Neighbor Search.” Proceedings of the ACM on Management of Data 3, 1, Article 80 (February 2025), 26 pages. https://doi.org/10.1145/3709730.

Jianyang Gao and Cheng Long. “RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search.” Proceedings of the ACM on Management of Data 2, 3, Article 167 (May 2024), 27 pages. https://doi.org/10.1145/3654970.

Contributing

Contributions are welcome. See the contributing guide for the build, formatting, pre-commit, and static-analysis workflows.

Acknowledgements

RaBitQ Library is developed by Yutong Gou, Jianyang Gao, Yuexuan Xu, Jifan Shi, and Zhonghao Yang. We thank Alexandr Guzhva, Li Liu, Chao Gao, Silu Huang, Jiabao Jin, Xiaoyao Zhong, and Jinjing Zhou for their valuable feedback.

License

RaBitQ Library is available under the Apache License 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rabitqlib-0.3.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rabitqlib-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rabitqlib-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rabitqlib-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file rabitqlib-0.3.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rabitqlib-0.3.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4302bef28a71cbfdaf55903dda08b534d7de1547608baed154b10cc37f86157b
MD5 6e886a8f4be04177ee584480f77ac3ef
BLAKE2b-256 41fa81f30a58023375c3d4a2ba71c6b6264fc1a1f858ae69fc2b062ce638430b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabitqlib-0.3.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on VectorDB-NTU/RaBitQ-Library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rabitqlib-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rabitqlib-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97b292a73d40959230d8a2600670120049f400f6e5782b2386954914e13f818d
MD5 67511bb7205e85e584393211807ae61f
BLAKE2b-256 cc42339f053172b0b1d25e276a5ce4b2541b30671000c93d3f14afbc96a76874

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabitqlib-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on VectorDB-NTU/RaBitQ-Library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rabitqlib-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rabitqlib-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18cccc171f66a09576a1f06b142403429158acffc10e1b3760c0f8b58189a003
MD5 915bcbba67689235eaf26cdc3a8423ab
BLAKE2b-256 2f686491f31a07906b2b42288073934e3c3b3a269ef343ba250dc51c23d77cd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabitqlib-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on VectorDB-NTU/RaBitQ-Library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rabitqlib-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rabitqlib-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 beb1f2c084e390c9dfae99f53ed086d9ad06b4797e01e5b0b2346c4dcc7d08a5
MD5 57e30fde5950c4fe933c9004a5359179
BLAKE2b-256 a37560f0bbe341eb8097896281ab5cc10f65ae82f067c5e4d9b30e265ed4a90a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rabitqlib-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on VectorDB-NTU/RaBitQ-Library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.2

4 files

This release

0.3.1 This release

4 files

0.3.0

4 files

0.2.2

4 files

0.2.1

4 files

0.2.0

6 files

0.1.0

1 file

0.0.1

2 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