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.4.tar.gz (654.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.4-cp313-cp313-manylinux_2_34_x86_64.whl (906.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

kannolo-0.5.4-cp313-cp313-macosx_11_0_arm64.whl (745.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kannolo-0.5.4-cp313-cp313-macosx_10_12_x86_64.whl (838.0 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kannolo-0.5.4-cp312-cp312-manylinux_2_34_x86_64.whl (906.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

kannolo-0.5.4-cp312-cp312-macosx_11_0_arm64.whl (745.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kannolo-0.5.4-cp312-cp312-macosx_10_12_x86_64.whl (838.1 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kannolo-0.5.4-cp311-cp311-manylinux_2_34_x86_64.whl (908.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

kannolo-0.5.4-cp311-cp311-macosx_11_0_arm64.whl (750.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kannolo-0.5.4-cp311-cp311-macosx_10_12_x86_64.whl (839.0 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kannolo-0.5.4-cp310-cp310-manylinux_2_34_x86_64.whl (908.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

kannolo-0.5.4-cp310-cp310-macosx_11_0_arm64.whl (750.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kannolo-0.5.4-cp310-cp310-macosx_10_12_x86_64.whl (839.3 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kannolo-0.5.4.tar.gz
  • Upload date:
  • Size: 654.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.4.tar.gz
Algorithm Hash digest
SHA256 9944accf80abdcb315a3b1e841b8f8866b0325ac2585c6216fb12060fad5efcf
MD5 8f81d776bf729b2d550dd6818a9237ee
BLAKE2b-256 af7c28b6c22d2812e9d4b1d5d81bff0f6f494d911f87a1b86d09dfe7826eb54f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8db13424d843cb6706dcbe53228df9f43dba1faf8bd44e99cb0ae85661513c1d
MD5 25803f56514339e1116c151108d9378e
BLAKE2b-256 5363904a87838658c13ea576296c25dc7082e124d5e9abd85a2ea1a70bd719f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db3e9428293b15488f425c2f848575404f8e686f51e6e23e0e0c870281151c8d
MD5 301577deb6d6015039ee4c170971a99e
BLAKE2b-256 200f68f79e3318f2a7df3ad371e0c603014fa5d72936c073c72cc06f5784ebfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5a263512ab02cca2ee9144ddf154472f065aac28e144801fbdeb4f5ffa7dd57c
MD5 47bd837df8d8777b4761e62f1bb80a2b
BLAKE2b-256 9e249d62d6ad8283a04d9d7bb19c9df88f2f774a522a8a45dbcda0199779608c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d342fbec43c05b46f3c9cac6b2eb2e23ae0b804beba28d894a0ad56f4df4c06a
MD5 a949259f5be665fe21f56d3be3a86987
BLAKE2b-256 76ca5797457705824a6089d70eb28346d401e0f0425d5969afb02658ae79b96f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 21b0fc8a7e4f514ff7e0b5857e57edd6a32afe85975f6f52d9fdc21403382ba5
MD5 6d701b2420ab5cf0cbc0ba6faa9d39b4
BLAKE2b-256 b9a1ce770a6971c605fa75a0a8075d6435c4acc4ce9e7f8db305698512e7f45e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f514efe6c569e9a0d587b37c55f5a15ca1a3f4a9a04b9b6c0dc5523af0ed8fb2
MD5 1520953c8eaf116e6fcdc3efa9c680e5
BLAKE2b-256 005c9e386843984cb580ed359b19023e0990b3ba1efcfcb5618085bff1120097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3ea0c9055c42b3073e103b3f6407adc04b339b84fcb8e9cf6c70c5ef3767dedb
MD5 37d0c2c2b60c4e07afff58e23cc686e6
BLAKE2b-256 4b165d0bb322ff3ec8216c41acaf24364ba99debbcb6e03ca5e55412e5531b50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5decd9f2f28241744ca54529689523ffa9fa70051baae446f4eab8f3f99c60f
MD5 fc6d7f94692ebd43090038ce6bbe06f2
BLAKE2b-256 5fc5fd6303c62677762c6f8d2c26abc2e87d37f6f7342c921ffe5115fa00a39f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9110e8246dce5cc6f066b2fa898bb4f3eaeb9b32319f5d9e4a75bacda21ee39b
MD5 19ee2bbd20b5b052629f3d0e4bee7549
BLAKE2b-256 3d6d0866922636827bfa323122a12b9dfe92c0d81a29b91abfc3ac10e552415c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4bdc07aa558516454dce097a84ab3569a6243cd45a7a68d48613e01e561056ca
MD5 d72ff6cc47480b356e3b01bd7d8ea8f9
BLAKE2b-256 3cb1a296aa3cbbda6a4bd3fe02e6265ea5ba6b030288fba5ce2b0ed033df8e77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c3e546f16d74357b3713b49c09149a641207c9155ce66a256eec9c93db0f8042
MD5 63342ec8a86b4f47657c1b452edf4ee3
BLAKE2b-256 59a298ffe97e15fcfe9abc42372efb432f63200aeb6cfa0e069a6c9eb54081a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kannolo-0.5.4-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 985187351d9ac1a2ddfa13e363db83cce7c36528fe4cf6f4b9899f07d49285e1
MD5 87db5f16563a1ad0af73c62097a59a22
BLAKE2b-256 ad21e866ae9330f1f42b7e75c1de9ccdd605a7dbb6db01c447766dfb261905bf

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