# vector — Postgres extension

> Store embeddings and find the nearest ones (pgvector, HNSW and IVFFlat indexes).

Source: https://scribase.com/extensions/vector

Category: AI and vectors. Version: 0.8.7. Optional, enabled per project.

## About

pgvector adds a vector column type and distance operators: <-> for Euclidean distance, <=> for cosine distance and <#> for negative inner product. With an HNSW or IVFFlat index, nearest-neighbour queries over embeddings stay fast as the table grows.

Keep embeddings next to the rows they describe, so one query can filter by tenant or permissions (and row level security) and rank by similarity at the same time.

## Enable it

```sql
create extension if not exists vector with schema extensions;
```

## Example

```sql
create table documents (
  id bigserial primary key,
  content text not null,
  embedding vector(1536)
);

create index on documents using hnsw (embedding vector_cosine_ops);

-- five closest documents to a query embedding
select id, content
from documents
order by embedding <=> $1
limit 5;
```

## Notes

- The console and API can also create a ready-made semantic search table: POST .../extensions/vector/search-table.

Upstream: https://github.com/pgvector/pgvector