cockroachdb/cockroach
Vector index
pkg/sql/vecindex/ adds an approximate-nearest-neighbor (ANN) index for the VECTOR SQL type, integrated with the optimizer and execution engines.
Surface
CREATE TABLE docs (id UUID PRIMARY KEY, embedding VECTOR(1536));
CREATE VECTOR INDEX docs_emb_idx ON docs (embedding);
SELECT id FROM docs ORDER BY embedding <-> '[…]'::VECTOR(1536) LIMIT 10;The optimizer recognizes the <->/<#>/<=> operators and rewrites the query to use the vector index when one is available.
Implementation
pkg/util/vector/— the data type (single-precision floats; cosine, L2, dot product distance).pkg/sql/vecindex/— the index. Internally a multi-level k-means tree that partitions the vector space; each partition becomes its own KV row with a small SST-friendly layout.pkg/sql/vector_search.go— query-time scanner that walks the tree.pkg/sql/vecindex/cspann/— control-plane code for re-balancing partitions.pkg/cmd/vecbench/— benchmark harness (recall and latency sweeps).
The index is online: writes to the base table are journaled and asynchronously absorbed into the partitioning tree. Reads tolerate slight stale-ness in exchange for low write amplification.
Configuration
A few cluster settings under sql.vector_index.* control the partitioning fan-out, the journal size, and the recall target.
Related pages
- SQL — optimizer and execution integration.
- features/workload —
vecindexworkload exercises the index.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.