# pgvecto.rs

> Postgres extension for vector similarity search, written in Rust

- Category: Retrieval & Knowledge (RAG) / Vector Databases
- Language: Rust
- Repository: https://github.com/tensorchord/pgvecto.rs
- Website: https://docs.pgvecto.rs
- Canonical page: https://ai-tldr.dev/tools/pgvecto-rs/

## In short

pgvecto.rs is a PostgreSQL extension that adds vector similarity search to your database. It sits in the Vector Databases category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Rust. To get started: run the Docker image.

## Overview

pgvecto.rs is a PostgreSQL extension that adds vector similarity search to your database. It is written in Rust on top of the pgrx framework, and it gives Postgres a new vector(n) data type plus distance operators so you can store and query embeddings using ordinary SQL.

It is meant for developers who already run PostgreSQL and want to keep their embeddings next to their relational data instead of standing up a separate vector store. It supports up to 65535 dimensions, extra types such as binary vectors, FP16, and INT8, and a VBASE method that combines vector search with filters and joins.

Note that the project has been succeeded by VectorChord, which the maintainers (TensorChord) describe as having better stability and performance. New work is recommended to use VectorChord, with a migration guide provided, but pgvecto.rs remains usable as described in its README.

## What it does

- Adds a vector(n) data type to PostgreSQL, supporting up to 65535 dimensions
- Three distance operators: squared Euclidean (<->), negative dot product (<#>), and cosine distance (<=>)
- VBASE method for combining vector search with relational queries (TopK + filter + join)
- Extra data types including binary vectors, FP16 (vecf16), and INT8 to reduce memory use
- Runtime SIMD dispatch that picks instructions based on the host CPU
- Stores index data separately from PostgreSQL's native storage engine

## Getting started

The quickest path is the official Docker image, which ships Postgres with the extension already built. Then enable the extension and run vector queries in plain SQL.

1. Run the Docker image

   Start a Postgres container with pgvecto.rs preinstalled. The default user is postgres and the password is the one you set here.

```bash
docker run \
  --name pgvecto-rs-demo \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -p 5432:5432 \
  -d ghcr.io/tensorchord/pgvecto-rs:pg17-v0.4.0
```

2. Connect and enable the extension

   Connect with psql, then create the vectors extension so the vector type and operators become available.

```bash
psql -h localhost -p 5432 -U postgres
```

3. Create a table with a vector column

   Enable the extension and define a table that holds embeddings as a vector column.

```sql
DROP EXTENSION IF EXISTS vectors;
CREATE EXTENSION vectors;

CREATE TABLE items (
  id bigserial PRIMARY KEY,
  embedding vector(3) NOT NULL -- 3 dimensions
);
```

4. Insert and search vectors

   Insert some embeddings, then order by a distance operator to find the nearest matches.

```sql
INSERT INTO items (embedding)
VALUES ('[1,2,3]'), ('[4,5,6]');

-- query the similar embeddings
SELECT * FROM items ORDER BY embedding <-> '[3,2,1]' LIMIT 5;
```

## When to use it

- Add semantic search over text or image embeddings to an app that already uses PostgreSQL
- Build a retrieval-augmented generation (RAG) or question-answering backend that keeps embeddings alongside relational data
- Run vector similarity queries with SQL filters and joins in a single Postgres query instead of a separate vector database
- Reduce embedding memory footprint with FP16 (vecf16), INT8, or binary vector types on high-dimensional data
