ITZMA is still taking shape, and its API can change between releases. Version 0.2.1: serde_with security fix
Docs / User guide

Vector queries and reranking

Closest first, exact or through an index, with rerank, nprobe and filters.

On this page

Nearest neighbors

A query returns up to top_k hits, closest first, each with its id, distance and attributes.

hits = ns.query([0.9, 0.1, 0, 0], top_k=5, filter=attr("year") >= 2022)
for hit in hits:
    print(hit.id, round(hit.distance, 4), hit.attrs)
let hits = ns.query(&[2.0, 0.1], 2).await?;
assert_eq!(hits[0].id, "east");
assert_eq!(hits[0].attrs, Some(serde_json::json!({ "label": "east" })));
assert!(hits[0].distance < hits[1].distance);

Options

Python takes them as keywords on query; Rust passes QueryOptions to query_with.

OptionDefaultWhat it does
rerank4An index proposes rerank * top_k candidates, which are then rescored against their exact vectors. None proposes every row.
nprobeNone (index picks)How many SQ8 partitions to read, or under HNSW a multiplier on how wide the graph search is.
exactfalseSkip indexes and scan every live document.
filterNoneA predicate the hits must match. See Filtering.
rust
let exact = QueryOptions::default().exact(true);
assert_eq!(ns.query(&[0.0], 1).await?, ns.query_with(&[0.0], 1, &exact).await?);

How does a query run?

Each segment with an index proposes candidates through it; segments without one and the WAL tail are scanned. A candidate that a newer segment or the tail overwrote or deleted is dropped, the survivors are reranked on exact vectors, and the closest top_k across all sources win. The answer never carries an approximate distance.

A query that starts after a write returned sees it, from any handle or process.

Distances

L2 is squared Euclidean, cosine is 1 - cos, dot product is negated, so lower is closer for all three. Distances are comparable only within one query.

Docs
esc

Loading the docs…