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.2.tar.gz (652.6 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.2-cp313-cp313-manylinux_2_34_x86_64.whl (902.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.5.2-cp313-cp313-macosx_11_0_arm64.whl (741.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl (835.8 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.5.2-cp312-cp312-manylinux_2_34_x86_64.whl (902.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.5.2-cp312-cp312-macosx_11_0_arm64.whl (741.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl (835.8 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.5.2-cp311-cp311-manylinux_2_34_x86_64.whl (905.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.5.2-cp311-cp311-macosx_11_0_arm64.whl (743.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.5.2-cp311-cp311-macosx_10_12_x86_64.whl (842.1 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.5.2-cp310-cp310-manylinux_2_34_x86_64.whl (905.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.5.2-cp310-cp310-macosx_11_0_arm64.whl (743.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.5.2-cp310-cp310-macosx_10_12_x86_64.whl (842.0 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kannolo-0.5.2.tar.gz
  • Upload date:
  • Size: 652.6 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.2.tar.gz
Algorithm Hash digest
SHA256 d5b78d21f14c52ae740b2463d3a9c26b030bf618549be9a5cf41f5e47bd8c95c
MD5 39cd874340e1bd91f24e4c4710ca7709
BLAKE2b-256 2fc14ffc31355de77b5e894a68c5dcf15447f1654c46dcef8d8b4a4af8e79afb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 946a3f4235adacf17053c7563d8d7f7124985a315cd9f4f307fce11547d12aaa
MD5 2d939abc09cc74e5ee4bef8d7a90ebd0
BLAKE2b-256 007f6b8d64fa0f908797322d6a46540517696afb0327047d536815ce0b9ac6db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7cd53c243e46ab0356f9c52353a7667f1e0ca870317ae1980b064fc8d88f2aa0
MD5 1a0039f5c3f68e44e43922735b99228b
BLAKE2b-256 1764aec4411b55b3ca551a2f95bd1ce3f61dd682657ae6d5fee0526d36d79b4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bf5fc53ac278fc8e23861b45cff353dc5c1ad5865a5dfaf478ab3419bc5d700f
MD5 055e259fa21ea0bad4ec44614cc0e49c
BLAKE2b-256 6ae127b98ed9476221560e4b8b18b3061847a0c8e35b9913e0f12a37c233ae02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 20f425446defe09b1ff1992938e546534ae3a76078cf094f3adee575b68e2c79
MD5 164c4383865b7de94463aec176b5209a
BLAKE2b-256 17670e5a126b1cfd77113ca9ae0c1fb8337dd6fda4ab357b7cbb678f2f0e9214

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c134b321fcd6844ce6bf01aef8cb7d218255bf3abd9390e9a5a94fb47eb32e58
MD5 175d3778e23b12450a54fb390f748d34
BLAKE2b-256 508d6ba8c0566e81c5aca2eddb4ef93627b594f8e80983c53c8ade689c41373b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 467c9343800674467b5008bf3cfcb9b3dab89aee006225c23c30c42ddff21d1e
MD5 421b909353ea1ce5b8da0933e8210663
BLAKE2b-256 d48a9eccb924a144b8fdbee634267a828aaeaff513ca09b9a3aa2965ef7c571e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 126c767b736906f091b2a1cb8a40df03b57269aa5a02c9b9b680b80cc73c5959
MD5 c303b3efd74654a3fc95374ad53f5eb4
BLAKE2b-256 92c0aad071927dc3e0a8fc07602d3cd814f191b73776c4d2f0cce3c004bac16d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 440429ec01163ec4c9c383c6184988226ed55a5cf143b2e6f5abf4cd726d20e9
MD5 c85013b2541a923b11ccf84b17ea4bc3
BLAKE2b-256 38df3dd88d6ae99044fc16cdbc5e155d926cf490049fb62a89416e116b4cf354

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8494fda7ef8ce2a13c963f6e1fd44509a65d12bc4b6a10eb2d2af9d1e7b8c946
MD5 786cb46560ce73921ddd0e8782dd8bb9
BLAKE2b-256 e7bec2ea2d7104cba42a2c929aaae3d9d962256f72433db5c75f22f361731315

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 470f85cc02f53fae863d7a8677958ef7b10276ce5b7cc9fdc12d6c5dfec3965f
MD5 1c948da19ed7d4bcff5e381aa50f2459
BLAKE2b-256 081b9b90f9c402c066cf71650e14044ca28ed151b73b515364dc575c5f16f464

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7df78f75f49577e1b936a0d26adaa2d4feb23ebbe0378d52a8d86fa2b61edc17
MD5 708450ea21990ec07a2b15058eb17ed0
BLAKE2b-256 16d1d2577f0f1248c300bb8b8c8ed18e6f6b39fa5e3b8cf3df367572cc46360f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.2-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d7ed56cf6126c5f4ff7f47cdc6ce5d56ffee00ea5b7bf52eb2e1a82e42b344e7
MD5 e046e289bd889f7ea1ad4f3481bc7e5b
BLAKE2b-256 6324e55b2aa0232a6202aba0f28df0221c20208f149e58d160a8733270a259f5

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