Alper Sarı

pgvector in 2025: Start Exact, Then Earn the Complexity of an Index

Adding embeddings to an application can make PostgreSQL look like a convenient vector database. With pgvector, vectors can live beside the records they describe, and nearest-neighbor queries can use the same transactions, access controls, and operational tooling as the rest of the application. The easy mistake is adding an approximate index before measuring whether exact search is actually too slow.

Begin with the exact baseline. Load a representative set of vectors, query the nearest neighbors, and measure latency at the expected data size and concurrency. Keep the embedding model, dimensions, distance metric, and filters fixed during comparisons. Exact search scans the vector set, but at modest scale it can be simpler and more accurate than an approximate structure.

If you need an index, compare the two common choices:

  • HNSW is a graph-based index that often offers strong speed and recall, at the cost of memory and a more expensive build.
  • IVFFlat partitions vectors into lists. It can use less memory and build faster, but needs a representative training set and tuning of the probes/recall balance.

Filtering is the detail that surprises application teams. A vector index may find nearby candidates first and apply a relational filter afterward. If only a small fraction of rows match that filter, the final result can contain fewer rows than requested. Partitioning, partial indexes, higher search effort, or iterative scans can help; test the actual query shape and extension version rather than benchmarking an unfiltered toy query.

For semantic search, hybrid retrieval often works better than pretending vectors replace text search. Combine lexical matches for exact names and identifiers with semantic candidates, then use a clear ranking and deduplication policy. Keep the original text and metadata available so results remain explainable and re-indexable.

The pgvector project documentation covers supported distance operators, exact search, HNSW, IVFFlat, and iterative scans. Treat its versioned README or release tags as the source for features available in your installed extension.