Skip to content

Other Vector Indexes

This page covers syntax and main options for vector indexes other than Vamana.

HNSW

HNSW is a graph-based ANN index. This example uses vector_l2_ops for L2 distance.

CREATE INDEX items_embedding_hnsw_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.hnsw]
    m = 12
    ef_construction = 300
  $$);
Option Default Notes
indexing.hnsw.m 12 Maximum number of graph connections per node. Higher values may increase memory use and build time.
indexing.hnsw.ef_construction 300 Search width during index construction. Higher values increase build time and may improve graph quality.

IVF

IVF partitions vectors into clusters and scans selected clusters at query time. nlist is a build-time option, and vectoron.ivf_nprobe controls how many clusters are scanned during search.

CREATE INDEX items_embedding_ivf_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.ivf]
    nlist = 1000
  $$);
Option Default Notes
indexing.ivf.nlist 1000 Number of clusters built by the index. Higher values may reduce candidates per cluster and increase build time and index metadata cost.

Flat

Flat is an exact baseline for small datasets and ANN validation. CPU cost grows with table size.

CREATE INDEX items_embedding_flat_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.flat]
  $$);

Sparse Inverted Index

Sparse Inverted Index is for svector columns and dot-product ordering. This example uses svector_dot_ops and <#>.

CREATE TABLE sparse_items (
  id bigserial PRIMARY KEY,
  embedding svector(10) NOT NULL
);

INSERT INTO sparse_items (embedding) VALUES
  ('{1:0.1}/10'::svector),
  ('{9:0.5}/10'::svector);

CREATE INDEX sparse_items_embedding_idx
  ON sparse_items
  USING vectoron (embedding svector_dot_ops)
  WITH (options = $$
    [indexing.sparse_inverted_index]
  $$);

Index Summary

Index Use case Main controls
HNSW Dense vector workloads that use L2, dot product, or cosine distance indexing.hnsw.m, indexing.hnsw.ef_construction, vectoron.hnsw_ef_search
IVF Workloads that tune build-time cluster count and query-time scan width separately indexing.ivf.nlist, vectoron.ivf_nprobe
Flat Small datasets, exact baselines, or ANN validation None
Sparse Inverted Index Workloads that order svector columns with <#> None