What actually happens when you ask a vector database for “the ten most similar items” and it answers in milliseconds? Behind that flicker of a response sits one of the more interesting engineering puzzles in modern software: how do you find near-matches in millions of high-dimensional vectors without comparing your query to every single one? The answer shapes everything about how these systems are built, tuned, and paid for.
This article walks through vector database architecture from the ground up: the indexes that make fast search possible, the storage and query layers that hold everything together, the trade-offs engineers fight over, and the mistakes that trip up teams building their first semantic search or retrieval system.
Why Exact Search Doesn’t Scale
A vector database stores embeddings: long lists of numbers (often 384 to 1,536 dimensions) that represent text, images, audio, or anything else a model can encode. Similarity is measured with a distance function, usually cosine similarity, dot product, or Euclidean distance. Finding the closest vectors exactly means computing distance to every stored vector, a full scan. For a few thousand items that’s fine. For tens of millions, it becomes unusable at interactive latency.
So the core architectural decision in nearly every vector database is to use approximate nearest neighbor (ANN) search instead. ANN indexes trade a small amount of accuracy, called recall, for enormous speed gains. The system might return 97 of the true 100 nearest neighbors, but it does so in a fraction of the time. That trade-off is the beating heart of the entire category.
The Index Layer: Where the Magic Happens

The index is the component that makes fast similarity search possible, and the choice of index drives most other design decisions.
HNSW: The Graph That Everyone Uses
Hierarchical Navigable Small World (HNSW) is the dominant index in production systems. It builds a multi-layer proximity graph where each vector links to nearby vectors; upper layers are sparse and act like highway networks, while lower layers are dense and allow fine-grained navigation. A query enters at the top, greedily hops toward the closest node, then descends layer by layer.
The original HNSW paper by Malkov and Yashunin reports logarithmic search complexity scaling and strong recall on benchmark datasets, which explains its popularity. If you want the mechanics in detail, the HNSW algorithm paper on arXiv is the canonical reference. Two parameters govern behavior: M, the number of links per node, and efSearch, the size of the candidate list during search. Raise efSearch and recall improves while latency climbs. This is why any performance claim about a vector database is meaningless without stated parameters.
IVF and Product Quantization: Squeezing Memory
HNSW is memory-hungry because it keeps the full graph and often the full vectors in RAM. For very large collections, systems often use inverted file (IVF) partitioning, which clusters vectors and searches only the nearest clusters, combined with product quantization (PQ), which compresses vectors into short codes. PQ was introduced by Jégou, Douze, and Schmid in IEEE TPAMI in 2011, and it can shrink memory use by an order of magnitude at the cost of some accuracy.
Flat Indexes: The Honest Baseline
A flat index does exact search. It’s slow on large datasets but perfectly accurate, and it’s the right choice for small collections or as a ground truth when measuring recall of an ANN index.
| Index type | Memory use | Speed | Accuracy | Best fit |
|---|---|---|---|---|
| Flat (exact) | High | Slow at scale | Perfect | Small sets, ground truth |
| HNSW | High | Very fast | High, tunable | Low-latency production search |
| IVF-PQ | Low | Fast | Moderate | Very large, memory-constrained |
| Disk-based ANN | Moderate | Moderate | Tunable | Cost-sensitive large archives |
Storage, Durability, and the Write Path
An index alone is not a database. Real systems need durability, so writes typically land in a write-ahead log or object storage before being indexed. Many architectures follow a pattern borrowed from search engines: incoming vectors accumulate in an in-memory buffer, get flushed to immutable segments, and background processes merge those segments and rebuild or update indexes.
This matters practically because index builds are expensive. HNSW insertion is incremental but graph quality can degrade with heavy deletion churn, and IVF indexes usually need periodic retraining as data drifts. Teams that treat a vector database as a simple key-value store often get surprised when a bulk reindex takes hours or memory spikes during compaction.
Modern cloud-native systems increasingly disaggregate storage, index, and compute, keeping vectors in object storage while query nodes hold hot indexes. That pattern mirrors broader trends in cloud infrastructure and architecture, where separating compute from storage improves elasticity and cost control.
The Query Layer: Coordination, Filtering, and Reranking
The query coordinator receives a request, embeds it (or accepts a precomputed vector), routes it to the right shard, gathers candidate results, and merges them. Two details separate good implementations from naive ones.
First, sharding and replication. Large collections are split across shards, and a top-k query must fan out to every shard and merge results, which means tail latency is governed by the slowest shard. Replicas improve throughput and availability but multiply memory cost.
Second, filtered search, which is genuinely hard. Users rarely want pure vector similarity; they want “similar items where category = shoes and price < 100." Combining metadata filters with ANN traversal can wreck recall or performance depending on approach. Pre-filtering narrows the candidate set before graph traversal but can disconnect the graph; post-filtering runs ANN first and discards non-matching results, which may return too few items. Filter-aware traversal is the sophisticated middle ground, and it remains an active design area rather than a solved problem.
Many production pipelines also rerank: ANN retrieves a generous candidate pool, then a more expensive exact scorer or cross-encoder reorders the top results. This two-stage pattern is common in retrieval-augmented generation and is central to AI inference architecture, where retrieval latency and model latency compete for the same budget.
Build Versus Buy: Libraries, Extensions, and Dedicated Systems
The vector search landscape has three rough tiers, and choosing among them is an architectural decision as much as a purchasing one.
Libraries like FAISS, released by Facebook AI Research in 2017, provide similarity search and clustering primitives. The FAISS similarity search paper explains the design. FAISS is not a database: it has no durability, replication, or query language, but it underpins many systems and is excellent for offline experiments.
Extensions bolt vector search onto existing databases. pgvector, first released in 2021, adds vector types and ANN indexes to PostgreSQL. The appeal is obvious: transactions, joins, backups, and access control already exist. The trade-off is that vector workloads compete with transactional ones for the same resources.
Dedicated vector databases such as Milvus, Pinecone, Weaviate, and Qdrant crystallized as a category roughly between 2021 and 2023. They offer purpose-built indexing, horizontal scaling, and filtering, at the cost of another system to operate.
| Option | Operational burden | Scale ceiling | When it wins |
|---|---|---|---|
| Library (FAISS) | High (you build it) | High with effort | Research, batch jobs, custom systems |
| Extension (pgvector) | Low | Moderate | Existing Postgres, modest scale |
| Dedicated database | Moderate | High | Large, latency-sensitive, filtered search |
A common mistake is reaching for a dedicated system on day one when a few hundred thousand vectors would fit comfortably in Postgres. The reverse mistake, stretching an extension past its comfort zone, usually shows up as query latency spikes during index rebuilds.
Measuring Performance Without Fooling Yourself
Benchmarks in this space are contested, and for good reason. The ANN-Benchmarks project, described in the ANN-Benchmarks methodology paper, compares recall against queries per second, but results depend heavily on hardware, dataset dimensionality, and tuning effort. A vendor can look excellent by tuning one system for weeks and leaving another at defaults.
Practical guidance: always measure recall@k against a flat index on your own data, at your own filter selectivity, with your own hardware. Record efSearch and M alongside every latency number. And test with filters applied, because filtered recall is where many systems quietly fall apart.
Operational Realities and Common Mistakes
A few patterns show up again and again in real deployments.
Ignoring the embedding model lifecycle. If you upgrade the embedding model, old vectors become incompatible with new queries. You need versioned collections and a migration plan. Teams forget this until a model upgrade forces a full reindex under deadline.
Underestimating memory. HNSW with 1,536-dimensional float32 vectors and M=32 can consume several kilobytes per vector before overhead. Ten million vectors can mean tens of gigabytes of RAM. Quantization or disk-based indexes are not optional at that point.
Skipping recovery drills. A vector index is often rebuildable from source data, but rebuilding ten million vectors can take hours. Knowing your recovery time matters; a recovery drill for a managed database is a useful template for testing that path before an incident does it for you.
Forgetting tenant isolation. In multi-tenant systems, a filter bug can leak another customer’s documents through semantic search. Designing tenant data separation in an enterprise assistant at the collection or namespace level, rather than relying solely on query filters, is the safer pattern.
Overlooking egress and data transfer. Replicating large vector collections across regions or pulling indexes into training jobs generates real costs. Tracking cloud data transfer costs early prevents unpleasant surprises.
Finally, portability is immature. There is no widely adopted standard query language for vector search; SQL extensions and vendor APIs dominate. That lock-in risk belongs in the architecture conversation, not the procurement footnote. For teams building broader systems around retrieval, the principles in enterprise AI systems and architecture and AI cloud architecture help frame where the vector layer fits.
Conclusion
Vector database architecture comes down to a chain of deliberate trade-offs: approximate indexes for speed, quantization for memory, sharding for scale, and filtering strategies for relevance. HNSW dominates because it balances recall and latency well, but it is not free, and the surrounding storage, query, and operational layers determine whether a system holds up under real workloads. The teams that succeed measure recall on their own data, plan for model migrations, and treat memory and filtering as first-class design constraints rather than afterthoughts. Get those right, and the millisecond answer to “what’s most similar?” stops looking like magic and starts looking like good engineering.
What is the difference between a vector index and a vector database?
A vector index is a data structure, such as HNSW or IVF-PQ, that speeds up similarity search. A vector database wraps one or more indexes with durability, replication, sharding, metadata filtering, access control, and a query API. FAISS is an index library; Milvus or Qdrant are full databases.
Why do vector databases use approximate search instead of exact search?
Exact search compares a query against every stored vector, which becomes too slow at millions of items. Approximate nearest neighbor search returns most of the true nearest neighbors far faster by navigating an index structure. The accuracy gap, called recall, is tunable through parameters like efSearch.
What does HNSW stand for and how does it work?
HNSW stands for Hierarchical Navigable Small World. It builds a multi-layer graph of vectors, with sparse upper layers for fast long-distance hops and dense lower layers for precise local search. Queries descend layer by layer, following links toward closer vectors until they reach a local minimum.
What is filtered vector search and why is it hard?
Filtered search combines metadata conditions, like category or date, with vector similarity. The difficulty is that filters can shrink the candidate pool so much that graph traversal loses connectivity, or post-filtering may return too few results. Approaches include pre-filtering, post-filtering, and filter-aware traversal, and quality varies widely between systems.
How much memory does a vector database need?
It depends on dimensions, vector count, index type, and quantization. Full-precision HNSW typically needs several kilobytes per vector including graph overhead, so ten million 1,536-dimensional vectors can require tens of gigabytes of RAM. Product quantization or disk-based indexes can cut that substantially at some cost to recall.
Can I just use PostgreSQL instead of a dedicated vector database?
Often yes, especially at moderate scale. The pgvector extension adds vector types and ANN indexes to PostgreSQL, letting you keep transactions, joins, and backups in one system. Dedicated databases usually win when collections grow large, latency requirements tighten, or filtered search at scale becomes central to the product.







