Skip to content

feat(index): tokenize JSON arrays into sub-documents - #7377

Merged
Xuanwo merged 3 commits into
lance-format:mainfrom
wirybeaver:lance-json
Nov 1, 2026
Merged

Xuanwo merged 3 commits into
lance-format:mainfrom
wirybeaver:lance-json

Conversation

@wirybeaver

@wirybeaver wirybeaver commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

JSON arrays need element boundaries in the inverted index: otherwise a query can combine values from different array elements. This adds a JSON tokenizer mode that emits one or more sub-documents per row and turns bracketed paths into position constraints. Existing indices continue to use the single-document mode.

This is the tokenizer foundation. The later PRs connect it to index creation and search. The design, query examples, and implementation order are tracked in #7445; index settings are next.

Validation: Rust formatting and cargo check -p lance-index --tests passed.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer enhancement New feature or request labels Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Important

This PR touches the Lance format specification.

Substantive changes to the format specification — the .proto definitions
and the spec docs under docs/src/format/ — require a PMC vote before merge.
Minor edits such as typo fixes, wording, or formatting are excluded; use your
judgment.

If this is a meaningful format change:

  • Start a vote following the Lance community voting process.
    Format specification modifications need 3 binding +1 votes (excluding the
    proposer), held on GitHub Discussions, with a minimum voting period of 1 week.
  • Once the vote passes, link the completed vote in this PR. It should not be
    merged until the vote is linked.

@github-actions github-actions Bot added the A-format On-disk format: protos and format spec docs label Jun 21, 2026
@wirybeaver wirybeaver changed the title feat(index): support array object paths in JSON FTS feat(index): support flattened JSON sub-doc indexing Jun 21, 2026
@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI labels Jun 21, 2026
@wirybeaver wirybeaver mentioned this pull request Jun 21, 2026
2 of 8 tasks
@wirybeaver

wirybeaver commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

@beinan @jja725 Would you mind taking a look at this Json Index improvement proposal shown in the PR summary? If no major concerns, I would go ahead to refine the PR.

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a useful addition to the JSON full text search. I think disable_cross_array_unnest is going to be pretty technical for the user to judge. It might be nice to have some guardrails. For example, if a single document generates more than X subdocs (or maybe more than X subdocs per byte of the original doc) we could log a warning like "more than X subdocuments generated for a single document, if you have sibling arrays you may need to disable cross array unnesting to avoid a combinatorial explosion". Or we could have a "max_subdocs_per_doc" variable that, if exceeded, would fail the index build.

In the other direction we could potentially add some kind of conservative one-time warning. If the user disabled cross array unnesting and then queried the index using multiple constraints. We wouldn't easily know they were multiple sibling array constraints but the warning could be something like "you are querying a JSON text index with multiple constraints and the index was built with cross array unnesting disabled. If those constraints are on two different sibling arrays you may get false negatives. To disable this warning set the environment variable ..."

Ideally we will want some examples added to the docs as well. We could probably expand https://lance.org/guide/json/#full-text-search-on-json-documents

Comment thread protos/index_old.proto Resolved
Comment thread python/python/lance/dataset.py Resolved

@jja725 jja725 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.

Thanks for this great contribution! this would help a lot with FTS

@wirybeaver

Copy link
Copy Markdown
Contributor Author

@jja725 @westonpace Sorry for the late reply. Somehow I miss the email notification about your folks' feedback during vacation. I will work on the improvement this week. Appreciate you folks compliment on this idea.

In terms of adding the parameter "max_sub_docs_per_row", do you folks prefer failing the whole indexing process OR logging an error but keep the already flattened docs?

@westonpace

Copy link
Copy Markdown
Member

In terms of adding the parameter "max_sub_docs_per_row", do you folks prefer failing the whole indexing process OR logging an error but keep the already flattened docs?

Either approach is fine. Failing the entire operation is safest but could be quite annoying if there is only one bad row. In vector indexing, if we encounter NaN / NULL embeddings, we just exclude that row from the index (so it will never appear in search) so there is some precedence for just skipping too.

@wirybeaver

Copy link
Copy Markdown
Contributor Author

Following up on max_sub_docs_per_row, I propose adding two JSON index params before implementation:

  • max_sub_docs_per_row: optional cap on how many flattened sub-docs one source JSON row may produce. If unset, behavior remains unlimited, so Lance will keep flattening until normal memory/resource limits apply.
  • max_sub_docs_per_row_exceed_action: enum scoped to this cap, with initial values fail and skip_row. fail aborts indexing with an error that suggests increasing max_sub_docs_per_row or setting disable_cross_array_unnest=true; skip_row omits the whole offending source row from the index and continues.

Default proposal: unset max_sub_docs_per_row and max_sub_docs_per_row_exceed_action=fail, so existing behavior is unchanged unless a user opts into the cap.

I'll wait for feedback from @westonpace and @jja725 before implementing this.

@github-actions github-actions Bot added the format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). label Sep 4, 2026
@wirybeaver
wirybeaver force-pushed the lance-json branch 3 times, most recently from 255666a to 9aa0019 Compare September 30, 2026 03:43
@wirybeaver

wirybeaver commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

I split the original big PRs into multiple incremental ones. I don't have the access to create branches on the upstream repo to leverage the Stacking PRs. Check the roadmap: #7445

@wirybeaver
wirybeaver marked this pull request as ready for review September 30, 2026 05:36

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

github-actions Bot commented Sep 30, 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: ❌ Blocked — 0 of 3 required approvals

Approvals none (0/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes none
Voting period elapsed — ended Mon 2026-10-05 05:36 UTC (Sun 22:36 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[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. and removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 30, 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-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 8, 2026
…20261101

# Conflicts:
#	rust/lance-index/src/scalar/inverted/tokenizer/document_tokenizer.rs
Reject flattened mode through the legacy single-document stream entry point, validate exact array indexes, and keep the test-only sibling policy setter out of production builds. Add query-path and empty/NULL coverage.
@Xuanwo Xuanwo removed the format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). label Nov 1, 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 Nov 1, 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.

Existing index construction still uses SingleDocument, so the staged tokenizer foundation can land without activating new indexing or search semantics.

The sibling-array expansion risk remains: opt-in flattening can materialize an unbounded Cartesian product. This is non-blocking while the mode stays outside normal index creation; the planned per-row cap should land before default activation.

@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-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 1, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving the staged JSON tokenizer foundation. The default index path remains SingleDocument, flattened mode cannot be consumed through the legacy single-document stream API, and exact array indexes are validated with focused regression coverage. All applicable checks pass on this head. The sibling-array expansion cap remains required before activation, as documented in #7445.

@Xuanwo
Xuanwo merged commit 39412d7 into lance-format:main Nov 1, 2026
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 A-java Java bindings + JNI A-python Python bindings enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants