# pg_vectorsearch

> A partition-based PRISM index for fast vector search inside PostgreSQL

- Category: Retrieval & Knowledge (RAG) / Vector Databases
- Language: C
- Licence: PostgreSQL
- Repository: https://github.com/timescale/pg_vectorsearch
- Canonical page: https://ai-tldr.dev/tools/pg-vectorsearch/
- Updated: 2026-10-13

## In short

pg_vectorsearch is an open-source PostgreSQL extension from Tiger Data (the company behind Timescale) for approximate nearest neighbor (ANN) vector search. It adds an index type called PRISM (Partitioned Routing Index for Similarity Matching), an IVF-style index with hierarchical routing that is designed for collections of 100 million vectors and more. It sits in the Vector Databases category of the Retrieval & Knowledge (RAG) tools and is open-source, written in C and licensed PostgreSQL.

## Overview

pg_vectorsearch is an open-source PostgreSQL extension from Tiger Data (the company behind Timescale) for approximate nearest neighbor (ANN) vector search. It adds an index type called PRISM (Partitioned Routing Index for Similarity Matching), an IVF-style index with hierarchical routing that is designed for collections of 100 million vectors and more.

Instead of the graph that HNSW builds, PRISM groups similar vectors into k-means partitions and stores compressed RaBitQ codes, about one bit per dimension, packed into database pages. A query walks a small tree of cluster centroids and then scans the nearest partitions with SIMD (AVX2, AVX512 or NEON). Vectors near a partition boundary can be stored in more than one partition to raise recall, and a two-stage search with error bounds limits how much full-precision reranking is needed.

The extension works with its own `vec32` and `vec16` types and can also index existing pgvector `vector` and `halfvec` columns directly, so a table that uses pgvector keeps its schema and queries. Tiger Data positions it as the successor to pgvectorscale, which it says is moving to maintenance mode. The project is marked alpha: the README says it is meant for testing, not production, and that indexes should be recreated between prereleases.

## What it does

- PRISM index: k-means partitions with hierarchical centroid routing, aimed at 100M+ vectors
- RaBitQ quantization with a two-stage, error-bounded search that reduces full-precision reranking
- SIMD distance computation on AVX2, AVX512 and NEON
- Indexes existing pgvector vector and halfvec columns without rewriting the table
- L2, inner-product and cosine operator classes for vec32/vector and vec16/halfvec
- One main tuning knob, prism.nprobe, where 0 targets about 95% recall automatically
- Inserts, updates and deletes, with oversized posting lists split by prism_rebalance or REINDEX

## Getting started

pg_vectorsearch builds from source with Meson and needs PostgreSQL 18 or later with development headers and a C11 compiler (GCC 11+ or Clang 14+). Load your data before creating the index, because the index is sized from the row count.

1. Build and install the extension

   Clone the repository and build it in release mode. CBLAS is optional and speeds up RaBitQ encoding.

```bash
git clone https://github.com/timescale/pg_vectorsearch.git
cd pg_vectorsearch
meson setup builddir --buildtype=release
meson install -C builddir
```

2. Create a table and load vectors

   Enable the extension and store embeddings in a vec32 column (use vec16 to halve storage).

```sql
CREATE EXTENSION pg_vectorsearch;

CREATE TABLE items (
    id serial PRIMARY KEY,
    embedding vec32(3) STORAGE PLAIN
);

INSERT INTO items (embedding)
SELECT ARRAY[i::real, (i % 7)::real, (i % 5)::real]::vec32
FROM generate_series(1, 1000) i;
```

3. Build a PRISM index and query it

   Create the index with an operator class, optionally raise nprobe for more recall, then order by distance.

```sql
CREATE INDEX ON items USING prism (embedding vec32_l2_ops);

SET prism.nprobe = 40;  -- 0 = auto (about 0.95 recall)

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

4. Or index an existing pgvector table

   PRISM reads pgvector vector and halfvec columns directly. Map vector_<metric>_ops to vec32_<metric>_ops (halfvec to vec16), check with EXPLAIN that the planner uses it, then drop the old HNSW index if you no longer need it.

```sql
CREATE EXTENSION vector;
CREATE EXTENSION pg_vectorsearch;

CREATE INDEX documents_embedding_prism
    ON documents USING prism (embedding vec32_l2_ops);
```

## When to use it

- Running vector search on 100M+ embeddings inside PostgreSQL without a separate vector database
- Replacing a pgvector HNSW index that is too slow to build or too large for available memory
- Serving RAG retrieval with high recall on smaller, cheaper database instances
- Testing a partition-based ANN index alongside an existing pgvector setup before migrating

## Version history

- 2026-10-13: Tiger Data announced pg_vectorsearch in alpha, with the PRISM index and benchmarks showing 100M-vector builds in under two hours where pgvector's HNSW took 42 hours. pgvectorscale moves to maintenance mode.
