Vector search
Wiki / Indexes and constraints
On this page
Vector (ANN) index
Store embedding vectors (list-of-number properties) and query for the
k nearest neighbours. Small indexes use exact brute-force k-NN; large ones
(at/above a threshold) use an approximate HNSW graph for sub-linear search,
with the returned candidates re-scored exactly — returned candidates are ordered by their exact scores. The approximate candidate
set may miss a true nearest neighbour; results are not guaranteed equal to a full
exact search. The HNSW graph is rebuilt on reopen (only the index
declaration is persisted), and is deterministic.
Declare
CREATE VECTOR INDEX embIdx FOR (n:Doc) ON (n.embedding)
OPTIONS { indexConfig: { `vector.dimensions`: 3, `vector.similarity_function`: 'cosine' } };
SHOW VECTOR INDEXES;
vector.dimensions— the expected embedding length; a wrong-length vector is silently skipped. Omit (or0) to accept any length.vector.similarity_function—'cosine'(default) or'euclidean'.- Backtick the dotted config keys (the lexer accepts backtick-quoted identifiers).
Query
Store vectors with the declared dimension before querying. An empty index returns no neighbours. For a standalone example:
CREATE (:Doc {title:'seed', embedding:[1.0,0.0,0.0]});
CREATE (:Doc {title:'near', embedding:[0.9,0.1,0.0]});
MATCH (d:Doc {title: 'seed'})
CALL db.index.vector.queryNodes('embIdx', 5, d.embedding)
YIELD node, score
RETURN node.title, score ORDER BY score DESC;
Cosine scores lie in [0, 1]; Euclidean scores lie in (0, 1] (higher = nearer). Maintained on every write and
rebuilt on restore (declaration-only persistence).
Removing the index
After querying, DROP VECTOR INDEX embIdx removes the index; stored vectors remain.
Related articles
EXPLAIN and PROFILE · Resident and hybrid storage · Schema and maintenance procedures