Vector embeddings are central to Generative AI applications, enabling semantic similarity search. pgvector is the Postgres extension that supports vector search, and its 0.5.0 release introduced HNSW (Hierarchical Navigable Small Worlds), a graph-based approximate nearest neighbor (ANN) index. The post explains what vectors and embeddings are, how distance metrics like L2 and cosine work, and how to perform vector similarity search with pgvector SQL queries. It then dives into HNSW index creation, covering the key parameters m (graph degree), ef_construction (candidate list size during build), and ef_search (candidate list size during query). Trade-offs between exact and approximate search are discussed, along with HNSW pros (speed, high recall, scalability) and cons (approximate results, resource-intensive indexing, parameter complexity).

11m read timeFrom neon.com
Post cover image
Table of contents
Vectors and Vector EmbeddingsSimilarity SearchDistance metricsVector search with pgvectorOptimizing vector similarity searchHNSW Pros and ConsConclusion