Vector query (kNN)
/ Vector, / Knn, / SemanticVector query (kNN) #
Finds the k nearest neighbors of a query vector — similarity search
over dense_vector / sparse_vector fields. The query vector can be
supplied directly, or as natural-language text that the serving layer
embeds with the field’s configured model (schema-driven semantic
search).
How it works #
Execution depends on where the documents live:
- Realtime (not yet flushed) — an exact brute-force scan over the
mutable store: every vector is scored, a size-
kmin-heap keeps the best, and a filter (see below) is tested before any distance is computed. - Flushed segments — the field’s
index_typedecides:flatscans the stored f32 vectors (exact,O(N·dims)); the graph types (hnsw_flat,turbo_quant_hnsw,bbq_hnsw) traverse the persisted HNSW graph with distances computed on the flat vectors — scores stay exact and only anef-bounded neighborhood is evaluated; the quantized scans (turbo_quant,bbq_flat) score compact codes for ak × oversamplingcandidate pool and rescore it with full precision (approximate). The per-type breakdown is in Index types.
Scores follow the field’s similarity (overridable per query, but it
must match the schema): cosine is the cosine similarity in
[-1.0, 1.0]; dot_product the raw dot product; l2 scores as the
negated squared Euclidean distance — 0 means identical vectors.
Higher is always more similar, so one top-k heap serves all three.