Vector similarity, where your data already lives
The pgvector extension adds a vector data type and similarity operators (<-> L2, <#> inner product, <=> cosine) to PostgreSQL. ANN indexes (HNSW, IVFFlat) make millions-of-vectors search practical without a separate vector database.
The shape of an AI feature with pgvector
- Generate an embedding for each row (OpenAI, Cohere, local model — your choice).
- Store it in a
vector(N)column on the same row. - Add an HNSW index for fast approximate nearest neighbour.
- Query: "find the 5 rows whose embedding is closest to this query embedding."
When it's the right answer
Up to roughly 10 million vectors with a single Postgres instance, pgvector is operationally simpler than a dedicated vector DB and gives you the joy of querying embeddings alongside the relational data. Past that scale, dedicated vector stores (Pinecone, Weaviate, Qdrant) start to win on absolute throughput.