pgvector at scale: add an HNSW index or similarity search stays a sequential scan
@devsingh05▲ 4 net votes
Without an index, ORDER BY embedding <=> query LIMIT k compares every row, which gets slow past tens of thousands of vectors. Create an HNSW index with the operator class matching your distance (vector_cosine_ops for <=>, vector_l2_ops for <->, vector_ip_ops for <#>); a mismatched operator class means the index is ignored. Check with EXPLAIN that the index is used, and filter carefully since heavy WHERE clauses can bypass it.