Vector search
Store embeddings in vector(N) columns, build per-part HNSW indexes, and run ANN search that rewrites to the VectorTopK operator.
NYXDB treats embeddings as first-class data: a vector(N) column stores them
next to the source rows, an HNSW index makes nearest-neighbor search fast, and an
ANN query is ordinary SQL.
The vector(N) type
CREATE TABLE docs (
id UInt64,
embedding vector(768),
PRIMARY KEY (id)
);vector(N) is a fixed-dimension dense numeric vector — N is 1–65535, element
type float32 (default) or float64. See
data types.
HNSW indexes
Declare an HNSW index on a vector column. A bare INDEX … TYPE hnsw defaults to
the cosine metric. The index is built per part at flush (vendored
usearch) and rebuilt on compaction, like every other
secondary index.
-- inline on a standalone table
INDEX ix emb TYPE hnswOn attribute tables, declare INDEX hnsw directly on the attribute; the index is
built on the projection:
CREATE TABLE emb_t (
id UInt64,
ATTRIBUTE (emb vector(8) INDEX hnsw)
);A bare attribute INDEX hnsw uses the cosine metric. Declaring INDEX hnsw on
a non-float-vector attribute is a hard bind error — the column must be a
vector(N).
ANN search → VectorTopK
An ORDER BY <distance>(col, $q) LIMIT k query rewrites to the VectorTopK
operator over the HNSW index (the AnnRewriteRule). The query vector is a
'[...]' literal:
SELECT id, cosine_distance(emb, '[1,0,0,0,0,0,0,0]')
FROM emb_t
ORDER BY cosine_distance(emb, '[1,0,0,0,0,0,0,0]')
LIMIT 3;EXPLAIN shows the rewrite:
EXPLAIN SELECT id, cosine_distance(emb, '[1,0,0,0,0,0,0,0]')
FROM emb_t
ORDER BY cosine_distance(emb, '[1,0,0,0,0,0,0,0]')
LIMIT 3;
-- plan contains: VectorTopK column: emb metric: cosineFor a default-latest read over an attribute table, the latest-projection rewrite runs first, then the ANN rewrite fires over the projection's HNSW index — so a KNN over current per-entity state is a VectorTopK, not a full scan.
Distance functions
cosine_distance, cosine_similarity, l2_distance, inner_product,
dot_product, negative_inner_product. See
Functions → vector / distance.
TODO-verify: end-to-end ANN query latency figures. The vector(N) raw-ABI kernel path saw a ~14–16× speedup (#131 / PR #370); that is a kernel measurement, not an end-to-end ANN latency. HNSW build/query cost models are on the vector-search roadmap (ADR-064).