Modular and Efficient Approximate Nearest Neighbors Search with Vectorium and kANNolo
Silvio Martinico, Franco Maria Nardini, Cosimo Rulli, Rossano Venturini
cs.IR, cs.DB
2026-11-03
Two Rust libraries split ANN search into data and index layers spanning dense, sparse, multi-vector; two-stage HNSW reaches 2.5-3.3x hnswlib at 99% accuracy, half the size.
Retrieval-Augmented Generation, semantic search and recommendation all bottom out in one operation: embed the query, find the k closest vectors among millions. Exact search is impractical at that scale, so Approximate Nearest Neighbors (ANN) trades a little recall for orders of magnitude of throughput. An efficient ANN system combines choices that are largely independent: an index structure (a proximity graph or an inverted file), a similarity function, a quantization scheme, and one of three vector representations: dense, learned sparse, or multi-vector. Together they span a large cross-product.
Existing libraries each carve out a small slice. Faiss, the most widely used, exposes one class per combination, each with its own construction and search code path. hnswlib implements a single algorithm over uncompressed dense vectors. PARLAYANN and ANNLib generalize the graph algorithm but ship almost no quantizers; GLASS generalizes the quantization side but hard-codes its graph layout. The more practical gap: no library covers all three representations, so an optimization written for dense vectors never reaches sparse. Anyone comparing representations, or building a sparse-first pipeline with a multi-vector rerank, ends up gluing several libraries together.
Two Rust libraries split the design space into two layers.
Vectorium is the data layer, with four independent abstractions: a vector view (how a vector sits in memory), a Distance (a score plus its ordering), a VectorEncoder paired with a QueryEvaluator (compression and scoring in one contract), and a Dataset (pure storage with no distance logic). Any meaningful combination is obtained by naming a type alias, with no new code. It ships 11 encoders, from lossless f32 down to 1-bit RaBitQ codes and sub-bit PQ codes.
kANNolo is the index layer: HNSW and IVF indexes generic over every representation, encoder and metric, plus RerankIndex, a two-stage index pairing any first-stage index with any rescoring dataset. A sparse HNSW first stage feeding a ColBERT-style MaxSim rerank is literally one type.
The engineering decision that makes this work is compile-time monomorphization: every combination becomes a specialized copy, distance kernels inline into the search loop, and no indirect call appears on the hot path. The paper measures the alternative: the same kernel called through a trait object costs 1.07-1.52x per distance. The kernels themselves are a few lines of plain Rust relying on fast-math floating point so the compiler vectorizes them; algebraic kernels run 13x faster than strict IEEE at 128 dimensions and 18-20x at higher dimensions, and the same source vectorizes unchanged on AVX2 and on a Raspberry Pi 5's NEON. Explicit SIMD survives only in packed encodings such as RaBitQ popcounts and DotPacking8.
Components are validated against their reference implementations first, then the full system is compared against six dense and five sparse systems on seven public collections.
| Comparison | Setting | Result |
| PQ vs Faiss IndexPQ | exhaustive scan | accuracy within 0.43 points; 1.20-1.62x faster while codes fit in L3, 1.17x slower at 1.7 GB |
| RaBitQ vs authors' implementation | exhaustive scan | accuracy within 0.80 points, 1.44-2.37x faster, 8-16 bytes/vector smaller |
| Two-stage HNSW vs hnswlib | 99% accuracy | 2.5-3.3x throughput, half the index size |
| Two-stage vs PyANN | sparse graph index | 5.2-48.4x faster, a third of the memory |
| Dense end-to-end | 12 collection-accuracy pairs | best memory-throughput trade-off in 9 |
On out-of-distribution queries, the two-stage HNSW and LORANN are the only two systems to still reach 99% accuracy. On sparse data the Vectorium-based systems lead on all three collections: Seismic and SeismicWave are the fastest at every target, kANNolo's indexes the most compact. Two more numbers worth keeping: f16 is the default storage precision at a cost of at most 0.08 accuracy points, lifting Sift1M exhaustive throughput from 819 to 1401 QPS; and quantizer choice tilts toward RaBitQ as dimension grows, winning on both accuracy and throughput at 1024-dim SnowFlake with no training phase, making builds 62-1062x faster than PQ.
For anyone building retrieval, the two libraries (MIT-licensed, with Python bindings exposing all three representations through one interface) remove the multi-library glue. The learned-sparse engine Seismic already runs on Vectorium, which shows the data layer stands on its own.
For library authors, the algorithms here are prior work: HNSW, IVF, PQ, RaBitQ. The contribution is the architecture and its verification: full genericity with compile-time specialization carries no run-time penalty, and auto-vectorized generic kernels hold up against hand-written SIMD in almost every measured regime. That is a result about how to build performance-critical libraries, and it generalizes beyond ANN.
The paper states the price up front: compilation is slower and binaries larger. The Python bindings instantiate every combination they expose; a clean release build takes 113 seconds, with the beam-search loop alone compiled 164 times, and the number of binding classes grows with the product of layouts, encoders and metrics. A combination outside the exposed set needs a new binding class and a rebuild.
"Three representations" carries an asterisk for multi-vector: MaxSim scoring is expensive enough that kANNolo's indexes do not suit it directly, so multi-vector data enters only as a reranking stage, and actual multi-vector indexing is left to a separate engine, TACHIOM.
The Faiss comparison is not a clean sweep: PQ training is 1.13-1.57x slower, encoding is 2.8-4.1x slower at dsub of 4 or 8, and once the code array saturates memory bandwidth (1.7 GB), Faiss scans 1.17x faster. Faster on small data, slower on large; check against your own scale. All measurements run on a single dual-socket Xeon with AVX-512 and 503 GiB of RAM, and ANN performance is bound to the memory hierarchy, so numbers will move on other hardware.