A vector store places vectors on shards by nearest cluster centroid and routes each query to the closest few shards: what recall does that risk, and how do you bound it?
answer
- neighbours across the boundary
- silent, not an error
- ground truth from full fan-out
- distance to centroid minus radius
- drift since the clustering
basics
~20 sNeighbours near a cluster boundary, and queries far from every centroid, land on shards the router skipped, so recall drops without any error. Bound it by measuring against full fan-out, probing more shards, duplicating boundary vectors and re-clustering when data drifts.
solid answer
~50 sCluster-routed placement trains centroids (typically with k-means), puts each vector on the shard of its nearest centroid, and sends a query only to the few shards whose centroids are closest. The loss is silent: results look normal but miss neighbours that sit just across a boundary, queries that fall between clusters, and data that drifted after the centroids were trained. To bound it, measure recall on sampled real queries against an exhaustive search over every shard, then raise the probe count until recall meets the target. Where the distance is a true metric, a shard whose centroid distance minus its radius exceeds the current k-th best distance can be skipped with no loss. Duplicating boundary vectors onto two shards buys recall for memory. Watch shard sizes and recall over time, because re-clustering means moving vectors and rebuilding shard indexes.
code
pseudocode · 12 linesshards = sort all_shards by distance(q, s.centroid), nearest first
results = empty top-k list
probed = 0
for s in shards:
bound = distance(q, s.centroid) - s.radius # metric distances only
if results.is_full() and bound > results.kth_distance():
continue # safe skip, no recall loss
if probed == max_probe:
break # budget cap, recall not guaranteed
results.merge(search(s, q, k))
probed = probed + 1
return resultsgo deeper
Recall that cluster-routed placement searches only the shards nearest the query, so a true neighbour on a skipped shard is simply missing.
Explain the four loss sources: boundary neighbours, queries between clusters, drift and size balancing, and why none of them raises an error.
Show the measurement: sampled real queries, exhaustive ground truth, recall per probe count and per segment, repeated on a schedule. Then pick levers by cost.
Decide whether a corpus that changes this fast should be cluster-routed at all, given that every re-clustering is a move-and-rebuild of shard indexes.
## How cluster-routed placement works A vector store that places by **vector cluster** first trains a set of **centroids**, one per shard (or a few per shard), usually with k-means over a sample of the data. Each vector is stored on the shard of its nearest centroid. At query time the router computes the query's distance to every centroid and searches only the closest few shards, often called the **probe count**. It is the same idea an inverted-file index uses inside one machine, applied one level up across machines; the index-level version is covered with partitioned indexes. The appeal is fan-out: a query that would have searched 64 shards searches 4. The risk is that the router decides what to skip from centroids alone, before it has seen a single real candidate. ## Where recall goes Recall here means the fraction of the true top-k neighbours that the routed search returns. Cluster routing loses it in four ways: - **Boundary neighbours.** A query near the edge of cluster A has true neighbours just over the line in cluster B. If B is not among the probed shards, those neighbours are gone. - **Queries between clusters.** A query roughly equidistant from many centroids has its neighbours spread across several shards; a small probe count catches only some. - **Drift.** Centroids are trained at one moment. New content (a new product line, a new language) is forced onto the nearest existing centroid, clusters stretch, and boundaries cut through dense regions. - **Imbalance.** To keep shards an even size, placement may push vectors to a second-nearest centroid, which breaks the "nearest centroid holds you" assumption the router relies on. None of these raises an error. The results look like results. That is why the loss must be **measured**. ## Measuring it 1. Sample real queries from production traffic, not synthetic ones; the hard cases are where real queries fall. 2. For each, compute ground truth with an **exhaustive** search across every shard (or brute force over the vectors), not with the routed search itself. 3. Compute recall at k for several probe counts, overall and per segment (per tenant, per language, per content type), because averages hide the clusters that suffer. 4. Repeat on a schedule, because drift moves the number without any code changing. ## Bounding it | Lever | What it does | Cost | |---|---|---| | Raise the probe count | Searches more nearby shards | Fan-out and latency grow | | Adaptive probing | Probes more when centroid distances are close | Variable cost per query | | Safe-skip rule | Skips a shard only when no vector in it can beat the current k-th result | Needs a metric distance; rarely fires in high dimensions | | Boundary duplication | Stores vectors near a boundary on both shards | Memory and write cost; duplicates to drop at merge; deletes reach both copies | | Re-clustering | Retrains centroids on current data | Moves vectors, rebuilds affected shard indexes | The **safe-skip rule** follows from the triangle inequality. If a shard's **radius** is the largest distance from its centroid to any of its vectors, then no vector in that shard can be closer to the query than `distance(q, centroid) - radius`. Once the router holds k results and that lower bound exceeds the k-th best distance, the shard cannot improve the answer. This holds for metric distances such as L2, and for cosine similarity when vectors are normalised and the bound is computed in L2 distance, which ranks identically there; it does not hold for raw inner-product scores. In high dimensions radii tend to be large, so the rule prunes less than hoped, and the probe budget is what actually caps cost. ## The routing loop, with both bounds The pseudocode below is illustrative; the merging of per-shard results is reduced to one call. ```pseudocode shards = sort all_shards by distance(q, s.centroid), nearest first results = empty top-k list probed = 0 for s in shards: bound = distance(q, s.centroid) - s.radius # no vector in s is closer (metric distances only) if results.is_full() and bound > results.kth_distance(): continue # safe skip: s cannot improve the top-k if probed == max_probe: break # budget cap: recall no longer guaranteed results.merge(search(s, q, k)) probed = probed + 1 return results ``` The loop uses `continue` rather than `break` on a safe skip because shards are sorted by centroid distance, not by bound: a later shard with a small radius can still have a low bound. ## Living with it Cluster routing suits large, slowly changing collections where most queries fall in dense regions and a recall target a little below exhaustive is acceptable. It suits poorly a corpus whose distribution changes weekly, because every re-clustering moves vectors between shards, and moving a vector into a graph-indexed shard means rebuilding that shard's index.
- Why does recall from cluster routing decay over months when nothing in the code has changed?Because the centroids describe the data as it was when they were trained. New content is assigned to the nearest old centroid, clusters stretch, radii grow and boundaries cut through dense regions, so more true neighbours land on unprobed shards. Re-clustering fixes it, but it moves vectors between shards and so rebuilds those shards' indexes.
- What does duplicating boundary vectors onto two shards cost?Memory and write work in proportion to the fraction duplicated, results that must be de-duplicated by record ID before they are returned, and deletes and updates that must reach every copy. It is worth it when a measured recall gap sits at boundaries and raising the probe count would cost more.
- Why can the safe-skip rule not be used with raw inner-product scores?The rule relies on the triangle inequality, which holds for metric distances such as L2. Inner product is not a metric: a vector far from a centroid can still score highest if its norm is large, so no lower bound follows from distance to the centroid. Normalising vectors and computing the bound in L2 distance, which then ranks like cosine, restores it.
- Routing to the nearest centroid shard loses nothing if each shard's index is exact.
- Recall loss from skipped shards shows up as errors or empty results.
- Comparing routed results with a repeat of the routed query measures recall.
- Centroids trained once stay valid as the corpus grows.
- The distance-minus-radius skip rule works for raw inner-product scores.