hannoy 🗼
hannoy is a key-value backed HNSW implementation based on arroy.
Motivation
Many popular HNSW libraries are built in memory, meaning you need enough RAM to store all the vectors you're indexing. Instead, hannoy uses LMDB — a memory-mapped KV store — as a storage backend. This is more well-suited for machines running multiple programs, or cases where the dataset you're indexing won't fit in memory. LMDB also supports non-blocking concurrent reads by design, meaning its safe to query the index in multi-threaded environments.
Features
- Supported metrics: euclidean, cosine, manhattan, hamming, as well as quantized counterparts.
- Python bindings with maturin and pyo3
- Multithreaded builds using rayon
- Disk-backed storage to enable indexing datasets that won't fit in RAM using LMDB
- Compressed bitmaps to store graph edges with minimal overhead, adding ~200 bytes per vector
- Dynamic document insertions and deletions without full re-indexing
Missing Features
- GPU-accelerated indexing
Usage
Rust 🦀
use hannoy::{distances::Cosine, Database, Reader, Result, Writer};
use heed::EnvOpenOptions;
use rand::{rngs::StdRng, SeedableRng};
fn main() -> Result<()> {
let env = unsafe {
EnvOpenOptions::new()
.map_size(1024 * 1024 * 1024) // 1GiB
.open("./")
}
.unwrap();
let mut wtxn = env.write_txn()?;
let db: Database<Cosine> = env.create_database(&mut wtxn, None)?;
let writer: Writer<Cosine> = Writer::new(db, 0, 3);
// build
writer.add_item(&mut wtxn, 0, &[1.0, 0.0, 0.0])?;
writer.add_item(&mut wtxn, 0, &[0.0, 1.0, 0.0])?;
let mut rng = StdRng::seed_from_u64(42);
let mut builder = writer.builder(&mut rng);
builder.ef_construction(100).build::<16,32>(&mut wtxn)?;
wtxn.commit()?;
// search
let rtxn = env.read_txn()?;
let reader = Reader::<Cosine>::open(&rtxn, 0, db)?;
let query = vec![0.0, 1.0, 0.0];
let nns = reader.nns(1).ef_search(10).by_vector(&rtxn, &query)?.into_nns();
dbg!("{:?}", &nns);
Ok(())
}
Python 🐍
import hannoy
from hannoy import Metric
import tempfile
tmp_dir = tempfile.gettempdir()
db = hannoy.Database(tmp_dir, Metric.COSINE)
with db.writer(3, m=4, ef=10) as writer:
writer.add_item(0, [1.0, 0.0, 0.0])
writer.add_item(1, [0.0, 1.0, 0.0])
reader = db.reader()
nns = reader.by_vec([0.0, 1.0, 0.0], n=2)
(closest, dist) = nns[0]
Alternatively, you can add many items at once from a 2d numpy array of dtype float 32:
import numpy as np
with db.writer(3, m=4, ef=10) as writer:
writer.add_items([0, 1], np.array([[3.0, 4.0, 5.0], [6.0, 7.0, 8.0]], dtype=np.float32))
Tips and tricks
Reducing cold start latencies
Search in an hnsw always traverses from the top to bottom layers of the graph, so we know a priori some vectors will be needed. We can hint to the kernel that these vectors (and their neighbours) should be loaded into RAM using madvise to speed up search.
Doing so can reduce cold-start latencies by several milliseconds, and is configured through the HANNOY_READER_PREFETCH_MEMORY environment variable.
E.g. prefetching 10MiB of vectors into RAM.
export HANNOY_READER_PREFETCH_MEMORY=10485760
Metadata
Release files for hannoy 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hannoy-0.1.3.tar.gz | 1.6 MB | Without provenance | Details |
Built distributions (wheels)
Total release size: 17.6 MB
Release files / hannoy-0.1.3.tar.gz
| Download URL | hannoy-0.1.3.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e2742be21f0781dd27f85323c1a59f55df99b7fa38ffa3439fbf60a0faa82e6
|
|
BLAKE2b-256 checksum How to use checksums |
5126ea49e23cc2f35e0940bdd42199df2fc556f7dac1fd809846c6e950769942
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hannoy-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ac83a89d61cc6a780e9525e039cce2a321715e6dceb48e70c0eff6dc9a3fbea2
|
|
BLAKE2b-256 checksum How to use checksums |
ce9e17d9ac88e2719633c503a031a4ec49cefba63e01fbda4162527cf283fabb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | hannoy-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa6e05a8ad17ad89f45aa67f8dc2c759eeb28a28beda0699335e4c1c081be831
|
|
BLAKE2b-256 checksum How to use checksums |
d13594e2e69a6a9b1bda7893a45becec23f8c4f1eb4472a6476cae8a1a115c9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | hannoy-0.1.3-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0df862bce70f0caaa9df1446465a554e239d28f87b11657bb0b108b538c78eb8
|
|
BLAKE2b-256 checksum How to use checksums |
e7221024eff019cd47b8df7d006669fddf1ba5128fa29d7d92e5a048c86269b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hannoy-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
09fd96c9c4d6f5db3857fd50ac7d8b7e87bef254ffa067f730342da4f05480c1
|
|
BLAKE2b-256 checksum How to use checksums |
ef9ad39518b24cd8d69caf57ccc479b96ef5600c3bb1e182de55fe2b7c069008
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | hannoy-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
478fe968d162bacfd39b117618f93cd5526aeec207a19d9affb64099e330ce2e
|
|
BLAKE2b-256 checksum How to use checksums |
fa3f3c11ac7351120e8085351b7e15ec0b39ba6c23ba63706562bb62c3c93dcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | hannoy-0.1.3-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
62dade88a318a75abf01789ee2f09cb50be9d6d37409aca36aac20e52195aae7
|
|
BLAKE2b-256 checksum How to use checksums |
da3c6221fb2d1b032164d0868dd76940f87783aefe5f329ba10df22fbd1271d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hannoy-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
43fec4c1c1baa7363fbdf919a00cd85121e6a1fc235ecad32c719e29fb5f77d7
|
|
BLAKE2b-256 checksum How to use checksums |
7f6628076976db97a08a5e3b47fe04c6074680389a90ecd89405d78bb20593c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | hannoy-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
6ad568d00121acdbd7e9edf3ff3602ff3e9588e183131c5f3e1c35c12a5face8
|
|
BLAKE2b-256 checksum How to use checksums |
9858fd4ceeffe6c063586deb48d4f3119fc54275264a05e2a0d47cd6ba3909c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | hannoy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
89bb64c1e820e0a3e23c1cfda8a38f2cb62c6edea92e9b348ef930d04ab87b4e
|
|
BLAKE2b-256 checksum How to use checksums |
56ea545d5d33f099e704b7720effd067ddf76114661622a694f6a7f38f29f09f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | hannoy-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
31743951220b0daaa986111d7bcb2c6e0149fc90d72cdf33d51b0ae1068161f8
|
|
BLAKE2b-256 checksum How to use checksums |
73c1cdf71fd73acd0abe6f0add8d8840fad8908707d9a453dcd306d272114657
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | hannoy-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
95a60df06124578e80dfc33e6850879d1916e421bf2cdd108982ec575dcef338
|
|
BLAKE2b-256 checksum How to use checksums |
d325f07d96bd631a40b2dad2a5cd2279fa0e885566622ec06ded73687ab01d1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / hannoy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | hannoy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f0ffddf4c15224e73d1c4416f2e9325e71be09c47f3267684e83dfea23a593b3
|
|
BLAKE2b-256 checksum How to use checksums |
75e84a02a836cee8262c6fd7640294bf93794f6472290d6391b4d8871897e99e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Security for hannoy 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.