Skip to content

fix(index): record the JSON wrapper's target index version - #9721

Merged
westonpace merged 2 commits into
mainfrom
fix/json-index-target-version
Oct 28, 2026
Merged

westonpace merged 2 commits into
mainfrom
fix/json-index-target-version

Conversation

@westonpace

@westonpace westonpace commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Follow-up to refactor(index): pass index_version into ScalarIndexPlugin::load_index #9518 (merged). Addresses the non-blocking risk the gatekeeper flagged there: JsonIndexPlugin::load_index passed target_plugin.version() (the target plugin's current max format version) instead of the version the target index was actually persisted at, since JsonIndexDetails never recorded it.
  • Adds an optional target_index_version field (field 4) to JsonIndexDetails, populated from CreatedIndex::index_version whenever the wrapper trains, remaps, or updates its target. load_index now reads it, falling back to the target plugin's current version only for details written before this field existed (matching the previous, safe-for-now behavior for old data).
  • Drops the now-stale note in the target_data_type docs saying these details do not record the target's format version.
  • This matters for the stacked BTree format change, which will use the passed-in version to distinguish stored row IDs from row addresses.

Test plan

  • cargo clippy -p lance-index -p lance --tests -- -D warnings clean
  • cargo fmt --all -- --check clean
  • cargo test -p lance-index --lib scalar::json:: — 27 passed

🤖 Generated with Claude Code

https://claude.ai/code/session_018BsnoP9ZPMX6vhJSygzdnN

@claude claude Bot 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). bug Something isn't working labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ✅ Vote passed — 3 PMC approvals, voting period elapsed

Approvals @Xuanwo, @wjones127, @BubbleCal (3/3)
Latest commit approved by @BubbleCal
Vetoes none
Voting period elapsed — ended Thu 2026-10-08 18:49 UTC (11:49 PDT)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Gate recommendation: approve with a non-blocking risk.

Recording the target’s persisted version is the right fix for newly written JSON indices. Historical metadata still needs version inference when a target format changes; land this plumbing before the format-aware BTree reader in #9481, and handle that legacy ambiguity with the format transition.

Please mark this PR with the breaking-change label.

Comment thread rust/lance-index/src/scalar/json.rs Outdated
// always came from a fresh training pass in the same codebase.
let target_index_version = json_details
.target_index_version
.unwrap_or_else(|| target_plugin.version());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Older JSON/BTree indices still take the reader’s current maximum here, although their targets were written as V0. After the BTree version becomes V1, this branch will pass V1 for those V0 targets. Fresh training established the writer’s version; it does not establish the version of a later reader.

This preserves existing behavior and is non-blocking on this head because the current BTree loader ignores the argument. When #9481 begins using it to select the row-identifier domain, the transition needs historical target-version inference, such as V0 for pre-field BTree targets, or an authoritative marker in the target’s stored metadata.

A loader probe through this head’s JSON wrapper, including protobuf serialization, confirmed Some(0) → 0, Some(3) → 3, and None → 7 when the target plugin advertised version 7. This verifies the fallback selection; wrong-result behavior after the separate BTree transition was not tested here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Updating the context after the rebase: #9481 has merged, so BTree now uses this argument. A current-head probe through the JSON wrapper loaded the target in row-ID domain for Some(0), and address domain for both Some(1) and None. The absent-field fallback is identical in the base revision, so this remains pre-existing behavior.

The same probe verified that training, update, and both remap APIs persist the target's returned version, including zero. #9856 contains the broader historical inference and wrapper-domain migration; the stable-row-ID creation restriction remains unchanged here. This remains a non-blocking legacy risk for this plumbing change.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 5, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 8, 2026
westonpace added a commit that referenced this pull request Oct 9, 2026
The gatekeeper review flagged that the row-address-domain migration
isn't safe yet for a BTREE index wrapped in a JSON index: JsonIndexDetails
has no field for the target's persisted version (load_index stands in
with the target plugin's current max version instead), and the
domain-safety checks protecting a plain BTree segment during merge/
compaction (IndexMetadata::results_are_row_addrs, append.rs's
legacy_domain_mismatch) key off the outer index's own type_url, which a
JSON wrapper's details never match. A wrapped BTREE segment that
genuinely stored row addresses on a stable-row-id dataset would be
invisible to all of that machinery.

Rather than implement the full fix (threading the target's domain
through the wrapper's own metadata -- #9721), reject
the combination outright, at both write paths: fresh creation/rebuild
(build_scalar_index) and incremental merge during optimize
(merge_scalar_indices), before either does any work. A dataset without
stable row ids is unaffected, since there a row id and a row address
are the same value, so a plain BTREE index and a JSON-wrapped one
created today keep working exactly as before.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Oct 9, 2026
The gatekeeper review flagged that the row-address-domain migration
isn't safe yet for a BTREE index wrapped in a JSON index: JsonIndexDetails
has no field for the target's persisted version (load_index stands in
with the target plugin's current max version instead), and the
domain-safety checks protecting a plain BTree segment during merge/
compaction (IndexMetadata::results_are_row_addrs, append.rs's
legacy_domain_mismatch) key off the outer index's own type_url, which a
JSON wrapper's details never match. A wrapped BTREE segment that
genuinely stored row addresses on a stable-row-id dataset would be
invisible to all of that machinery.

Rather than implement the full fix (threading the target's domain
through the wrapper's own metadata -- #9721), reject
the combination outright, at both write paths: fresh creation/rebuild
(build_scalar_index) and incremental merge during optimize
(merge_scalar_indices), before either does any work. A dataset without
stable row ids is unaffected, since there a row id and a row address
are the same value, so a plain BTREE index and a JSON-wrapped one
created today keep working exactly as before.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Oct 14, 2026
The gatekeeper review flagged that the row-address-domain migration
isn't safe yet for a BTREE index wrapped in a JSON index: JsonIndexDetails
has no field for the target's persisted version (load_index stands in
with the target plugin's current max version instead), and the
domain-safety checks protecting a plain BTree segment during merge/
compaction (IndexMetadata::results_are_row_addrs, append.rs's
legacy_domain_mismatch) key off the outer index's own type_url, which a
JSON wrapper's details never match. A wrapped BTREE segment that
genuinely stored row addresses on a stable-row-id dataset would be
invisible to all of that machinery.

Rather than implement the full fix (threading the target's domain
through the wrapper's own metadata -- #9721), reject
the combination outright, at both write paths: fresh creation/rebuild
(build_scalar_index) and incremental merge during optimize
(merge_scalar_indices), before either does any work. A dataset without
stable row ids is unaffected, since there a row id and a row address
are the same value, so a plain BTREE index and a JSON-wrapped one
created today keep working exactly as before.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@westonpace
westonpace force-pushed the fix/json-index-target-version branch 2 times, most recently from f424ab6 to 4bb84cd Compare October 22, 2026 19:43
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 22, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 22, 2026
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 22, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 22, 2026
@LuQQiu

LuQQiu commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Blocking: the absent-field fallback still uses the running plugin's current version, not the legacy file's version.

For a concrete example:

Being freshly trained by the writer at the time does not mean the files match the reader's current version after an upgrade. This fallback pre-exists, but adding the field for new writes does not fix the legacy case.

Could we use documented, evidence-backed legacy versions per target when the field is absent, and treat an unresolvable target as unsupported rather than guessing? The proto comment should describe that same rule. A regression where the historical target version is 0 but the plugin now supports 1 would cover this.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 22, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Gate recommendation: approve with a non-blocking risk.

The 13.0.0 example is correct: those JSON details omit the target version, so the fallback passes V1 for a BTree target written as V0. The proto's “fresh training” explanation does not establish the version for an upgraded reader.

The recommendation remains non-blocking because the base already passes the same version for the same metadata; this patch leaves that legacy read path unchanged. #9856 includes historical-version inference and the wrapper-domain migration. This version-recording plumbing can land independently while retaining the stable-row-ID creation restriction.

Please mark this PR with the breaking-change label.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 22, 2026
JsonIndexPlugin::load_index passed the target plugin's current max
version instead of the version the target was actually persisted at,
since JsonIndexDetails didn't record it. Store it from
CreatedIndex::index_version on train/remap/update and use it on load,
falling back to the plugin's current version for older details that
predate this field.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@westonpace
westonpace force-pushed the fix/json-index-target-version branch from 4bb84cd to 1f9d2f5 Compare October 27, 2026 13:45
@westonpace

Copy link
Copy Markdown
Member Author

Blocking: the absent-field fallback still uses the running plugin's current version, not the legacy file's version.

I've changed the fallback from "current version" to "old version"

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 27, 2026

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

…rsion

BasicTrainer::train_index for these three builtins always reports the
current (address-domain) version: that generic path has no dataset
awareness to tell whether a row id and a row address coincide, unlike
build_scalar_index in the lance crate, which downgrades to the
row-id-domain version for exactly that reason. The JSON wrapper now
persists the target's trained index_version verbatim, so it picked up
this always-address-domain value and failed
test_json_wrapped_target_loads_as_row_id_domain on every platform.

A JSON-wrapped target of these three types is never built on a
stable-row-id dataset, so a row id and a row address always coincide
here and the row-id-domain version is always correct. Share the
floor-version lookup between load_index (fallback for details
predating target_index_version) and train_index (override after
training).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@westonpace
westonpace merged commit 1818a96 into main Oct 28, 2026
41 checks passed
@westonpace
westonpace deleted the fix/json-index-target-version branch October 28, 2026 14:54
Xuanwo pushed a commit that referenced this pull request Nov 2, 2026
Record the trained JSON target type in `JsonIndexDetails` and carry the raw recorded value through load, remap, update, and rebuild without retraining.

Preserve the target index version from #9721, keep creation scalar-only, and retain the established PascalCase `JsonIndexParameters` spelling for recovery and rebuild compatibility. The new `details_as_json` field uses lowercase independently; `LargeBinary` remains legacy-only.

Closes #9256.
westonpace added a commit that referenced this pull request Nov 6, 2026
Similar to #9814 (Bitmap/LabelList → row-address domain), and #9481
(BTree). It applies the same migration to the JSON index. JSON is a
wrapper, so it takes its domain from the target index it wraps. This is
also built on #9721 which adds the target index version to the JSON
index details.

Prior to this change we only supported creating JSON indexes against
targets that were in their "legacy domain". For example, a JSON->BTREE
index would be row ids and a JSON->ZONE_MAP index would be row addrs.
This remains the behavior for JSON index version 0.

This PR adds a new JSON index version (1) which can only be used with
row address domain indcies. The new index version is really just
simplification and convenience as it makes it easy to tell we are in the
row address domain without consulting the index details and doing some
complicated type-dependent logic (we could otherwise determine this from
the target version and index type). However, it is also consistent with
the other indexes which have been bumping the index version as part of
the switch.

The actual index itself did not need to change (it's just a wrapper) but
some of the index management logic did (since JSON indexes could now
potentially be row address indexes).

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer bug Something isn't working format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants