Database & AI Infrastructure
pgvector HNSW インデックス RAM & サイズ計算機
PostgreSQL pgvector HNSW インデックスのメモリ要件を本番導入前にシミュレーション。ディスクスワップを防ぎ、最適な設定を出力します。
1. Dataset & Vector Dimensions
Vector Count (Rows)1,000,000 vectors
2. Vector Precision & Quantization
3. HNSW Graph Hyperparameters
Higher m increases recall at the cost of index RAM and build time.
Controls graph build quality. Does not affect index RAM size.
Fast (20)Balanced (100)Max Recall (400)
4. PostgreSQL Host Server Specs
Memory & Sizing Estimates
Index fits cleanly in RAM
HNSW graph and vector payloads (7.05 GB) fit comfortably inside your 32 GB server memory for sub-15ms search latency.
HNSW Index Size (RAM):7.05 GB
Raw Table Footprint:6.39 GB
Total Recommended RAM:> 8.8 GB
Recommended maintenance_work_mem:7943 MB
Est. Index Build Time:~21s
Key SRE Rule for pgvector
Unlike B-tree indexes where partial cache hits still yield acceptable performance, HNSW vector search relies on non-local random graph walks. If the index spills from RAM to disk, latency degrades from 5ms to 800ms+.
-- 1. Enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- 2. Create optimized vector storage table
CREATE TABLE IF NOT EXISTS documents (
id BIGSERIAL PRIMARY KEY,
content TEXT NOT NULL,
metadata JSONB DEFAULT '{}'::jsonb,
embedding vector(1536) NOT NULL
);
-- 3. Set dedicated build memory for the current session (avoids disk spills)
SET maintenance_work_mem = '7943MB';
SET max_parallel_maintenance_workers = 6;
-- 4. Create HNSW index for sub-15ms semantic search
CREATE INDEX IF NOT EXISTS idx_documents_embedding_hnsw
ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (
m = 16,
ef_construction = 64
);Advertisement
How to use
- Step 1: ベクトル行数と埋め込みモデル(OpenAI 1536次元など)を選択します。
- Step 2: 精度(Float32、Float16 halfvec、Binary)を選択します。
- Step 3: HNSWハイパーパラメータ(m、ef_construction)を調整します。
- Step 4: 生成されたSQLおよび設定ファイルをコピーします。
Frequently asked questions
なぜpgvector HNSWインデックスはRAMに完全に収まる必要がありますか?
HNSWはランダムなグラフ探索を行うため、ディスクI/Oが発生すると検索レイテンシが急激に悪化します。インデックス全体をRAM上に保持することが必須です。
The Senior Full-Stack Production Kit (2026)
Checklists, Docker recipes, and SSR error fixes in one dense PDF.