Skip to content
BENIBIX Learn

pgvector

AI🔎 Retrieval & SearchVector Databases

Also known as pgvector Extension, Postgres Vector Extension

A free add-on for Postgres. It lets the database store and search vectors.

Think of it like

It is like adding a new drawer to a desk you already own. No new desk needed.

Example

Lucy's shop already runs on Postgres. She adds pgvector and stores a vector for each product. One SQL query finds items like it.

Why it matters

Many teams already run Postgres. They get vector search without a new system to learn and pay for.

Definition

pgvector is a free add-on that lets the Postgres database store and search vectors. You add a column of type vector beside your normal columns. Then you can sort rows by how close their vectors are to a query. It can build HNSW and IVFFlat indexes to make that fast. Your vectors live next to the rest of your data, in one place.

Example code

sql
CREATE EXTENSION vector;
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
Turn it on, add a vector column, then ask for the 5 nearest rows.
pgvector sits inside a database you already run. You add no new system.

Common mistake

Forgetting to add an index. Without one, each search checks every row.

Key takeaways

  1. 1
    Inside Postgres. Vectors sit beside your other data.
  2. 2
    Plain SQL. Sort by distance and limit.
  3. 3
    Add an index. HNSW or IVFFlat for speed.