RAG vs. Long-Context & Vector DB Memory Calculator
Estimate HNSW index RAM across FP32, INT8 scalar, and Binary quantization — and compare monthly API spend for RAG vs. prefix-cached long context.
1. Vector Database & HNSW Index Sizing
~4× smaller RAM, <1% recall drop with oversampling
2. RAG vs. Long-Context Monthly Spend
Estimated HNSW Index RAM
1.0 GB
Vectors: 0.8 GB · Graph: 0.1 GB
RAG Monthly Token Cost
$2,300/mo
Retrieving top-8 chunks per query
Long-Context Monthly Cost
$28,500/mo
RAG is 12.4× cheaper on input tokens
Recommended Vector Architecture
pgvector (Postgres HNSW)
Under ~1M–5M vectors, staying inside Postgres eliminates dual-write sync bugs and extra ops.
Machine Learning at Scale Newsletter · 13k+ ML Engineers
Get weekly retrieval, RAG, and production ML deep dives
How Airbnb, LinkedIn, Spotify, and Meta engineer billion-scale retrieval, hybrid search, and AI agents in production — free every week on Substack.
Scaling a production RAG, search, or recommendation pipeline and want an outside review? Explore ML Consulting & Architecture Reviews →
Companion RAG & Vector Search Guides
Vector Databases Compared: Pinecone, Qdrant & pgvector
HNSW memory math, filtered latency, and when Postgres is enough.
Long Context LLMs: RoPE Scaling, YaRN & RAG Trade-Offs
When 128K–1M windows win and when RAG still beats them.
RAG Systems at Scale (Free 14-Chapter Book)
Chunking, hybrid retrieval, reranking, GraphRAG, and evaluation.
Frequently Asked Questions
How much RAM does an HNSW vector index need?
Approximate HNSW RAM equals num_vectors × (dimensions × bytes_per_dim + M × 8 bytes) × 1.2 overhead. For 1M vectors at 1536 dimensions, FP32 requires ~7.6 GB RAM while INT8 scalar quantization shrinks it to ~2.0 GB with minimal recall loss.
When is RAG cheaper than 128K–1M long-context LLMs?
Even with a 70–80% prompt caching hit rate, sending 100K+ tokens per query typically costs 5–20× more in input tokens (and adds prefill latency) than retrieving top-8 chunks via RAG. Use long context when reasoning requires reading an entire document or codebase end-to-end.
When should I switch from pgvector to Qdrant or Pinecone?
Keep pgvector if you already run Postgres and have under ~1M–5M vectors so you avoid dual-write sync bugs. Move to Qdrant, Weaviate, or Pinecone once filtered HNSW latency, multi-tenancy, or RAM scaling beyond 5M–10M vectors becomes a bottleneck.