#5683·paradedb

SuperKMeans IVF: medoid centroids via snap-to-nearest-vector

Author: rebasedmingCreated Jul 24, 2026Updated Sep 28, 2026
Labelsfeaturepriority-highsuperkmeansvectors

Summary

Add medoid centroids (snap-to-nearest training vector) to SuperKMeans, so centroids are actual training vectors and can be referenced instead of stored as a whole new vector set. Third of three SuperKMeans features tracked for IVF centroid training in the vector-paradedb tantivy branch (see also balanced clustering and hierarchical tree exposure).

Feasibility: FEASIBLE, TRIVIAL (in SuperKMeans). The by-reference storage saving is tantivy format work and deferred.

SuperKMeans side

The snap is one call to existing machinery with the arguments swapped:

Assign(/*vectors=*/centroids, /*centroids=*/data, k, n)

returns, per centroid, the index of its nearest training vector — brute force via FindNearestNeighbor (batch_computers.h:104), no code changes. Cost is O(k·n·d) via BLAS, negligible next to training.

Caveats

  • Initialization is already Forgy (real vectors) but centroids drift to means, so the snap is genuinely needed.
  • The nearest vector may not belong to the centroid's own cluster — acceptable for routing; a true per-cluster medoid would need an inverted cluster→members index (the pattern already exists at hierarchical_superkmeans.h:271-286).
  • For Cosine, snapped centroids are already unit vectors, so tantivy's re-normalization (plugin.rs:620-633) becomes a no-op.

Tantivy side (deferred — the storage saving)

.centroids slot [0] currently stores raw k×d bytes (index.rs:63-88). By-reference storage means:

  • storing u32 row references,
  • resolving centroid vectors through the .vec rows,
  • extending IvfCentroids (training.rs:75-90) with an IDs variant.

Note the training set is a strided subsample (plugin.rs:242-269), so the medoid's sample index must be mapped back to its doc/row id — that mapping exists in the sampling walk.

Effort

Trivial (SuperKMeans-side: one reversed Assign call). Moderate (tantivy-side: by-reference format) — later.