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.3.tar.gz (652.4 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.3-cp313-cp313-manylinux_2_34_x86_64.whl (899.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.5.3-cp313-cp313-macosx_11_0_arm64.whl (740.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.5.3-cp312-cp312-manylinux_2_34_x86_64.whl (899.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.5.3-cp312-cp312-macosx_11_0_arm64.whl (740.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.5.3-cp312-cp312-macosx_10_12_x86_64.whl (831.5 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.5.3-cp311-cp311-manylinux_2_34_x86_64.whl (900.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.5.3-cp311-cp311-macosx_11_0_arm64.whl (744.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.5.3-cp311-cp311-macosx_10_12_x86_64.whl (833.0 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.5.3-cp310-cp310-manylinux_2_34_x86_64.whl (900.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.5.3-cp310-cp310-macosx_11_0_arm64.whl (744.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.5.3-cp310-cp310-macosx_10_12_x86_64.whl (833.3 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kannolo-0.5.3.tar.gz
  • Upload date:
  • Size: 652.4 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.3.tar.gz
Algorithm Hash digest
SHA256 83e1d5eb9f5bc7a1e90eede7219e696d9c371411ba2a69bdd92d270931828641
MD5 aa46ad74e1b65e34e058175603e8996a
BLAKE2b-256 ac2258e5b6e3388abdc156f2e2067682c4ff5ea24fcee999abbe2bb431eee847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 38939952b02a79d5709d35ad71198722b15196fc1e0319142d454c7c22d37e11
MD5 7c4bd9acd1d7c06ea946403fd36fb2b4
BLAKE2b-256 5e149287eba541840d71a2badae638352db9858293a9d22832fb5b0df32f0a6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95210a705ae0eb6b6f08ab8a0a35d6a3a1b044753ae0a834f04de2f22a0cd71c
MD5 0e49747d59994f2f03e753c420277c31
BLAKE2b-256 b296367c1691670a12e55a2dd9129bca0aa961f447f4ee2aa6f660945088d91c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b6d14a99ef8857fe56b1e40edc4398c8f909e003e430fcc03dae4856e760cf63
MD5 5b9f4e3065c2214b914fd62229938de6
BLAKE2b-256 0ab2f89877dc556406e3ca20a7dbd29ed2920be4cf05834b37342d76c333bc37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 61f355b5af91ff0aa6db8fe7fc2ceb1c3df7b0077f01d3b9bd3f188a3a90ad49
MD5 c241e73bbab3731a88f40570376187a9
BLAKE2b-256 117c2b1922a6600a402edfd841fc5f3bdff4405b58c2bd08a7cc8a0fc36de61c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 506d26e130f39c5b891c98888ad768243da84027d49ac4ebec9f6ba08583d0e4
MD5 329d497bf5bd1e8978c859f9899473c5
BLAKE2b-256 6b68c4983a65c36df91ed9f17ed34ee3bff31932d8d55ff84c12590d694bf9b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 71dad40f89b53d5402f0b731d6e71dfa48cb623132128aaf9e378edd617f8ffb
MD5 9dc4cd644357c62c188556f9166daebf
BLAKE2b-256 9815e4eaed3e6569192ca8b35be2ced014ab6894572af783a26f0d49053920a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3ae3b5cb48fbfad6e0416634493a8f26b6710f8ff582a88b8fac22dcfb96c639
MD5 1cf5ee80833ebc16015f46f63cb4b955
BLAKE2b-256 36c4a33c1c81335c5a2b717c406b04d9e2787ef0815544940b253fd03c794daf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ad98a32b65de2673465187f25ab977db582e75e8e6e4f790776debae5502541
MD5 693945ff1bf035624af167cbe67cacde
BLAKE2b-256 408deadfbbe4715380e374304e8852b729dcd41b8af66b6db5f727c3737026c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f93bc338bf35998b1445c81ed97e4325f5b1c1b38b961d60b5e936b1113b60db
MD5 dde934328ae48f818b0f5679a67d284c
BLAKE2b-256 e74958f785094d76fd79670561ca46daaa58f701b6b6d9b9c19e8ff5eb7b716d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e26c642dff5213257da0f565c8a69a42c940d2cbc55400bab6f1605ac10446a0
MD5 0af8b99b527e0b6a50fe8b9307485e52
BLAKE2b-256 da269d3199f598beb10cec37d36020ed739b6ade760513ef16fdf51299ecdb04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2866aa3e72f41dc21116c5c7661ed6db3d7ec0099fe100c73b194864f041bc8c
MD5 d8974ef1a174bc726f0df67b8f83f07e
BLAKE2b-256 0a5cdfd99a9cb6ebed6cb07f73f89d8aa3095fac7296d7eb873a13e78d9093e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6128fd217cecf61d555605eeee67d3b166ff4dae4525e76c29415f2d66cfa38e
MD5 0c271c18e769427cd885a367b7ef9efd
BLAKE2b-256 491294dc74d85362f35187d707911df254dd33e28381cf6f5718e7403b15a27d

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