0PricingLogin
AI Engineering Academy · Lesson

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

  1. Why You Need a Vector Database
  2. Getting Started with Pinecone
  3. pgvector: Embeddings in PostgreSQL
  4. Choosing and Benchmarking Vector Stores
← Back to AI Engineering Academy