Centroid Vector Index
Centroid sharding groups indexed vectors by an outer routing model within each
row-ID range. Spark and PyPaimon support this layout for ivf-flat, ivf-pq,
ivf-sq, ivf-rq, and diskann.
Build in Spark
Use Spark to build centroid indexes on Data Evolution append tables
without a primary key. Enable row tracking and Data Evolution and set bucket=-1.
Each source row-ID range in a partition gets a router and one shard per populated centroid.
The examples use a 768-dimensional embedding column and two optional scalar
filter columns.
CREATE TABLE db.model_embeddings (
embedding ARRAY<FLOAT>,
tenant_id STRING,
status STRING,
dt STRING
)
PARTITIONED BY (dt)
TBLPROPERTIES (
'bucket' = '-1',
'row-tracking.enabled' = 'true',
'data-evolution.enabled' = 'true',
'fields.embedding.dimension' = '768',
'fields.embedding.metric' = 'cosine'
);
After inserting data, build a cosine IVF-PQ index on one dt partition. Set
<index-type>.sharding=centroid to select centroid sharding. The default is range.
CALL sys.create_global_index(
table => 'db.model_embeddings',
index_column => 'embedding',
index_type => 'ivf-pq',
partitions => 'dt="2026-11-17"',
options => 'ivf-pq.sharding=centroid,ivf-pq.dimension=768,ivf-pq.distance.metric=cosine,ivf-pq.centroid.nlist=256'
);
The build records the layout in the manifest so queries can recognize each row-ID range after a restart or a change to the build options.
A centroid build pins one snapshot. Spark map tasks count non-null vectors in their input splits. Using those counts and the configured training ratio, the driver plans the exact row ordinals that the outer IVF-FLAT trainer would retain. Each map task reads its own splits and shuffles selected vectors by reservoir slot. Within each contiguous range, one task trains a router on those vectors in the original training order. Spark broadcasts that router and shuffles the range's vectors by centroid. Independent ranges can build concurrently within the global build parallelism budget. One call atomically replaces the selected partitions' prior routers, vector shards, and Bitmap files for the vector column and index type.
Search and Tune
Use the standard vector search APIs. For L2 and cosine queries,
centroid.nprobe controls how many outer centroids to select before opening their shards.
Inside each selected shard, ivf.nprobe controls how many local IVF lists to search.
For DiskANN, diskann.l_search controls the graph search.
For inner product, automatic routing searches every outer shard. A high-norm vector in a distant
shard can have the largest inner product. Set an explicit outer width to trade recall for fewer
shard reads. For cosine and L2, Paimon chooses the initial width per row-ID range. The minimum is three for a four-centroid
router, four for an eight-centroid router, and eight otherwise, capped at the number of centroids.
Paimon budgets at least one sixteenth of the shards and four candidate rows per requested result
using the average shard size. A row-ID filter scales the initial width by the inverse of its
selectivity, up to all shards. If there are fewer than top-K results, automatic routing can
probe additional shards. Set centroid.nprobe explicitly to use a fixed outer width.
For unfiltered L2 queries on centroid-sharded ivf-flat and ivf-pq, Paimon can choose both
widths together. With 64 outer centers, an automatic outer width of eight, and top-K from 10
through 100, it checks the four nearest shard descriptors in the manifest. If all four have 64 local lists and at
least 16 × top-K vectors each, it searches those four shards with 16 local probes each.
Other layouts use independent automatic widths. Setting either probe width explicitly, or
setting ivf.max_initial_filter_expansion_factor, also selects independent sizing.
Both single and batched searches open each selected shard once per probe round, including
when queries in the same batch use different widths.
Unindexed rows, including gaps that belong to other partitions, are eligible for
raw search in vector-index.search-mode=detail or chunk. The default fast mode
searches indexed rows. Exact refinement uses the index's build-time metric.
For raw fallback, configure the table's column metric to match the build-time metric.
For all four IVF types, Spark shuffles vectors by their assigned routing centroid.
Each populated shard trains an independent IVF index on the vectors it receives.
For IVF-PQ, this gives each shard its own inner centroids and PQ codebook. The outer
<index-type>.centroid.nlist sets the number of shard slots per contiguous range. The optional
<index-type>.nlist sets the number of IVF lists per shard and
defaults to automatic sizing from that shard's vector count.
For example, build with
ivf-pq.sharding=centroid,ivf-pq.centroid.nlist=64,ivf-pq.nlist=32.
A query with map('centroid.nprobe','4','ivf.nprobe','8') selects four centroids per range
and searches eight local lists in each populated shard. Both levels
support automatic probe sizing.
DiskANN uses the same outer router as IVF. Each populated centroid uses the ordinary DiskANN trainer, writer and reader. The shard trains its PQ codebook and builds its graph from the rows it receives. DiskANN’s seed and memory budget apply to this local build. The outer sample and coarse centers use the same IVF-FLAT training options as the IVF shard types.
For example, use index_type => 'diskann' and
options => 'diskann.sharding=centroid,diskann.centroid.nlist=64', then query with
map('centroid.nprobe','8','diskann.l_search','64'). Persist
diskann.dimension and diskann.metric on the table for raw fallback.
For quantized IVF indexes, each range or centroid shard fits its own codebooks
or bounds. Compare performance at a common recall target using separate calibration
and validation queries. Probe all outer centroids and local lists to measure the effect
of quantization. For IVF-RQ, calibrate rq.bits. For DiskANN, calibrate both outer
probes and local graph search width.
Calibrate ivf-pq.centroid.nlist and ivf-pq.pq.m together with the query probe width.
Increasing centroid.nlist can create more populated shard files, each carrying its own
local model. With 8-bit PQ codes, pq.m=64 uses twice the code bytes per vector
of pq.m=32. Record the resolved build options, total index size, query file
reads, and achieved recall when comparing configurations.
Centroid Index Storage Format
Index Manifest Metadata
Each centroid file has a descriptor in GlobalIndexMeta.indexMeta (_INDEX_META in the
index manifest). The descriptor starts with a 14-byte header.
| Byte offset | Size in bytes | Field |
|---|---|---|
| 0 | 8 | ASCII marker PAIMCENT |
| 8 | 1 | Numeric format version 1 |
| 9 | 1 | ASCII role R, S, or B |
| 10 | 4 | Outer nlist for R, zero-based centroid ID for S, or scalar field ID for B, stored as a big-endian int32 |
The value ranges from 0 to 2,147,483,647. The role also determines the payload starting at byte 14.
| Role | Payload |
|---|---|
R (router) | Build-time distance metric in UTF-8 |
S (vector shard) | The actual local IVF list count as a 32-bit big-endian integer for populated L2 IVF-FLAT and IVF-PQ shards. Other shards end at the header. |
B (Bitmap) | Standard Bitmap key-bound and null metadata. |
The router and its shards share the manifest row-ID range [_ROW_RANGE_START, _ROW_RANGE_END].
Each shard stores row IDs relative to _ROW_RANGE_START. During a query, Paimon translates
row-ID filters to this local range and adds the range start back to matching IDs.
Router and Vector Shard Files
An all-null vector range has one router entry with outer nlist=0 and a zero-byte
router file. In other ranges, the router defines centroid IDs from 0 through
nlist - 1. Each populated centroid has one vector shard file and a manifest
entry with a positive row count. A centroid ID absent from the manifest represents
an empty shard. Empty centroids still count toward the requested probe width.
A populated router file contains the native PVROUT01 model bytes.
| Byte offset | Size in bytes | Field |
|---|---|---|
| 0 | 8 | ASCII marker PVROUT01 |
| 8 | 4 | Vector dimension, little-endian unsigned integer |
| 12 | 4 | Outer centroid count, little-endian unsigned integer |
| 16 | 4 | Metric code, little-endian unsigned integer. 0 is L2, 1 is inner product, and 2 is cosine. |
| 20 | 4 × nlist × dimension | Center coordinates in centroid-ID order. Each center has dimension consecutive little-endian float32 coordinates. |
Paimon checks the router file size before allocating a read buffer. The vector library validates the native header and payload length, and Paimon checks that the loaded model's centroid count matches the manifest.
Bitmap Files
Each row-ID range with indexed vectors has one standalone Bitmap file
per field in _EXTRA_FIELD_IDS. Each Bitmap covers all indexed rows in the range.
Its field ID is in the B descriptor, and the build schema ID in _SOURCE_META
identifies the key type. A range with no vectors has no Bitmap files.
For a vector assigned to centroid c, a Bitmap stores the position
c * range_size + (row_id - row_range_start), where range_size is
row_range_end - row_range_start + 1. After evaluating a scalar predicate once
for the range, Paimon uses the quotient to select the shard and the remainder as
the row ID relative to the start of the range.
Scalar Bitmap Filters in Centroid Shards
In Spark, pass the vector column in index_column and a JSON object mapping scalar column names
to index types in extra_fields. The supported scalar index type is bitmap. Set
global-index.column-update-action to THROW_ERROR or DROP_PARTITION_INDEX.
CALL sys.create_global_index(
table => 'db.model_embeddings',
index_column => 'embedding',
index_type => 'ivf-pq',
options => 'ivf-pq.sharding=centroid,ivf-pq.centroid.nlist=256',
extra_fields => '{"tenant_id":"bitmap","status":"bitmap"}'
);
Spark and Java vector searches can use these Bitmaps for =, <>, IN, NOT IN,
IS NULL, IS NOT NULL, and combinations of these predicates with AND or OR,
including across columns. They apply the exact matches before ranking and skip opening
the ANN file when no visible vector matches.
If any branch cannot be evaluated exactly by the field Bitmaps, the filter uses the existing
scalar-filter path.
Use Spark's sys.add_global_index_fields
to add scalar columns to existing centroid ranges with Bitmap fields. The procedure writes the
new fields' Bitmap files and reuses the existing Bitmap, router, and vector shard files. Use
sys.drop_global_index_fields
to remove selected Bitmap fields while keeping at least one per affected range. Predicates that
depend on a removed field use the existing scalar-filter path. To set
the full list of scalar columns, including the first Bitmap on a vector-only index, run the
centroid build with extra_fields. For the selected partitions, the build replaces the indexes
of the same type on the vector column. Pass the vector column as index_column to
sys.drop_global_index to remove the group.
Rebuild and Compatibility
If a concurrent write or compaction replaces data in the vector column or any configured Bitmap column within a source range, the index commit fails and the build must be retried. Updates to unindexed columns and appends outside the source ranges can proceed. When a row-ID reassignment moves a whole range by a constant offset, the router and shards can be reused with the updated manifest range.
Spark builds and Java searches require the vector plugin and a matching native
library with centroid model APIs. PyPaimon delegates builds and searches to
pypaimon-rust. See the PyPaimon guide.
Tables that used an earlier centroid development format need a drop and rebuild.
Measure model-loading cost and total index size alongside recall, latency, and file reads.