Skip to content

pgvector

Medium — good to knowDatabase

ELI5 - The Vibe Check

pgvector turns your regular Postgres database into a vector database without making you run a whole separate system just to store AI embeddings. You add a new column type that holds arrays of numbers, and suddenly you can ask Postgres to find the rows most similar to this one using the same database that already stores everything else.

Real Talk

pgvector is a PostgreSQL extension that adds a vector data type and similarity search operators (L2 distance, cosine distance, inner product), along with approximate nearest neighbor indexes like IVFFlat and HNSW for fast similarity search at scale. It lets teams store embeddings alongside relational data instead of standing up a dedicated vector database.

Show Me The Code

CREATE EXTENSION vector;
CREATE TABLE docs (id serial, embedding vector(1536));
SELECT * FROM docs
ORDER BY embedding <-> '[0.1, 0.2, 0.3]' LIMIT 5;

When You'll Hear This

"We skipped a separate vector database and just added pgvector to our existing Postgres." / "The HNSW index made similarity search fast enough for production."

Made with passive-aggressive love by manoga.digital. Powered by Claude.