---
title: Compare HNSW, IVF-PQ and flat search for 100 million chunks. When would you use Postgres or a search engine you already…
url: https://gurkanozkan.ai/learn/questions/applied-llm-rag-09/
markdown: https://gurkanozkan.ai/learn/questions/applied-llm-rag-09.md
kind: question
role: Applied LLM
stage: Technical
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/applied-llm-rag-09.json
robots: noindex
---

# Compare HNSW, IVF-PQ and flat search for 100 million chunks. When would you use Postgres or a search engine you already run instead of a dedicated vector database?

Applied LLM · Technical · Medium

Theme reported publicly: [OpenAI](https://www.aced.io/guides/openai-forward-deployed-engineer-interview)

## Answer

*Model answer, written in a candidate's voice*

### In short

- Flat: exact linear scan, fine up to ~1M vectors, too slow/expensive at 100M
- HNSW: graph-based, high recall at low latency, memory-hungry, awkward deletes
- IVF-PQ: search nprobe clusters; PQ compresses vectors with recall loss, mitigated by rescoring
- Memory maths: 100M x 1,024 dims x 4B ~ 400GB raw, so quantise, use PQ or shard
- Filtered search: pre- vs post-filtering matters for ACLs
- Postgres/existing search engine when scale is moderate and joins, transactions and existing ops matter
- Tune efSearch/nprobe against measured recall and latency, not defaults

### In full

At 100M chunks, flat search is out: it is an exact linear scan that is fine up to roughly a million vectors but too slow and expensive at this scale. HNSW gives high recall at low latency via a graph, but it is memory-hungry and deletes are awkward; IVF-PQ partitions into clusters and probes nprobe of them, with PQ compressing vectors at the cost of recall, which you recover by rescoring candidates with exact vectors. The memory maths is the real driver: 100M x 1,024 dims x 4 bytes is about 400GB raw, so you need quantisation, PQ or sharding regardless of index choice. Filtered search matters for ACLs: pre-filtering restricts the candidate set before search while post-filtering searches then filters, and the wrong choice can hurt recall or latency. I would use Postgres or a search engine I already run when scale is moderate and joins, transactions and existing operations matter; a dedicated vector database earns its place when you need high recall at low latency at this scale and can own the extra operations. Either way, tune efSearch or nprobe against measured recall and latency, not defaults.

*Checked against sources by an independent AI reviewer.*

## What a strong answer covers

- Flat: exact, linear scan, fine up to ~1M vectors; HNSW: graph, high recall at low latency, memory-hungry, awkward deletes; IVF: search nprobe clusters; PQ compresses vectors with recall loss, mitigated by rescoring
- Memory maths: 100M × 1,024 dims × 4 B ≈ 400 GB raw → quantise, use PQ or shard
- Filtered search behaviour (pre- vs post-filtering) matters for ACLs
- Existing Postgres/OpenSearch when scale is moderate and joins, transactions and existing operations matter
- Tunes efSearch/nprobe against measured recall and latency

## Common mistakes

- Picking a store by popularity without memory maths
- ignoring filtered-search recall

## Topic guides

- [ML and LLM system design](https://gurkanozkan.ai/learn/topics/system-design.md)
- [Retrieval-augmented generation](https://gurkanozkan.ai/learn/topics/rag.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
