AI & Vectors

Vector indexes

Once your vector table starts to grow, you will likely want to add an index to speed up queries. Without indexes, you'll be performing a sequential scan which can be a resource-intensive operation when you have many records.

Choosing an index

Today pgvector supports two types of indexes:

In general we recommend using HNSW because of its performance and robustness against changing data.

Distance operators

Indexes can be used to improve performance of nearest neighbor search using various distance measures. pgvector includes 3 distance operators:

OperatorDescriptionOperator class
<->Euclidean distancevector_l2_ops
<#>negative inner productvector_ip_ops
<=>cosine distancevector_cosine_ops

Currently vectors with up to 2,000 dimensions can be indexed.

Resources

Read more about indexing on pgvector's GitHub page.