Container & RAM Tuning
Sizing pgvector HNSW Indexes & Postgres shared_buffers
Calculate exact 1536-dimension HNSW memory footprint from 1k to 250k chunks and tune shared_buffers + maintenance_work_mem.
~14.5 MB / 1k Chunks · 25% RAM shared_buffers · Zero Disk Thrash
Why HNSW Latency Jumps When Evicted From RAM
HNSW graph traversal relies on random hops across vector neighbor lists. Once the index exceeds Postgres shared_buffers plus OS page cache, every RAG query incurs NVMe random read IOPS instead of microsecond memory lookups.
Maintenance Work Memory During Re-Indexing
Set maintenance_work_mem=256MB in the db command override so building new HNSW graphs finishes quickly without starving concurrent API queries.
Measured Thresholds & Container Limits
| Chunk Count (1536d) | Est. HNSW + Table RSS | Recommended shared_buffers |
|---|---|---|
| 15,000 chunks | ~220 MB index + 420 MB DB | 1,024 MB (on 8 GB VPS) |
| 65,000 chunks | ~940 MB index + 550 MB DB | 4,096 MB (on 16 GB VPS) |
| 200,000 chunks | ~2.9 GB index + 800 MB DB | 8,192 MB (on 32 GB VPS) |