Sub topic 14
Updates, deletes, sharding and other operational concerns
This chapter assumes you know how HNSW and IVF indexes work, what recall means, and what a vector database adds beyond an index. Here we look at what happens after the first load: data changes, grows, and has to survive failures.
Why updates are harder than in a relational index
A B-tree handles an insert or delete cheaply. Approximate indexes do not.
- HNSW links each new vector to neighbors in a graph. Inserts work, but each one costs a graph search plus edge updates.
- Deletes in HNSW are usually soft. The node is marked deleted but stays in the graph so paths through it still work. Many deletions leave dead nodes that waste memory and slow searches.
- IVF assigns each vector to the nearest centroid. Inserts are cheap, but the centroids were trained on the old data. If the data distribution drifts, clusters become unbalanced and recall drops.
- Product quantization codebooks have the same drift problem as IVF centroids.
An update to a vector is normally a delete followed by an insert. Updating only metadata does not touch the index in most systems.
Segments, compaction and rebuilds
Many databases avoid editing a large index in place. They write new data into a small mutable segment, keep older segments immutable, and search all of them, then merge the results.
Compaction removes soft-deleted vectors and rebuilds a clean index. It uses CPU and I/O, so schedule it away from peak traffic. Many small segments mean many small searches per query, which raises latency until compaction catches up.
Plan a full rebuild when you change the embedding model. Vectors from different models are not comparable, even if they have the same dimension.
Sharding and replication
One machine eventually runs out of memory or query throughput. Two techniques address this, and they solve different problems.
| Technique | Solves | Cost |
|---|---|---|
| Sharding (split data across nodes) | Data too large for one node | Each query must reach every shard |
| Replication (copy data across nodes) | Query throughput and availability | Extra memory and write fan-out |
With sharding, a query is sent to all shards. Each returns its local top k, and a coordinator merges them into a global top k. Latency is set by the slowest shard, so one overloaded node hurts every query. Sharding by a key such as tenant ID lets you route a query to one shard, but it can create hot shards.
Memory, consistency and backups
- Memory. HNSW graphs are normally held in RAM. Estimate roughly
n * d * 4bytes for float32 vectors, plus graph links. Quantization or disk-based indexes reduce this at some cost in recall. - Consistency. Many systems are eventually consistent. A vector you just wrote may not appear in search for a short time, because it is not yet in the searchable index. Test this if your application reads its own writes.
- Backups. Snapshot the vectors and metadata, not just the index. The index can be rebuilt from vectors, but the vectors cannot be rebuilt from the index if it is quantized.
- Monitoring. Track recall against a sampled exact baseline, p95 and p99 latency, deleted-vector ratio, segment count and memory use.
Exercise
A collection of 50 million vectors no longer fits in one node's RAM, and queries per second are fine. Would you add shards or replicas, and why?
Show answer
Add shards. The problem is data size, not throughput. Replicas would copy the full dataset onto each node, which still does not fit. Sharding splits the data so each node holds a part, at the cost of querying every shard and merging results.
Exercise
Your HNSW index has had many deletes and searches have become slower with no change in query volume. What is the likely cause and fix?
Show answer
Soft-deleted nodes remain in the graph and are still traversed, wasting work and memory. Run compaction or rebuild the index to remove them.