Skip to main content

Python interface for the kANNolo library

Project description

kANNolo

kANNolo is a research-oriented library for Approximate Nearest Neighbors (ANN) search written in Rust 🦀. It is explicitly designed to combine usability with performance effectively. Designed with modularity and researchers in mind, kANNolo makes prototyping new ANN search algorithms and data structures easy. kANNolo supports both dense and sparse embeddings seamlessly. It implements the HNSW graph index and Product Quantization.

Python Installation

Quick start (prebuilt wheels)

For most users, this is the easiest option:

pip install kannolo

The prebuilt wheel includes dense and sparse HNSW indexes. If a compatible wheel exists for your platform, pip downloads and installs it directly. If not, pip compiles from source.

To use multivector reranking (SparseMultivecRerankIndex, SparseMultivecTwoLevelsPQRerankIndex), build from source with the multivec feature enabled (see Building from source below).

Building from source (maximum performance)

For maximum performance optimized to your CPU, build from source. Choose one of the two approaches below:

Shared Prerequisites

Both building approaches require Rust and nightly:

  1. Install Rust (via rustup):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Activate nightly:
rustup install nightly
rustup default nightly

Approach 1: Build from PyPI source

Compile and install directly from PyPI with CPU optimization (dense and sparse indexes only):

RUSTFLAGS="-C target-cpu=native" pip install --no-binary :all: kannolo

This installs the package in your system/virtual environment site-packages. For multivector reranking support, use Approach 2 instead.

Approach 2: Build from GitHub (development mode)

Clone the repository and build for development/modification:

  1. Clone and prepare:
git clone https://github.com/TusKANNy/kannolo.git
cd kannolo
  1. Create a virtual environment (recommended):
python3 -m venv ./venv
source ./venv/bin/activate  # On Windows: venv\Scripts\activate

Alternatively, use conda:

conda create -n kannolo python=3.11
conda activate kannolo
  1. Install maturin:
pip install maturin
  1. Build and install in editable mode:

    Dense and sparse indexes only (default, lighter build):

    RUSTFLAGS="-C target-cpu=native" maturin develop --release
    

    With multivector reranking support (SparseMultivecRerankIndex, SparseMultivecTwoLevelsPQRerankIndex):

    RUSTFLAGS="-C target-cpu=native" maturin develop --release --features multivec
    

Why use editable mode? Changes to Python code take effect immediately without reinstalling. Perfect for development and prototyping.

  1. Verify installation:
python -c "import kannolo; print('Successfully installed kannolo!')"

Rust

The crate exposes three feature flags:

Feature What it enables Default
multivec Multivector reranking indexes (SparseMultivecRerankIndex, SparseMultivecTwoLevelsPQRerankIndex) and the hnsw_rerank_search CLI binary No
python PyO3 bindings — activated automatically by maturin when building the Python wheel No
cli CLI binaries: hnsw_build, hnsw_search (combine with multivec to also get hnsw_rerank_search) No

If you want to compile the library only (dense and sparse indexes, no multivec, no binaries):

RUSTFLAGS="-C target-cpu=native" cargo build --release

If you want the CLI binaries hnsw_build and hnsw_search (dense and sparse):

RUSTFLAGS="-C target-cpu=native" cargo build --release --features cli

If you want multivector reranking in the library (adds SparseMultivecRerankIndex and SparseMultivecTwoLevelsPQRerankIndex):

RUSTFLAGS="-C target-cpu=native" cargo build --release --features multivec

If you want all CLI binaries including hnsw_rerank_search:

RUSTFLAGS="-C target-cpu=native" cargo build --release --features "cli,multivec"

The resulting binaries are placed in target/release/.

Details on how to use kANNolo's core engine in Rust 🦀 can be found in docs/RustUsage.md.

Details on how to use kANNolo's Python interface can be found in docs/PythonUsage.md.

Resources

Check out our docs folder for a more detailed guide on how to use kANNolo directly in Rust, replicate the results of our paper, or use kANNolo with your custom collection.

📚 Bibliography

Leonardo Delfino, Domenico Erriquez, Silvio Martinico, Franco Maria Nardini, Cosimo Rulli and Rossano Venturini. "kANNolo: Sweet and Smooth Approximate k-Nearest Neighbors Search." Proc. ECIR. 2025.

Citation License

The source code in this repository is subject to the following citation license:

By downloading and using this software, you agree to cite the under-noted paper in any kind of material you produce where it was used to conduct a search or experimentation, whether be it a research paper, dissertation, article, poster, presentation, or documentation. By using this software, you have agreed to the citation license.

ECIR 2025

@InProceedings{10.1007/978-3-031-88717-8_29,
author =    "Leonardo Delfino and
             Domenico Erriquez and
             Silvio Martinico and
             Franco Maria Nardini and
             Cosimo Rulli and
             Rossano Venturini",
title =     "kANNolo: Sweet and Smooth Approximate k-Nearest Neighbors Search",
booktitle = "Advances in Information Retrieval",
year =      "2025",
publisher = "Springer Nature Switzerland",
pages =     "400--406",
isbn =      "978-3-031-88717-8"
}

Project details


Download files

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

Source Distribution

kannolo-0.5.0.tar.gz (653.0 kB view details)

Uploaded Source

Built Distributions

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

kannolo-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl (900.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (743.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl (828.3 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl (900.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (743.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl (828.4 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl (902.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (745.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl (834.2 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl (902.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.5.0-cp310-cp310-macosx_11_0_arm64.whl (745.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.5.0-cp310-cp310-macosx_10_12_x86_64.whl (834.1 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file kannolo-0.5.0.tar.gz.

File metadata

  • Download URL: kannolo-0.5.0.tar.gz
  • Upload date:
  • Size: 653.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kannolo-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7a6ace1559f9d5764b61f082ac7c8ce36a02dacd707cb502653223537eb005eb
MD5 3dc0d2732245384c31998df8c5a831c7
BLAKE2b-256 b545145c305bcb804c0e84eab09d862cfa78df3575082871cbac039aa491d2a0

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 89aaeb9df58cc71d9a2c105ec8aac7841143c65838712a57e9abb3c2a8045d76
MD5 3126c4b11f1357d79c9f342566dcfb0f
BLAKE2b-256 187858483a64f2a345a95c7ff3561bde87c0d2a391779e984f8657420d78c077

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e12c7fc0f0bdcb0f8ba885464e44e49d3f98d0fd186991e6db7ed8fa7425b3fd
MD5 0f1bb6076b01b92caee6862b724c2db9
BLAKE2b-256 fdf501e137f413acea303fce3cb622ce0e0dd21f2f5752c339e7be3216b7fdb1

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5f39a594874db26972853b7169c4a6a8999e34c49645bc97caac3fafc0234e18
MD5 8b308858c56aef1818366feb6d473eae
BLAKE2b-256 cb562a33f9b6e8450641ad8c1b925dad3d93784d4151ea2676f1fab687b77d22

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d8dfdc24fcb469d6fd8d19e27502406adbd88272d676c8f1aa9a11af95e53877
MD5 d8d94c4e8a1cb6b1453b3c99958b4a5c
BLAKE2b-256 975758739f0350d8e45bb77ebc01722f6c58265e43598c5a0239e3ed10f72ff1

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 527788358ef4e6335e1bd186e2beb8b179152e75be12c4847b2890bc8f3bd7a7
MD5 e1f891b4cef516cd7db2a06343033673
BLAKE2b-256 ee023a1222a9916b29ec8092ec3eb47fca6ee4616f7e08d6c8bc5d498654acbd

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eef376e29782c158b8374d26b34430813cea998d2c128c9737668842f074aad4
MD5 e87bc8f074ef2b3aa4ab6379783a1cc5
BLAKE2b-256 6e486fcc2a040999425652b397550265740bdeaeb69dbca587999541ebfd2066

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 775ad63b1eaafe6e9c2a20ad42aa0d8484481cc810082a395e8d5206ac1cdd1c
MD5 22a50f00b847207625586cd0928cdc77
BLAKE2b-256 814846092e40deeca1de72f48e3218b6e60ab8c4959c3bb0b1a55ab42003da91

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a3fa3a7932a0cda817590e8fb05cec40735d8c9a32a04907f5707367c0d7911
MD5 c9e7272234703497d0a34d933fc394f9
BLAKE2b-256 bb72b63a57dfffb5167d6c43485e21ae9586e5be99a52df9e118da4eac9394ab

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a57947725098497b2236e8ca0a91b01a2764ea1b0a7257b35740c1f258a3c84a
MD5 1901e090f7d45c878ab84dbb3a7c1a13
BLAKE2b-256 170ba69c1df463110bbec5bd4d72e02509aaae93e6c4ae33a02ce139d38547e2

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 83359f87d714a6dee422d5545378f22176db420f61848b49bcaeeee4deec157b
MD5 2471aad60f8fb61ec4614fe7a5a165cf
BLAKE2b-256 b5a604749ab285424c0f85c93fb0e47458aa07d556a44334e65b603986cf1aa1

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c662bb7f56b6b4b1aa083ae9892a69f5c83a348a8b08bac4fec56e75a9190404
MD5 f8895857806a12ecc7d5e58779904ec7
BLAKE2b-256 9a34195c1266d2a43c3410e0aaf8516d36e611a56bc446defb7ef0ea368fd09f

See more details on using hashes here.

File details

Details for the file kannolo-0.5.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kannolo-0.5.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d7a308e34e4ba9631a2d11a86a77daa77292d189af8b8a72c547fab4b7542298
MD5 bf092cebdc8c7fecf4dd014eeda14216
BLAKE2b-256 f7e7f3939be9955e22f45e2ee56092470ce099259e247b4ca0f1c6145d21eefd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page