pgvector
Open-source vector similarity search for PostgreSQL.
Why consider pgvector?
pgvector is an open-source PostgreSQL extension that adds vector data types, exact and approximate nearest neighbor search (HNSW, IVFFlat), and L2/cosine distance operators to PostgreSQL.
Learn pgvector by building
Practical setup notes, real use cases, and copy-ready examples in one focused guide.
In this guide3 sections
Overview of pgvector
pgvector transforms standard PostgreSQL instances into full vector databases. It allows developers to store vector embeddings directly alongside their relational application tables, eliminating the need to maintain separate vector databases.
Enabling the Extension
In your PostgreSQL database:
CREATE EXTENSION vector;Storing and Indexing Embeddings
Create a table with a 1536-dimensional vector column (OpenAI embedding size):
CREATE TABLE documents ( id bigserial PRIMARY KEY, content text, embedding vector(1536));-- Create an HNSW index for ultra-fast vector similarity searchCREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);Query nearest neighbors using cosine similarity:
SELECT content, 1 - (embedding <=> '[0.012, -0.045, ...]') AS similarityFROM documentsORDER BY embedding <=> '[0.012, -0.045, ...]'LIMIT 5;pgvector is licensed under the PostgreSQL License.
Related tools
More options with a similar category or technology profile.
AI Fullstack SaaS Boilerplate
All-in-one AI SaaS starter kit with OpenAI, Anthropic, Gemini, Stripe, and Next.js.
Vibe
Transcribe audio and generate subtitles completely offline with modern UI on desktop.
Buzz
Transcribe and translate audio offline on your personal computer using OpenAI Whisper.
InvokeAI
Leading open-source generative AI creative engine for visual artists and design studios.