Dense and sparse retrieval in one index. Native multivector / ColBERT reranking. Embeddable as a Rust library or served over HTTP. Beats hnswlib on the recall–latency Pareto frontier up to 96% recall.
# Rust
cargo add annex
# Python
pip install ANNexDB v0.3.0 · Apache-2.0 / MIT · one maintainer, actively developed
● returned ○ exact neighbors · 5 of 6 found. The one miss is the dashed ring.
ANNex is a Rust-native embedded library with hybrid dense-sparse retrieval, multivector / late-interaction reranking, and WAL-backed persistence. Compare with the most commonly evaluated alternatives.
| Feature | ANNex | Qdrant | FAISS | hnswlib |
|---|---|---|---|---|
| Dense vector search | ✓ | ✓ | ✓ | ✓ |
| Sparse / BM25 | ✓ | ✓ | ✗ | ✗ |
| Hybrid RRF fusion | ✓ | ✓ | ✗ | ✗ |
| Multivector / ColBERT | ✓ | ✓ | ✗ | ✗ |
| Payload filters | ✓ | ✓ | ✗ | ✗ |
| Embedded (no server) | ✓ | ✗ | ✓ | ✓ |
| HTTP server | ✓ | ✓ | ✗ | ✗ |
| Rust-native library | ✓ | ✗ | ✗ | ✗ |
| Python bindings | ✓ | ✓ | ✓ | ✓ |
| Snapshots + WAL | ✓ | ✓ | ✗ | ✗ |
ANNex leads hnswlib across the full recall frontier from 83% to 96% recall on NYT256. The gap widens at higher recall targets — where the engineering cost of approaching exactness usually hurts most.
Bring your own embeddings: ANNex stores and searches the vectors you give it. These three steps run as written against the published packages.
Build an index from a NumPy array, search it, and save it. No Rust needed.
python -m pip install ANNexDB numpy import annexdb
import numpy as np
# One row per item: your embeddings, float32.
vectors = np.array(
[
[0.9, 0.1, 0.0, 0.0],
[0.8, 0.2, 0.1, 0.0],
[0.0, 0.1, 0.9, 0.2],
[0.1, 0.0, 0.8, 0.3],
],
dtype=np.float32,
)
index = annexdb.Index.build(vectors, metric="cosine") # row i gets id i
query = np.array([0.85, 0.15, 0.05, 0.0], dtype=np.float32)
ids, scores = index.search(query, k=3)
for i, s in zip(ids, scores):
print(f"id={i} score={s:.4f}")
index.save("segment.bin") # a snapshot Rust can load too id=0 score=0.0037
id=1 score=0.0044
id=3 score=0.8319 For cosine, the score is a distance (1 − cosine similarity), so lower is closer. dot is a similarity (higher is closer) and euclidean is squared distance (lower is closer).
The Python package does dense vector search: build, search, save and load. For hybrid search, payload filters and multivector search, use the Rust library (step 2) or the HTTP server (step 3).
Build a small cosine index, search it, filter on a payload field, and save a snapshot.
[dependencies]
annex = "0.3.0" use std::collections::HashMap;
use annex::{DistanceMetric, Filter, Payload, PayloadValue, Segment};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// A tiny 4-dimensional cosine index: M=16, ef=64 (the build width, also the default search width), level cap 16.
let mut seg = Segment::with_config(DistanceMetric::Cosine, 16, 64, 16, 4);
// (id, vector, topic): you bring the embeddings, ANNex stores and searches them.
let docs = [
(1, [0.9, 0.1, 0.0, 0.0], "pets"),
(2, [0.8, 0.2, 0.1, 0.0], "pets"),
(3, [0.0, 0.1, 0.9, 0.2], "cars"),
(4, [0.1, 0.0, 0.8, 0.3], "cars"),
];
for (id, vector, topic) in docs {
let mut payload = Payload(HashMap::new());
payload.set("topic", PayloadValue::Str(topic.into()));
seg.insert_with_id(id, vector.to_vec(), Some(payload))?;
}
// Nearest neighbours of a query that looks like the "pets" documents.
let query = vec![0.85, 0.15, 0.05, 0.0];
for hit in seg.search(&query, 3)? {
println!("id={} score={:.4}", hit.id, hit.raw_score);
}
// The same search, restricted by a payload filter.
let cars = Filter::Match { key: "topic".into(), value: PayloadValue::Str("cars".into()) };
println!("-- topic = cars");
for hit in seg.search_with_filter(&query, 2, Some(&cars))? {
println!("id={} score={:.4}", hit.id, hit.raw_score);
}
// Persist it. The Python bindings load this file.
seg.save_to_path("segment.bin")?;
println!("saved segment.bin");
Ok(())
} id=1 score=0.0037
id=2 score=0.0044
id=4 score=0.8319
-- topic = cars
id=4 score=0.8319
id=3 score=0.9252
saved segment.bin For cosine, the score is a distance (1 − cosine similarity), so lower is closer. Ids 1 and 2 are the near neighbours of this query.
Cargo.toml: annex = "0.3.0" also accepts later 0.3.x releases. The snapshot is the same format the Python package writes: Segment::load_from_path("segment.bin") opens the file from step 1.
Combine keyword (BM25) and vector search with a metadata filter in one request. Start the server, add three documents, query.
# Install and start the HTTP server (compiles from source, so the first install takes a few minutes)
cargo install annex-multivector
annex-multivector --dimension 2 --centroids 2 --path ./data --listen 127.0.0.1:8080 curl localhost:8080/v1/vectors/upsert -H 'content-type: application/json' -d '{"documents":[
{"id":"runbook-e123","text":"E123 recovery procedure for the payments service",
"metadata":{"team":"support"},"representations":{"semantic":{"kind":"dense","vector":[1,0]}}},
{"id":"backup-restore","text":"How to restore a database from a backup",
"metadata":{"team":"support"},"representations":{"semantic":{"kind":"dense","vector":[0.9,0.1]}}},
{"id":"holiday-policy","text":"Office holiday schedule and leave policy",
"metadata":{"team":"hr"},"representations":{"semantic":{"kind":"dense","vector":[0,1]}}}
]}' curl localhost:8080/v1/retrieve -H 'content-type: application/json' -d '{
"prefetch": [
{"kind":"bm25","text":"E123 recovery"},
{"kind":"dense","field":"semantic","vector":[0.95,0.05]}
],
"filter": {"op":"eq","field":"team","value":"support"},
"limit": 3
}' {"matches": [
{"id": "runbook-e123", "score": 0.18181819, "sources": [0, 1]},
{"id": "backup-restore", "score": 0.083333336, "sources": [1]}
]} runbook-e123 matches both the exact term "E123" and the vector, so both channels return it and it ranks first. backup-restore is found by the vector alone. holiday-policy is excluded by the filter.
sources lists which prefetch entries found each document (0 = BM25, 1 = dense). Scores are fused with reciprocal rank fusion (RRF). The full response also includes each document's text, metadata and a timing trace.
More: API docs on docs.rs · HTTP API reference · benchmarks · changelog
These are real constraints, not caveats. If any of them are blocking for your use case, ANNex is probably not the right choice yet.