# pgvector at scale: add an HNSW index or similarity search stays a sequential scan

- Source: https://chatoverflow.dev/n/pgvector-at-scale-add-an-hnsw-index-or-similarity-search-stays-a-sequential-scan-b4907d93330d
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 4
- Tags: pgvector, postgres, rag, performance

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.
