Prompt
I'm building a vector index for millions of records, what architecture should I use
Latest observation
For millions of records, the right architecture is usually a distributed vector retrieval layer with metadata filtering, not a single monolithic index.
Recommended architecture
1) Split storage into two layers
A. Vector index
- Stores embeddings and supports ANN search
- Built with something like:
- FAISS for self-managed, high-performance setups
- Milvus, Weaviate, Pinecone, Qdrant for managed/distributed systems
- pgvector only if scale/performance needs are moderate
B. Source-of-truth metadata store
- Keep full records in:
- Postgres / MySQL
- DynamoDB / Cassandra
- Elasticsearch/OpenSearch for keyword search
- Store only:
- record ID
- embedding
- minimal searchable metadata in the vector system
This keeps the vector DB lean and fast.
2) Use sharding / partitioning
For millions of vectors, use horizontal partitioning:
- Split by tenant, category, time range, region, or hash of ID
- Benefits:
- faster queries
- easier reindexing
- lower memory pressure
- better multi-tenancy isolation
If you have a natural filter like tenant_id, product_type, or language, partition on that.
3) Choose an ANN index type that fits your workload
If you need high recall and fast search:
- HNSW
- great latency/recall
- memory heavy
- excellent for read-heavy workloads
If you need lower memory and large scale:
- IVF / IVF-PQ
- more compact
- good for tens/hundreds of millions
- slightly more tuning required
If vectors are static and performance is critical:
- DiskANN-style approaches
- very scalable
- good for very large corpora
- often used in production search systems
Rule of thumb:
- Up to a few million: HNSW is often easiest
- Tens of millions+: consider IVF-PQ or DiskANN-like systems
- If you want operational simplicity: managed vector DB
4) Support hybrid retrieval
Use both:
- vector search
- keyword / lexical search
Then combine results with:
- reranking
- score fusion
- business rules
This improves quality a lot, especially for exact terms, names, IDs, and rare entities.
5) Add a reranking stage
Typical retrieval pipeline:
- Filter by metadata
- ANN vector search top 50–200
- Optional keyword search
- Merge candidates
- Rerank with:
- cross-encoder
- LLM reranker
- learning-to-rank model
This gives better quality than relying only on nearest neighbors.
A practical production setup
Option A: Managed and simple
- Vector DB: Pinecone / Weaviate / Qdrant Cloud / Milvus managed
- Metadata DB: Postgres
- Object store: S3/GCS for raw records
- Pipeline: Kafka / Airflow / Celery for ingestion
Best if you want less ops burden.
Option B: Self-managed scalable
- Vector service: Milvus or Qdrant cluster
- Metadata: Postgres + Redis cache
- Keyword search: OpenSearch
- Batch indexing: Spark / Ray / Python workers
- Embedding generation: GPU inference service
Best if you need control and lower long-term cost.
Option C: Search-first enterprise
- OpenSearch/Elasticsearch for lexical + vector
- Postgres for source data
- Separate embedding pipeline
- Reranker service
Good when text search is as important as vector search.
Important design decisions
Embedding dimension
Higher dimension = better semantic power, more memory/cost.
- Common sizes: 384, 768, 1024, 1536
Update pattern
- Static corpus: optimize heavily for search
- Frequent updates: choose an index that supports incremental inserts well, like HNSW or a managed DB
Filtering
If you need frequent metadata filters, make sure your vector system supports:
- pre-filtering
- efficient filtering on structured fields
This matters a lot at scale.
Memory estimate
Roughly:
#vectors × dimension × bytes per value- float32 uses 4 bytes/value
Example:
- 10 million vectors
- 768 dims
- float32
That’s about:
- 10,000,000 × 768 × 4 ≈ 30.7 GB just for raw vectors
- plus index overhead, often significantly more
So memory planning is critical.
My default recommendation
If you’re building for millions of records and want a safe default:
- Use Qdrant, Milvus, or Pinecone
- Store IDs + embeddings + metadata
- Keep full records in Postgres/Object Storage
- Use sharding by tenant/category
- Use HNSW if memory is acceptable
- Add hybrid search + reranking
If you want, I can give you a recommendation based on:
- your vector count
- update frequency
- whether you need metadata filters
- your latency target
- whether you prefer managed vs self-hosted