# pgvector

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

**Field:** Artificial Intelligence  
**Category:** Retrieval & Search  
**Also known as:** pgvector Extension, Postgres Vector Extension

## Think of it like

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

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Vector Database](https://learn.benibix.com/term/ai/vector-database)
- [PostgreSQL](https://learn.benibix.com/term/development/postgresql)
- [Hierarchical Navigable Small World (HNSW)](https://learn.benibix.com/term/ai/hierarchical-navigable-small-world)
- [Vector Index](https://learn.benibix.com/term/ai/vector-index)
- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)

![Four columns, from you build more to you run less. A library inside your program: FAISS. An add-on in a database you run: pgvector. A vector database, open source, to run or rent: Chroma, Qdrant and Weaviate. A hosted service you rent: Pinecone.](https://learn.benibix.com/diagrams/ai3-vector-stores.svg)

---

Source: https://learn.benibix.com/term/ai/pgvector
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
