pgvector: Embeddings in PostgreSQL
Enable the pgvector extension in PostgreSQL, create a table with a vector column, insert embeddings, and run nearest neighbor queries using the cosine distance operator.
pgvector: Vector Search in PostgreSQL
pgvector is an open-source PostgreSQL extension that adds a vector data type and similarity search operators. It lets you store embeddings alongside your regular application data in the same database you already operate, avoiding a separate vector store.
This is ideal for teams that already use PostgreSQL and want to add semantic search without introducing a new infrastructure dependency.
Enabling the pgvector Extension
Install pgvector from the official repository or use a managed PostgreSQL provider that pre-installs it (Supabase, Neon, AWS RDS, Render). Then enable it in your database with a single SQL command — no restart required.
-- Run this once per database to enable the extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Verify it's installed
SELECT extname, extversion
FROM pg_extension
WHERE extname = 'vector';
-- Returns: vector | 0.7.0 (or similar)All lessons in this course
- Why You Need a Vector Database
- Getting Started with Pinecone
- pgvector: Embeddings in PostgreSQL
- Choosing and Benchmarking Vector Stores