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.1.tar.gz (652.7 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.1-cp313-cp313-manylinux_2_34_x86_64.whl (899.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.5.1-cp313-cp313-macosx_11_0_arm64.whl (741.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.5.1-cp313-cp313-macosx_10_12_x86_64.whl (831.4 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl (899.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.5.1-cp312-cp312-macosx_11_0_arm64.whl (741.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl (831.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl (901.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.5.1-cp311-cp311-macosx_11_0_arm64.whl (742.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl (838.3 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl (901.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.5.1-cp310-cp310-macosx_11_0_arm64.whl (742.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl (838.2 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kannolo-0.5.1.tar.gz
  • Upload date:
  • Size: 652.7 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.1.tar.gz
Algorithm Hash digest
SHA256 042041a3f6de107b1afffaa20664af386247cc0fba35bea2fbb574632e3b4aa9
MD5 d67444661bb9a34abcc4d1b5a86807cc
BLAKE2b-256 dfb28f632f89436edd1432b2496de84916e8bf9cdaec261510d3f305eda79b4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bb29f82f2c36ccc365a12abc059522272967d78f006885735e432f5d986bf918
MD5 e067cb071bc3bb69641348c55847678f
BLAKE2b-256 1c3ac266e65d5db4b61ccc7332adf60551bb9002bc38ed8fffff36609d8c06b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d328b9a6584ddc75aff5d3085c31693074976d4e1bc3e3361a75e3b974cf5e5
MD5 3e8972340eb0cb7171be9b6d650af65f
BLAKE2b-256 8a8ce13d8d20bee1adb4529a9ed5a2e0cbd3fcf96a958efbafd0775503b180f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 148834bbcc3963c51682f45dc8609e7a2f07a5ddd0b6113978c2e0480e0a61cb
MD5 5c041f7a52ef61551e867e7bedbc3d95
BLAKE2b-256 28ebf5833705b03d6ed56af422f1035cceec2d17380334b592edbcfbf0afaa57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5140105bbaf6bd4b43640ca0410affa20a01c22f2997f5c29d347e9cbcf39428
MD5 1cdace72d9f55818822639e532c56fc5
BLAKE2b-256 3311bb8cb6f6051d5a4ae6e0b3066852da7cdf0542c15db026b862c1ca38b7ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1d37bcc64bc7b0fac74199d309217935259c5cb19839fec14cf7e7742360c340
MD5 04218da9e55f5b8b72313b66c152e8b7
BLAKE2b-256 4328407d4053a918daf53a5eb7ea4c8944d9416183bc7c13dd7c8cdac209d84b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8c286df4a69d2c5689c001575130a532d3926f2351a1fdc1a8e3973045669953
MD5 6214e4a3069e403feebb2e133302d4e7
BLAKE2b-256 0d42cf006300af42dc67e926058c4b5b17f0e8c23d23e837a2f220a5ab6fff77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ad7da427cb39698d33c89da19895abd6a3140a88236ec0a67524677c2b7a2081
MD5 faa85b6d805745525ee4aadec7b7e01a
BLAKE2b-256 def70ffd8e40983e5295af42318115c38a93d2fb896f3da2f5e01010577dab6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8b5b46cfa224feea6e4b774e207180464e8fe03765b4794e73c987066d6dbdc
MD5 eb9c957c81c044c4978cf3de9efd5ef0
BLAKE2b-256 e13906aa45c765b08d65cd5609e4bb841ee706a9da87a9bcda015b5c856bcf2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 175b535c23ca08a9fcd94fe15d9920ac950d0fdbb24deab20b4d0e5e40c7b794
MD5 ea387166758bb6369e67456dab28bc33
BLAKE2b-256 5f334c69419574c5695e2967583bb49ea4876732902f93738e0df9f76d20b813

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 69ef4703edced99c020740f471ae9c41b2bb4a6843302eb68e67fb1f6e5674bf
MD5 171d3f6467ff48d0f624dfd4a56ddd23
BLAKE2b-256 c7893a4020d7bb80b4884fe917da48f3090080acf8bab283591ae81d030ab7ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86c5ec556f584c5543c0345c00d90a9dde3659fe273b8ad9814730ac7b919c86
MD5 54aaaee3e737b32424a466a79a4ab68f
BLAKE2b-256 fda6b36f02b8311202f9c7fece96f689791cdb8c9492611002fc109e24bb76d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e1284f8998982009fbd27469d9b84c3c39e1946fabacb319920852f506c676fb
MD5 5966adb0ed3279f76e3fd17842d48fd6
BLAKE2b-256 1f08340d7c1e6c45268ddc219a6f0ebeb74163963a4d91121c5b92bd82222ac5

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