pgvecto.rsのdockerプル:
VectorChord(VChord)は、スケーラブル、高性能、およびディスク効率の高いベクター類似性検索用に設計されたPostgResQL拡張機能であり、PGVecto.RSの後継者として機能します。
VectorChordを使用すると、わずか1ドルで400,000のベクトルを保存できます。大幅な節約を可能にします。Pineconeの最適化されたストレージと比較して6倍のベクトル、同じ価格1でPGVector/PGVecto.RSよりも26倍多くなります。その他の洞察については、ローンチブログ投稿をご覧ください。
VectorChordは、PGVecto.RSおよびPGVectorをめぐる顕著な強化を紹介します。
furityパフォーマンスの強化:PGVectorのHNSW実装と比較して、最大5倍の高速クエリ、16倍高いインサートスループット、16倍速い2インデックスビルで最適化された操作を提供します。
?手頃な価格のベクトル検索:クエリ100M 768次元ベクトルは、わずか32GBのメモリを使用して、TOP10 Recall@95%で35ms P50の遅延を達成し、高い検索品質を維持しながらインフラストラクチャコストを抑えるのに役立ちます。
?シームレスな統合:PGVectorデータ型と構文と完全に互換性があり、最適なデフォルトをボックスから提供します - 手動パラメーターチューニングは必要ありません。パフォーマンスを向上させるために、VectorChordをドロップするだけです。
?外部インデックスビルド:IVFを活用してインデックスを外部(GPU上)に構築して、Kmeansクラスタリングを高速化し、Rabitq 3圧縮と組み合わせて、自律的な再ランキングを通じて検索品質を維持しながらベクターを効率的に保存します。
?長いベクトルのサポート:最大65,535の寸法のベクトルを保存および検索し、テキスト巻き取り-3-largeなどの最高の高次元モデルを簡単に使用できます。
新規ユーザーの場合は、Docker画像を使用してすぐに開始することをお勧めします。
docker run
--name vectorchord-demo
-e POSTGRES_PASSWORD=mysecretpassword
-p 5432:5432
-d tensorchord/vchord-postgres:pg17-v0.1.0次に、 psqlコマンドラインツールを使用してデータベースに接続できます。デフォルトのユーザー名はpostgresであり、デフォルトのパスワードはmysecretpasswordです。
psql -h localhost -p 5432 -U postgres次のSQLを実行して、拡張機能が有効になっていることを確認します。
CREATE EXTENSION IF NOT EXISTS vchord CASCADE; postgresql.confのshared_preload_librariesにvchord.soを追加してください。
-- Add vchord and pgvector to shared_preload_libraries --
ALTER SYSTEM SET shared_preload_libraries = ' vchord.so ' ;VectorChord Rabitq(VCHORDRQ)インデックスを作成するには、次のSQLを使用できます。
-- Set residual_quantization to true and spherical_centroids to false for L2 distance --
CREATE INDEX ON gist_train USING vchordrq (embedding vector_l2_ops) WITH (options = $$
residual_quantization = true
[ build . internal ]
lists = [ 4096 ]
spherical_centroids = false
$$);
-- Set residual_quantization to false and spherical_centroids to true for cos/dot distance --
CREATE INDEX ON laion USING vchordrq (embedding vector_cos_ops) WITH (options = $$
residual_quantization = false
[ build . internal ]
lists = [ 4096 ]
spherical_centroids = true
$$);クエリステートメントは、PGVectorとまったく同じです。 VectorChordは、vBaseを使用してpgvecto.rsのような条項と条項/結合任意のフィルター操作をサポートします。
SELECT * FROM items ORDER BY embedding < - > ' [3,1,2] ' LIMIT 5 ;サポートされている距離関数は次のとおりです。
probesとepsilonパラメーターを調整して、検索パフォーマンスを微調整できます。
-- Set probes to control the number of lists scanned.
-- Recommended range: 3%–10% of the total `lists` value.
SET vchordrq . probes = 100 ;
-- Set epsilon to control the reranking precision.
-- Larger value means more rerank for higher recall rate.
-- Don't change it unless you only have limited memory.
-- Recommended range: 1.0–1.9. Default value is 1.9.
SET vchordrq . epsilon = 1 . 9 ;
-- vchordrq relies on a projection matrix to optimize performance.
-- Add your vector dimensions to the `prewarm_dim` list to reduce latency.
-- If this is not configured, the first query will have higher latency as the matrix is generated on demand.
-- Default value: '64,128,256,384,512,768,1024,1536'
-- Note: This setting requires a database restart to take effect.
ALTER SYSTEM SET vchordrq . prewarm_dim = ' 64,128,256,384,512,768,1024,1536 ' ;そして、Postgresの設定用
-- If using SSDs, set `effective_io_concurrency` to 200 for faster disk I/O.
SET effective_io_concurrency = 200 ;
-- Disable JIT (Just-In-Time Compilation) as it offers minimal benefit (1–2%)
-- and adds overhead for single-query workloads.
SET jit = off;
-- Allocate at least 25% of total memory to `shared_buffers`.
-- For disk-heavy workloads, you can increase this to up to 90% of total memory. You may also want to disable swap with network storage to avoid io hang.
-- Note: A restart is required for this setting to take effect.
ALTER SYSTEM SET shared_buffers = ' 8GB ' ;インデックスを事前に装備するには、次のSQLを使用できます。限られたメモリを使用すると、パフォーマンスが大幅に向上します。
-- vchordrq_prewarm(index_name::regclass) to prewarm the index into the shared buffer
SELECT vchordrq_prewarm( ' gist_train_embedding_idx ' ::regclass) "インデックスビルディングは並列化でき、外部の重心の事前計算により、合計時間は主にディスク速度によって制限されます。次の設定を使用して並列性を最適化します。
-- Set this to the number of CPU cores available for parallel operations.
SET max_parallel_maintenance_workers = 8 ;
SET max_parallel_workers = 8 ;
-- Adjust the total number of worker processes.
-- Note: A restart is required for this setting to take effect.
ALTER SYSTEM SET max_worker_processes = 8 ;pg_stat_progress_create_indexビューをクエリして、インデックスの進行状況を確認できます。
SELECT phase, round( 100 . 0 * blocks_done / nullif(blocks_total, 0 ), 1 ) AS " % " FROM pg_stat_progress_create_index;純粋なSQLとは異なり、外部インデックスの事前計算は最初に外側のクラスタリングを行い、PostgreSQLテーブルに重心を挿入します。より複雑なかもしれませんが、外部ビルドは、より大きなデータセット(> 5m)で間違いなくはるかに高速です。
開始するには、 faiss 、 scikit-learn 、またはその他のクラスタリングライブラリを使用してベクターのクラスタリングを行う必要があります。
重心は、3つの列のある名前のテーブルでプリセットする必要があります。
pgvectorベクタータイプの表現そして、例は次のようなものかもしれません:
-- Create table of centroids
CREATE TABLE public .centroids (id integer NOT NULL UNIQUE, parent integer , vector vector( 768 ));
-- Insert centroids into it
INSERT INTO public . centroids (id, parent, vector) VALUES ( 1 , NULL , ' {0.1, 0.2, 0.3, ..., 0.768} ' );
INSERT INTO public . centroids (id, parent, vector) VALUES ( 2 , NULL , ' {0.4, 0.5, 0.6, ..., 0.768} ' );
INSERT INTO public . centroids (id, parent, vector) VALUES ( 3 , NULL , ' {0.7, 0.8, 0.9, ..., 0.768} ' );
-- ...
-- Create index using the centroid table
CREATE INDEX ON gist_train USING vchordrq (embedding vector_l2_ops) WITH (options = $$
[ build . external ]
table = ' public.centroids '
$$);ワークフローを簡素化するために、外部インデックスの事前計算にエンドツーエンドスクリプトを提供します。スクリプトを参照してください。
PGRXの指示に従ってPGRXをインストールします。
cargo install --locked cargo-pgrx
cargo pgrx init --pg17 $( which pg_config ) # To init with system postgres, with pg_config in PATH
cargo pgrx install --release --sudo # To install the extension into the system postgres with sudo このソフトウェアは、デュアルライセンスモデルの下でライセンスされています。
GNU Affero General Public License V3(AGPLV3) :AGPLV3の条件でこのソフトウェアを使用、変更、および配布することができます。
弾性ライセンスV2(ELV2) :特定の制限がある弾性ライセンスV2でこのソフトウェアを使用、変更、および配布することもできます。
お客様のニーズに基づいて、いずれかのライセンスを選択できます。商業的なコラボレーションやサポートを歓迎しますので、ライセンスに関する質問やリクエストを[email protected]にメールしてください。
768次元ベクトルと95%のリコールを備えたマイスケールベンチマークに基づいています。 ↩
768次元ベクトルを備えたマイスケールベンチマークに基づいています。詳細については、ブログ投稿をチェックアウトしてください。 ↩
Gao、Jianyang、Cheng Long。 「Rabitq:近隣の近隣検索のための理論的誤差を使用して高次元ベクトルを量子化します。」データの管理に関するACMの議事録2.3(2024):1-27。 ↩