vchord
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1810 | vchord | No | Yes | Yes | Yes | No | Yes | - |
| Related | vector vector vectorscale pgcontext vectorize pg_rrf pg_search vchord_bm25 pg_bestmatch pgml pg4ml |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.1 | 1817161514 | vchord | vector |
| RPM | PIGSTY | 1.1.1 | 1817161514 | vchord_$v | pgvector_$v |
| DEB | PIGSTY | 1.1.1 | 1817161514 | postgresql-$v-vchord | postgresql-$v-pgvector |
Build
You can build the RPM / DEB packages for vchord using pig build:
Install
You can install vchord directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
Usage
- https://github.com/tensorchord/VectorChord
- Launch Blog: VectorChord: Store 400k Vectors for $1 in PostgreSQL
Add this extension to shared_preload_libraries in postgresql.conf
Create Index on embedding:
Docs
Query
The query statement is exactly the same as pgvector. VectorChord supports any filter operation and WHERE/JOIN clauses like pgvecto.rs with VBASE.
Supported distance functions are:
<->- L2 distance<#>- (negative) inner product<=>- cosine distance
Due to the limitation of postgresql query planner, we cannot support the range query like
SELECT embedding <-> '[3,1,2]' as distance WHERE distance < 0.1 ORDER BY distancedirectly.
To query vectors within a certain distance range, you can use the following syntax.
Query Performance Tuning
You can fine-tune the search performance by adjusting the probes and epsilon parameters:
And for postgres’s setting
Indexing prewarm
To prewarm the index, you can use the following SQL. It will significantly improve performance when using limited memory.
Index Build Time
Index building can be parallelized using build_threads in the index options and PostgreSQL settings. Optimize parallelism using the following settings:
Indexing Progress
You can check the indexing progress by querying the pg_stat_progress_create_index view.
External Index Precomputation
Unlike an internal build, external index precomputation performs the partitioning work outside PostgreSQL and inserts the resulting centroids into a PostgreSQL table. This can reduce database-side build time and memory use for large datasets.
To get started, you need to do a clustering of vectors using faiss, scikit-learn or any other clustering library.
The centroids should be preset in a table of any name with 3 columns:
- id(integer): id of each centroid, should be unique
- parent(integer, nullable): parent id of each centroid, should be NULL for normal clustering
- vector(vector): representation of each centroid,
pgvectorvector type
And example could be like this:
For the complete workflow and table requirements, see the official External Build documentation.
Limitations
- Architecture Compatibility: The fast-scan kernel is optimized for x86_64 architectures. While it runs on aarch64, performance may be lower.
Build
Building this extension requires clang-17+
Which is available on EL 8/9, Ubuntu 24.04 directly, but require manual installation on Ubuntu 22.04 / Debian 12.
For example, install clang-18 on Ubuntu 22 / Debian 12 and set it as the default clang:
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)