Skip to content

vchord

Vector database plugin for Postgres, written in Rust

vchord · Vector database plugin for Postgres, written in Rust

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1810vchordvchord1.5.0RAGAGPL-3.0-onlyRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd-rNoYesYesYesyesno
PGSTY fork; requires vector and preload; vchordg/halfvec scans can return distances out of order; rerank for strict order.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.5.019 18 17 16 15vchordvector
RPMPIGSTY1.5.019 18 17 16 15vchord_$vpgvector_$v
DEBPIGSTY1.5.019 18 17 16 15postgresql-$v-vchordpostgresql-$v-pgvector
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.3.0PIGSTY 1.3.0PIGSTY 1.3.0PIGSTY 1.3.0
el8.aarch64N/APIGSTY 1.3.0PIGSTY 1.3.0PIGSTY 1.3.0PIGSTY 1.3.0
el9.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
el9.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
el10.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
el10.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
d12.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
d12.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
d13.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
d13.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u22.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u22.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u24.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u24.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u26.x86_64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0
u26.aarch64PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0PIGSTY 1.5.0

Source

pig build pkg vchord;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install vchord;		# install by package name

pig install vchord -v 19;   # install for PG 19
pig install vchord -v 18;   # install for PG 18
pig install vchord -v 17;   # install for PG 17
pig install vchord -v 16;   # install for PG 16
pig install vchord -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'vchord';

Create this extension with:

CREATE EXTENSION vchord CASCADE; -- requires vector

Usage

Sources:

vchord 1.5.0 provides approximate vector search on PostgreSQL 15–19. It uses pgvector’s types and adds the partitioned vchordrq index and the disk graph vchordg index. It requires the vector extension, shared preloading, and superuser privileges to install. Graph indexing is documented as a preview feature.

Add the library to the existing preload list and restart PostgreSQL:

shared_preload_libraries = 'vchord'
CREATE EXTENSION vchord CASCADE;
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]'), ('[3,1,2]');
CREATE INDEX items_embedding_idx ON items
USING vchordrq (embedding vector_l2_ops);

SELECT id, embedding <-> '[3,1,2]' AS distance
FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;

Small datasets can start with an unpartitioned index. For larger datasets, choose the partition hierarchy through TOML build.internal.lists, then set vchordrq.probes to the number of partitions to search at each level. More probes trade query work for recall; the probe list must match the hierarchy. The graph alternative uses the same column and distance operator classes:

CREATE INDEX items_embedding_graph_idx ON items
USING vchordg (embedding vector_l2_ops)
WITH (options = $$
m = 32
ef_construction = 64
$$, ef_search = 128);

Use the graph definition as an alternative to the partitioned index above. The recall example below assumes only the partitioned index exists; inspect the query plan when comparing index methods.

Types, Operators, and Tuning

ObjectPurpose
vector_l2_ops, <->Euclidean distance, ordered ascending.
vector_ip_ops, <#>Negative inner product, ordered ascending.
vector_cosine_ops, <=>Cosine distance, ordered ascending.
halfvecHalf-precision vectors, with corresponding halfvec_*_ops classes.
rabitq4, rabitq8Quantized vector storage; conversion loses precision.
sphere, <<->>, <<#>>, <<=>>Distance-radius predicates for L2, inner product, and cosine search.
vchordrq.epsilonReranking tradeoff; default 2.5 in 1.2.0, previously 1.9.
vchordg.ef_searchGraph search breadth; default 64.
vchordrq_prewarm, vchordg_prewarmLoad hot index pages; require table ownership or table-level SELECT.
SELECT id FROM items
WHERE embedding <<->> sphere('[1,2,3]'::vector, 0.5);

SELECT dequantize_to_vector(quantize_to_rabitq8('[1,2,3]'::vector));
SELECT dequantize_to_halfvec(quantize_to_rabitq4('[1,2,3]'::halfvec));

Sphere radii use the distance operator’s units. PostgreSQL rechecks graph sphere predicates, but approximate search can still miss matching rows. Dequantization cannot recover the original vector exactly.

Per-index probes, epsilon, and ef_search options supply search defaults. Explicit GUC settings, including database or server settings, override them. Resetting a session setting restores its configured default, which can still override the index.

Ordering and Recall

Graph scans can discover closer rows after returning earlier candidates; nearly equal half-precision distances can also appear out of order. Increasing the search breadth reduces some ordering errors but does not guarantee strict ordering. Materialize a larger candidate set and sort it explicitly when ordering matters:

WITH candidates AS MATERIALIZED (
    SELECT id, embedding <-> '[3,1,2]' AS distance
    FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 100
)
SELECT * FROM candidates ORDER BY distance LIMIT 10;

This sorts the retrieved candidates; recall still depends on the candidate count and search parameters. For partitioned indexes, compare approximate results with an exact baseline:

SELECT vchordrq_evaluate_query_recall(
    query => $$SELECT ctid FROM items
                ORDER BY embedding <-> '[3,1,2]' LIMIT 5$$,
    exact_search => true
);

The query must return ctid; keep sequential scans enabled for the exact pass. Multi-vector MaxSim queries using @# require exact_search => true for recall evaluation.

Maintenance and Upgrade

Keep normal vacuuming enabled: graph searches exclude deleted vertices after VACUUM, and index maintenance updates tuple/page statistics. ANALYZE alone does not rebuild or compact the index.

Install matching 1.5.0 library and SQL files, restart PostgreSQL to load the new library, then update each database as the extension owner or an administrator:

ALTER EXTENSION vchord UPDATE TO '1.5.0';

The release provides upgrade paths from 0.2.0 through 1.1.1 without reindexing. Recheck representative rankings after upgrading: 1.2.0 fixes MaxSim candidate estimates, graph sphere filters, deleted-vertex visibility, and quantization edge cases, and raises the default reranking budget. The extension is relocatable; include its chosen schema in the search path or qualify its objects.

Version 1.4.0

Version 1.4.0 supports PostgreSQL 15–19. PostgreSQL 14 requires a server upgrade first. Install matching files, restart PostgreSQL and apply ALTER EXTENSION vchord UPDATE; in each database.

RQ filter key columns support equality, range and NULL conditions. vchordrq.probes selects initial lists; vchordrq.max_probes limits subsequent expansion and defaults to -1, allowing all lists. The initial probes are always honored. In 1.5.0, ordered keyed scans stream the initial probes and expand on demand; distances can decrease across refill rounds. Measure recall before lowering this cap.

Ordinary 1.3.0 RQ indexes retain format 1001. A new index with filter key columns uses format 1003. Before returning to a 1.3.0 binary, remove keyed indexes under 1.4.0 and restore a compatible extension catalog or backup. A binary downgrade alone is insufficient. Sphere scans through both index methods remain approximate; use a verified sequential plan when every matching row is required.

Version 1.5.0 Maintenance

Version 1.5.0 reads 1.4.0 indexes in place and retains their SQL objects and on-disk formats. Recheck ordering and recall for keyed RQ queries as well as graph queries; explicitly sort materialized candidates when strict ordering is required. Sphere rechecks, nullable-vector scans, prepared queries and prefiltering receive correctness fixes.

Graph insertion and VACUUM connectivity are repaired. If an older VACUUM already removed an entire graph region, rebuild that affected index with REINDEX INDEX CONCURRENTLY index_name;; installing the new code cannot recreate links already lost.

Table reader