Back to glossary

Term

pgvector

pgvector is an open-source PostgreSQL extension for vector search — adding embedding columns, distance functions, and ANN indexes (HNSW, IVFFlat) directly to an existing Postgres database.

pgvector — explained

Instead of running a separate dedicated vector database, pgvector extends PostgreSQL with a vector data type, distance operators (<-> euclidean, <#> dot product, <=> cosine), and the index types HNSW (fast, low tuning) and IVFFlat (smaller, slower on lookup). Embeddings can sit in the same table as your metadata — joins, WHERE filters, transactions, and the familiar Postgres ecosystem all included.

Example / Practical context

A RAG setup for an existing SaaS app: documents are already in Postgres, pgvector is enabled via CREATE EXTENSION vector, an embedding vector(1536) column is added, and an HNSW index is built. Retrieval runs via SELECT … ORDER BY embedding <=> $1 LIMIT 10. Hosted on Supabase, Neon, AWS RDS, Azure, and many other providers — no extra service required.

Dedicated vector DBs like Pinecone or Qdrant scale into the billions of vectors and often offer lower p99 latency, but require additional infrastructure. pgvector is the pragmatic choice when Postgres is already in the stack and vector counts are in the millions. With pg_trgm or Postgres full-text, hybrid search can be built directly inside the same database.

Entdecke mehr