StreamingDiskANN index-supported queries
You need to use the cosine-distance embedding measure (<=>) in your ORDER BY clause. A canonical query would be:
Pgvector provides a graph-based indexing algorithm based on the popular HNSW algorithm.
To create an index named document_embedding_idx on table document_embedding having a vector column named embedding, run:
This command creates an index for cosine-distance queries because of vector_cosine_ops. There are also "ops" classes for Euclidean distance and negative inner product:
| Distance type | Query operator | Index ops class |
|---|---|---|
| Cosine / Angular | <=> | vector_cosine_ops |
| Euclidean / L2 | <-> | vector_ip_ops |
| Negative inner product | <#> | vector_l2_ops |
Pgvector HNSW also includes several index build-time and query-time parameters.