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.6.1.tar.gz (656.1 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.6.1-cp313-cp313-manylinux_2_34_x86_64.whl (974.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.6.1-cp313-cp313-macosx_11_0_arm64.whl (762.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.6.1-cp313-cp313-macosx_10_12_x86_64.whl (897.7 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl (974.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.6.1-cp312-cp312-macosx_11_0_arm64.whl (762.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.6.1-cp312-cp312-macosx_10_12_x86_64.whl (897.7 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl (973.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (767.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.6.1-cp311-cp311-macosx_10_12_x86_64.whl (904.5 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.6.1-cp310-cp310-manylinux_2_34_x86_64.whl (974.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (767.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.6.1-cp310-cp310-macosx_10_12_x86_64.whl (903.3 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for kannolo-0.6.1.tar.gz
Algorithm Hash digest
SHA256 5ef71da30a0687f364c13444ce20fb91f4c4754f80aac40db263ea13362953d2
MD5 cd88d834bbb8191d386bbb281833de4f
BLAKE2b-256 32f1e4aca9828746cef730b85a8721d690d0f2d38dde35a61615159f2b0dfa07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2d54c196f943569c6c84503d559137424d1b41b6645ea049eab582acd95e63cc
MD5 845a547a65c56ca64c55d782a677c308
BLAKE2b-256 c6e280b1fd193caa3f28c90f1f15b1ba2e811a07a7dfa194c6e2cffdd2c8a561

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8fb9f9e0df8de2515fc5a3b9b5a8f38fa8e5ca8342e36cf49092bc12fbe3d4d0
MD5 7fe923b6a8006769bc5015181d716c59
BLAKE2b-256 48b4be38025ef330bc241d3b96cfef8b355f801709f347959306c456cd61923a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a0aa3a91971f50970d47b60a6ef8a1dd5598da4c5920b61c5f6b0a73b3562712
MD5 fd0a254474079387fe3e69ed84c49330
BLAKE2b-256 43ecc4892fc6cde214a470dd3feea6b3ae8ff036ad98366600a3b3c1e959471f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7d708b2a9238063b5ebaa3a6e59650a1c3e6b38fe7b8d6ca686ed5b47032e24d
MD5 e66cb8d084822467d69b7fee36449d3e
BLAKE2b-256 0f3787f8679ae22ac23f62c6a2938de03fa99db0ad02be3a9d3bbe230c558cf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f63827e512d3ab9b06e53ce5cfbc019f6f546caca10a4a822d0c5ca3e3c5ad23
MD5 b78adcb342418a53ab943762d4ad9ab3
BLAKE2b-256 89da9a518d004d740dfd22d6ab7466362644ec8e63c433d4fe90def302134502

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c58fbd63b8eda4c55f61dfbbed618fc601c4a5dea1abcccee16e5b35cd33563d
MD5 7a51111e6684dc7728d07d3c6497a994
BLAKE2b-256 ecb1554d515845d149cd1d095cc94e5573c148b28d31ba6adde6458ba0999653

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9a4c2962d0eabd13271c0d8463af2c366ed50983be36cfc704c69716762aa246
MD5 cd6842d6ca1cd05ff1fbded9a3970756
BLAKE2b-256 e0b7898adc6e2029089d53d7d7a27f99b4175f4d4f2a050e27642ab33856cbe0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2202460ed93e236d9f02f7ea946a48104d83e5b259789c11d49e49a3f7d3ac09
MD5 22d74a75e8f29a9f8ae998eadc3a5cc6
BLAKE2b-256 f987fe4c9ad8b52b377e5563d4c4c01c1464616052c68a675964685060276e2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fdfb9c149f0ebaff6ff5112a770c33ec749178ebcee3b56d67945ca1a414138a
MD5 59bc1659b36185375026a5ccc2a26d52
BLAKE2b-256 442899c8290235e6f88a390c0ea76803cc47ed79ee02727dd0392dc7132fdfdf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c297dc54e5656b8e35d5ca56d70922bd8f59dce31a178c3807331af27f3812b8
MD5 a40a4bbdb60665aa550422bc9536f12c
BLAKE2b-256 f736f508c2a568f643c9c5726f84cacde518946af1867232ec4c2d1977823b2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2a34b8fd1808b012ae5b83944dba3883132816fe50bc1dfe67416b4688bc732
MD5 1f9df7533a73a22a546205a3bc28bdd5
BLAKE2b-256 8d0c0d8b5cf02c894bb5232284501678b3e24ed74b5b41936d7d99f7fa894048

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.6.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 104aad0d921c08cb98b89389ac393bc53673b14d7a48d3d5d09be634e7ab7eeb
MD5 46cfefaf1827ee0770c8f67d865a33e4
BLAKE2b-256 fcc1e8393e44354ff44e72893f274e43a89de05af9cfa9c51ead89e0c309b567

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