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.7.0.tar.gz (671.5 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.7.0-cp313-cp313-manylinux_2_34_x86_64.whl (972.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.7.0-cp313-cp313-macosx_11_0_arm64.whl (783.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.7.0-cp313-cp313-macosx_10_12_x86_64.whl (889.9 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.7.0-cp312-cp312-manylinux_2_34_x86_64.whl (972.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (783.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.7.0-cp312-cp312-macosx_10_12_x86_64.whl (889.8 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.7.0-cp311-cp311-manylinux_2_34_x86_64.whl (972.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (788.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.7.0-cp311-cp311-macosx_10_12_x86_64.whl (896.1 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.7.0-cp310-cp310-manylinux_2_34_x86_64.whl (972.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (788.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.7.0-cp310-cp310-macosx_10_12_x86_64.whl (895.3 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for kannolo-0.7.0.tar.gz
Algorithm Hash digest
SHA256 3e1a7d001e1a517b7ba2f59cab0eb628e4a97009c103ea0fc390fa254f246fef
MD5 ffd5e6f4265454b60928aa46a0b9b6b6
BLAKE2b-256 ac0e367ac1f287f4d35454531a0d5f3394502ef954662be281a5a61199dc456e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6878f1ce74cee4690c7db6c0b31171e0bce1fc471b0e121a6ce41eef7829833d
MD5 66423022ec79e0fe775b3c8eb4a3b804
BLAKE2b-256 722d41804886ec2f5ee360369e18b71e5e8f5da8b83236a4cb62cc09db44ba5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 553952cdea5bf7dfd24a4c0c01f4d9354d7671091d719ab3472d8d1b0e6ab2de
MD5 af97314493e335bcdffb8516cadaa803
BLAKE2b-256 7d9d4d05f772217a16a2ad16e4eb2af5c6776783a5c1844fafdcdd03a00605c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d6e709874854dad24157151ba6f16359cd67dee9cdbd4f635fb2fa0e5a7803df
MD5 3a801b80f54ca9674a84150586ed6c9c
BLAKE2b-256 5014f3ae8b7795e05dfb5df38ce3e790f0159f7067de2505c5c6486e5c12962d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6c4ee26102f15c6c0ec15f2093039157709d64365925399cb2e669179d8e454a
MD5 18bfb7bfd956a3b4cff8f3e90df862f6
BLAKE2b-256 571885de36102cb26f2126ecf500d489a1cfcda8cbf69302b19587b128223b93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44aa5b16ae59145d51f509f7d380f68a5aaaa00b4d058b0ffcb5fd26133d213b
MD5 4c16d0b87131512b7e9c14962aa2fbfb
BLAKE2b-256 d1f2980fb8b7ca6aea2d9d388a1d3d892e4c6ae1bcacea52ee5166e8fcf1802a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cf17208f4b621583a16c29609d5239cf17cbd064ea74a699e91522ea6a2cd0f4
MD5 a6ee3de164793f41930a2a52b039c75b
BLAKE2b-256 9a0922d0a85254a7bc65e31387ad668c08c9fc385fa40988ed0b36d668f07070

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 32b33a7ab580b79d4a3860de899bd2464f47ac1e28bd2b13e2c69f744dff00ce
MD5 a39a89f7b7b23aab88d83339a71eb7dc
BLAKE2b-256 f8235aa11bf88fb751f90eb0e76aedcebaba28fc92cb57862c84ad1853ba273e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a08a984e8ed8b9f361db8cb7cc4e348dbe663c67fb285f1442048f2bc6c5eaa3
MD5 8a872cbecef0f273159c94b3cdafa426
BLAKE2b-256 7744d2763fecd5531adad08c8f0783f524393999ed4c0f06b58db6f5aa0c7f80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b9aacdb6b0a61469ef07509491784da731036bc11ba70704592189b039b6738f
MD5 d741afd475362f23b76924f3edda6f8a
BLAKE2b-256 c4d0d2c1d80ecfea9b530fc7ab7e54f9ec7211e536ede12d22710f30141d3438

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 38349edaeb1604c7de1ba4e5f6bf814e52ee19c22c7cd2f9b8073bff30cde7de
MD5 67260bd816a104c7bc00f54f38465b46
BLAKE2b-256 20669d514879d0475394b2453fe8a5f4cad31133c8f219bee2810648aaa22bb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f36ed0751284028c5c8262dc7dde4b3df93037729b8baea5337eff970c8355b
MD5 e79726b0d1a9a4a8868be2caaab30162
BLAKE2b-256 7eb57d80417965b050dd6b29a195bee9970de704d2adadb411ab578bb33e223b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.7.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 66b36fe3e54c02388a8946e37ab8410fe27aac40009fbcf6f06e835805bb6a9e
MD5 7579ed6a5a8fe67b534dbfabda5397f2
BLAKE2b-256 71bded9bf1ddfacde049a3e376fba2e7b460644c52fd5fab8814b802e2fc9da0

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