index
Vector
pgvector extension supports approximate nearest-neighbor HNSW search; recall and latency trade off. Extension version is not pinned or tested. Target: PostgreSQL 17 + pgvector. Use a disposable database; plan selection is not guaranteed.
Formal Syntax & Structure
sql syntaxsql
CREATE INDEX ix ON embeddings USING hnsw (v vector_l2_ops)Working Example
Example Snippetsql
CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE embeddings(id int, v vector(3)); INSERT INTO embeddings VALUES (1,'[1,0,0]'),(2,'[0,1,0]');CREATE INDEX ix ON embeddings USING hnsw (v vector_l2_ops);SELECT id FROM embeddings ORDER BY v <-> '[1,0,0]' LIMIT 1;