Vector Search¶
Built-in HNSW vector indexing for similarity search, RAG applications, and AI/ML workloads.
Creating Vector Tables¶
Inserting Vectors¶
INSERT INTO documents (id, content, embedding)
VALUES (1, 'Machine learning basics', '[0.1, 0.2, 0.3, ...]');
Vector Search¶
Nearest Neighbor (Euclidean)¶
Cosine Similarity¶
Creating Vector Indexes¶
HNSW Index¶
CREATE INDEX docs_embedding_idx ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 200);
IVF Index (Large Scale)¶
CREATE INDEX docs_embedding_idx ON documents
USING ivf (embedding)
WITH (lists = 100, quantization = 'pq');
Vector Operators¶
| Operator | Description |
|---|---|
<-> |
Euclidean distance |
<=> |
Cosine distance |
<#> |
Negative inner product |
Hybrid Search¶
SELECT content FROM documents
WHERE category = 'tech'
ORDER BY embedding <-> '[0.1, 0.2, ...]'
LIMIT 10;
Tuning Performance¶
SET hnsw.ef_search = 100; -- Higher = more accurate, slower
SET ivf.probes = 20; -- More probes = more accurate
REPL Commands¶
Related¶
- SQL Reference - Vector syntax
- API Reference - Vector API