Merge shard answers under an explicit exactness contract
Prove when local top-k suffices, then identify approximation, replica, and deduplication cases that break the proof.
On this page
The question for today
What you’ll understand
- Prove the disjoint-shard exact top-k merge rule.
- Trace missing-shard and duplicate-replica effects.
- Separate local ANN recall from distributed merge correctness.
Partitioning a vector corpus across machines creates two different kinds of correctness obligations. Each shard must retrieve good local candidates, and the coordinator must merge them into the requested global result. A flawless merge cannot recover a true neighbor omitted by local approximate search. Conversely, even exact local searches can produce an incorrect global answer if a shard is missing, replicas are counted twice, or scores use incompatible geometries. Write the distributed ranking contract before tuning fan-out and parallelism, so completeness failures do not disappear behind a fast partial response.
Why exact local top-k is enough in the simple case
Assume shards partition the eligible logical documents without overlap. All use the same deterministic total order: first the exact query score, then a global stable-ID tie key. If a document lies below position k on its own shard, that shard alone contains at least k documents ahead of it, so it cannot appear in the global top k. Therefore the union of exact local top k sets contains every global winner, and an exact coordinator sort can select the answer.
The shared total order matters at ties. If each shard breaks equal distances differently from the coordinator, a globally preferred tied ID might be omitted locally. Score compatibility matters too: independently trained compressed codebooks can introduce different approximation biases. Comparing their reported approximate distances does not restore the original exact order. Exact reranking on common original vectors can make candidate scores comparable, but the local candidate sets must still contain the global winners.
Replicas duplicate work, not population
A replica holds another copy of a shard’s documents to improve availability or serving capacity. It does not add new eligible IDs. Select a replica for each shard or deduplicate by logical ID and version before the final ranking. Overlapping partitions can also merge correctly when each local top-k ranks unique logical IDs under that same total order. Trouble appears when multiple physical versions or duplicate entries consume slots within a local result before deduplication: top-k over entries is then not top-k over logical documents. A larger local candidate count alone is a heuristic.
A missing shard changes the answer domain. Returning the best items from responding shards may be a useful degraded response, but it cannot be labeled exact global top-k without additional information proving the absent shard contains no better item. Record coverage explicitly. A replica’s stale snapshot can also resurrect old versions or miss recent documents, so shard coverage and snapshot coverage must both be checked before treating a merged result as complete.
Approximation remains after distribution
With local ANN search, the coordinator can compute an exact top k of the received candidates while still missing the corpus’s true top k. Distinguish those statements in metrics and API documentation. Oversampling local candidates and exact reranking can improve recall, but there is no universal multiplier that repairs every graph miss or unprobed IVF cell. Benchmark the entire fan-out, filtering, deduplication, and merge path against a frozen exact reference.
Latency is also a distributed property: waiting for all required shards makes the slowest necessary response relevant, while speculative replica requests add resource cost. Measure the result deadline, timeout policy, coverage fraction, and coordinator work, rather than summing isolated single-shard timings. Keep shard count fixed when isolating local search parameters; changing partitioning alters both candidate distributions and network fan-out, so it is a different system configuration that needs fresh evaluation.
Work it through
Two exact candidates from each shard contain the global two
Use lower-is-better exact distances and k=2. Disjoint shard 1 holds A:1, B:4, C:8; shard 2 holds D:2, E:3, F:9. Both use ascending-ID ties and the same snapshot. Each returns its exact local top two.
Shard 1 returns A:1 and B:4; shard 2 returns D:2 and E:3. The candidate union contains four distinct IDs. C and F are omitted because each already has two better documents on its own shard.
Merge by the common exact order: A:1, D:2, E:3, B:4. The global top two are A and D. No discarded local document can enter these first two positions under the proof’s assumptions.
If shard 2 is unavailable, the responding-shard answer becomes A and B. Compared with the full-snapshot ground truth {A,D}, its recall@2 is 1/2. Calling that answer exact global top two would conceal the missing domain.
Local exact top-k plus a correct complete merge is sufficient for disjoint shards. The same sorting code cannot establish global completeness when one required shard is missing.
The living notebook
Explore the model
Interactive lab · reliability
Copies and unavailable copies are separate counts
Reset, set Replica count n to 3 and Unavailable replicas k to 1. Predict 2 available copies and majority threshold 2 before Step. Reset, set n to 3 and k to 2, predict 1 available copy and majority threshold 2 before Step. This arithmetic availability model does not simulate shard coverage, ANN recall, snapshot agreement, or a quorum protocol.
- Available replicas
- 4 of 5
- Majority needed
- 3
- Majority available?
- Yes
A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forAvailable replica counts alone do not establish that every logical shard was searched at the correct snapshot.
Pause & reason
Check your understanding
Your turn
Try it yourself
Three disjoint shards each return at most 4 unique candidates. Each encoded result entry is 16 bytes. Bound candidate-union size and entry payload. Does receiving that full payload prove exact global recall?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count S×k entries, then distinguish the transport count from search completeness.
Compare with the solution
The union has at most 3×4=12 IDs, and full entry payload is 12×16=192 bytes before framing, retries, or reranking vectors. Receiving all 192 bytes proves neither exact local retrieval nor common-snapshot agreement. Exact global top four additionally needs the proof’s ordering, coverage, and exact-local-search conditions; local ANN can fill every slot while missing a true winner.
Keep the idea
Take it with you
- Exact local top-k suffices for disjoint complete shards with one total order.
- Replicas are duplicate copies, not additional logical documents.
- An exact merge of ANN candidates can still be globally approximate.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.