Skip to content

[core] Filter centroid vector shards with colocated Bitmap indexes - #1493

Merged
JingsongLi merged 6 commits into
apache:mainfrom
JingsongLi:codex/centroid-shard-bitmaps
Nov 22, 2026
Merged

JingsongLi merged 6 commits into
apache:mainfrom
JingsongLi:codex/centroid-shard-bitmaps

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Part of #1490. Add Java-compatible scalar Bitmap filters to centroid shards, including cross-column OR. Aligns with apache/paimon#11306 and apache/paimon#11329.

Depends on #1491. Review the Bitmap-only diff.

Brief change log

  • Accept extra_fields on centroid builds. Write a Bitmap file per populated vector shard using row labels relative to the shared source range. The directory records the build schema and section lengths.
  • Bind exact =, IN, null checks, AND, and OR against compatible build fields. Intersect the result with row and deletion filters before ANN, and skip the ANN file for empty matches.
  • Use the existing scalar path for unsupported predicates or incompatible schemas. Keep vector and Bitmap files in one replaceable generation, addressed by the vector column.

Tests

Exercises scheduled exact prefiltering with an ANN file absent from a nonmatching shard, group replacement and drop, and a Java-generated two-section sparse Bitmap file.

API and Format

Uses Java's version 2 centroid metadata. Adds the optional extra_fields argument to DataFusion's create-index procedure and accepts the same JSON in Rust build options.

Documentation

Adds a centroid build example with two Bitmap columns and describes exact predicate support and fallback.

@JingsongLi
JingsongLi force-pushed the codex/centroid-shard-bitmaps branch from 94409d0 to 1051fbe Compare November 22, 2026 07:14
@JingsongLi
JingsongLi marked this pull request as ready for review November 22, 2026 07:19
@JingsongLi
JingsongLi force-pushed the codex/centroid-shard-bitmaps branch from 1051fbe to a59091a Compare November 22, 2026 08:04
@JingsongLi
JingsongLi force-pushed the codex/centroid-shard-bitmaps branch from a59091a to ebd8e9d Compare November 22, 2026 08:12

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff at head ebd8e9d against main (31 files, +2352/-231; branch is 0 behind main, #1491 and #1494 are merged), cross-checked against the Java CentroidBitmapIndex (directory layout, section headers, schema-ID prefix) and CentroidIndexMeta version 2 / matchesIndexFields semantics from apache/paimon#11306 and apache/paimon#11329. Part of #1490.

Core / generic semantics touched (flagging per review policy):

  • Generic query path (de_vector_read.rs): bound Bitmap generations split vector entries into bitmap and regular partitions. Bitmap entries use the pre-scalar-filter searches, drop the post-filter predicate (the bound predicate is exact), skip deleted-row limit inflation (deletions are prefiltered exactly via BitmapWork.deleted), and exclude their ranges from scalar prefiltering and raw fallback (covered = scalar_prefilter_ranges intersect bitmap_ranges). Regular entries keep the previous scalar-prefilter / post-filter behavior unchanged.
  • Distributed task contract: new kind vector-index-centroid-bitmap with serde(default) BitmapWork payload and worker-side validation that kind and payload agree; old workers reject the unknown kind instead of ignoring the predicate.
  • Scan plan format: VectorScanPlan gains scalar_prefilter_ranges (skip-if-empty, serde default, merged on deserialize); Python __reduce__ now roundtrips the plan as JSON so the coverage metadata survives pickling. The explicit (splits, snapshot) constructor intentionally loses it, which the tests document.
  • Build pipeline: extra_fields JSON option (centroid sharding required, vindex types only, BTree-compatible field validation, vector column itself rejected); streamed BitmapSpill offset/key files preserve sparse source labels (zero-offset holes for vector-null rows and all-null batches); per-shard sections are written through the new write_sorted_bitmap_section with 1MB flushes and section-relative offsets; version 2 descriptors carry extra_field_ids and a build-schema-ID directory prefix. Requires THROW_ERROR or DROP_PARTITION_INDEX for the column-update action at build time.
  • Commit semantics: a colocated Bitmap belongs to the vector index identity (index_identity_extra_fields returns None for version-2 files), so rebuild replaces the whole group and drop-by-vector-column removes Bitmap files; overlap validation uses the same identity. Under IGNORE, updates touching index or extra fields of a retained overlapping Bitmap generation are rejected, and a partial router-only delete does not bypass the check.
  • Generation validation: version 2 requires non-empty, duplicate-free extra field IDs excluding the index field; one Bitmap per populated shard with matching row counts; consistent build schema ID across sections; directory parsing mirrors the Java bounds checks (section lengths sum to file size, no trailing bytes).
  • Bitmap writer refactor: the existing single-file writer now shares BitmapSectionWriter; block order (nulls, non-nulls, postings, dictionary, index, footer) and footer encoding are unchanged for the non-centroid path.

What I verified:

  • Predicate binding is exact-or-fallback: only =, IN, IS NULL, IS NOT NULL, AND, OR over allowed build fields bind; any unsupported leaf falls back to ordinary scalar filtering for the whole generation. Non-finite float literals and lossy decimal/timestamp normalization decline binding; signed-zero and cross-type float/double behavior matches the Java dictionary representation (tests pin -0.0 vs 0.0, decimal rescale, sub-milli timestamp).
  • Schema evolution: binding checks field ID and type (ignoring nullability) against the build schema; renames keep working, type changes fall back without opening Bitmap files; the REST fallback accepts only the exact requested schema ID on the default branch (both older and newer loaded handles are covered by tests).
  • Per-shard evaluation intersects the Bitmap result with validated deletion ranges and per-query include IDs, validates row-ID bounds against the shared source range, and skips the ANN file entirely on empty matches (test deletes the ANN payload of a nonmatching shard). Joint probing is disabled for Bitmap work; widening still applies so exact prefiltering can visit more shards to fill Top-K.
  • Java compatibility: a real Java-generated two-section sparse Bitmap file (CentroidBitmapIndex.Writer + CentroidIndexMeta.scalarIndex) is read correctly, including OR across columns and relative labels 2/4 at source range [10, 14].
  • Test coverage: scheduled and buffered reads agree; group replacement and drop; IGNORE update rejection incl. partial-drop bypass attempt; streamed section offsets across 1MB flushes; sparse spill labels with tiny sort/dictionary budgets; SQL CALL sys.create_global_index with extra_fields plus cross-column OR through vector_search; pickle roundtrip preserving scalar coverage; plan reuse with a different filter.

No findings. CI is fully green at this head (15/15 checks).

@JingsongLi
JingsongLi merged commit 8e2284d into apache:main Nov 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants