DEV Community

kkkevin
kkkevin

Posted on Originally published at opshubs.space

RAG Vector Database Sizing Guide: HNSW RAM, Quantization & Cost (Qdrant vs pgvector vs Pinecone)

Most production RAG outages do not happen in the LLM layer—they happen when your vector database silently runs out of RAM during an HNSW index build or segment compaction. Teams frequently estimate memory with the naive formula vectors × dimensions × 4 bytes, provision a VM to match, and hit OOMKilled the moment ingestion doubles.

This guide breaks down the exact memory anatomy of HNSW vector indexes, shows how Scalar INT8 and Binary quantization cut RAM by 4× to 32× without wrecking recall, and compares real-world monthly costs across Qdrant, PostgreSQL pgvector, and serverless Pinecone. If you want to plug in your own numbers right away, use our free RAG Vector Database Memory & Cost Calculator.

1. Why Naive Vector Math Underestimates RAM by 40%+

A production vector store keeps three distinct structures hot in memory—not just the floating-point arrays:

Vector Database Memory Anatomy and Quantization Compression

  • Raw Vector Footprint: N × D × bytes_per_dim. For 1,000,000 chunks at 1,536 dimensions (text-embedding-3-small) in FP32 (4 bytes), raw vectors alone take 5.72 GB.

  • HNSW Graph Links: Each node stores up to 2 × m bidirectional neighbor links on layer 0 (4 bytes per integer ID) plus upper-layer pointers and allocator overhead: roughly N × m × 8 × 1.15 bytes. At m = 16 and 1M vectors, that adds ~140 MB; at 10M vectors with m = 32, the graph alone consumes ~2.75 GB—even if your vectors are heavily quantized.

  • Payload & Filter Indexes: Filtering by tenant_id, doc_type, or updated_at requires inverted/B-tree payload indexes in RAM (~25% of raw metadata size).

  • Operational Headroom (1.3×): Segment merges, background HNSW rebuilds, and concurrent query buffers spike memory usage by 25%–35%. Multiply everything by your replication factor (typically 2× for production HA).

2. Quantization: Cutting Vector RAM by 4× to 32×

Keeping full FP32 vectors in RAM is almost never cost-effective past 500K chunks. Modern vector engines (Qdrant, Milvus, pgvector 0.7+) let you keep a compressed copy in RAM for fast graph traversal while storing original FP32 vectors on NVMe for top-k rescoring.

QuantizationBytes / Dim1M × 1536d VectorsTypical Recall@10Best Production Use Case*FP32 (Baseline)4 B5.72 GB99%+Small datasets (<250K) where RAM is cheapFP16 / BF162 B (2×)2.86 GB99%+Drop-in pgvector halfvec defaultScalar INT81 B (4×)1.43 GB97%–99% (with rescore)Default choice* for 1M–20M SaaS RAG*Binary (1-bit)*0.125 B (32×)0.18 GB92%–96% (with 4× oversample)High-dim (1536d–3072d) & 10M+ scale

Production tip: When using Scalar INT8 or Binary quantization, always enable oversampling + rescoring (e.g., fetch 3× to 4× candidate IDs from the quantized in-RAM index, then rescore those 30–40 candidates against exact FP32 vectors from NVMe). You keep >98% of FP32 retrieval quality at a fraction of the RAM bill.

3. Qdrant vs. pgvector vs. Serverless Pinecone: Which Architecture Fits?

  • PostgreSQL + pgvector (0.7+ with halfvec): Best when you are under ~2–5M vectors and already run Postgres. You get transactional consistency between your relational permissions/metadata and embeddings with zero extra infrastructure. Watch out for HNSW index build memory (maintenance_work_mem) and vacuum bloat.

  • Self-Hosted Qdrant / Milvus on Cloud NVMe VMs: Best cost-performance ratio from 1M to 50M+ vectors. Native INT8/Binary quantization with on-disk originals lets a single 16 GB RAM node comfortably serve 10M+ chunks with sub-30ms p99 latency.

  • Serverless Vector DB (Pinecone Serverless / Qdrant Cloud): Best for bursty, low-QPS workloads or teams without dedicated SRE bandwidth. You pay per GB stored plus read/write units instead of idle 24/7 HA nodes—though steady high-QPS traffic becomes cheaper on dedicated VMs.

4. Production Index Templates

For a 1M–10M chunk workload using 1,536-dim embeddings with INT8 scalar quantization in RAM and original vectors on NVMe:

// Qdrant Collection Config (INT8 in RAM + FP32 on disk for rescoring)
{
  "vectors": {
    "size": 1536,
    "distance": "Cosine",
    "on_disk": true
  },
  "quantization_config": {
    "scalar": {
      "type": "int8",
      "quantile": 0.99,
      "always_ram": true
    }
  },
  "hnsw_config": {
    "m": 16,
    "ef_construct": 128
  },
  "replication_factor": 2
}
Enter fullscreen mode Exit fullscreen mode

If you are staying inside PostgreSQL with pgvector 0.7+, cast to halfvec for an instant 2× RAM reduction without losing recall:

-- PostgreSQL pgvector 0.7+ (halfvec HNSW index)
SET maintenance_work_mem = '2GB';

CREATE INDEX CONCURRENTLY idx_rag_chunks_halfvec
ON rag_chunks
USING hnsw ((embedding::halfvec(1536)) halfvec_cosine_ops)
WITH (m = 16, ef_construction = 128);
Enter fullscreen mode Exit fullscreen mode

5. Size Your Own RAG Stack

Use our interactive calculators to budget your entire production AI pipeline end to end:

Originally published at OpsHubs. Found it useful? Buy us a coffee ☕.

Top comments (0)