Skip to content

feat(knn): expose ANNIvfBatchExec's query, width and inputs - #9262

Merged
hamersaw merged 3 commits into
lance-format:mainfrom
hamersaw:feature/ann-ivf-batch-accessors
Sep 16, 2026
Merged

hamersaw merged 3 commits into
lance-format:mainfrom
hamersaw:feature/ann-ivf-batch-accessors

Conversation

@hamersaw

@hamersaw hamersaw commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

Adds accessors to ANNIvfBatchExecquery(), query_count(), dataset(), indices(), prefilter_source() — and re-exports the node and QUERY_INDEX_COL from lance::io::exec.

Why

ANNIvfSubIndexExec has had query(), dataset(), indices() and prefilter_source() since it was introduced. ANNIvfBatchExec landed with every field private and only try_new, so a caller that matches it in a physical plan can see it exists but can't read anything out of it.

That blocks plan rewriting on the batch path. A downstream rewriter that needs to add a second scan arm to a batch vector search — for example, to cover rows that aren't in the index yet — has to read the query vectors, how many there are, and the dataset and index metadata out of the base plan. The per-query union shape (HNSW, or any refine_factor) is already reachable through ANNIvfSubIndexExec; the shared-scan fast path is not, so the two shapes can't be handled the same way.

Rebuilding the node with a different candidate k needs the same fields, since try_new takes them all and there's no way to get them back out of an existing node.

Notes

  • Purely additive: no behavior change, no signature changes, nothing removed.
  • query()'s doc notes that key holds all query_count vectors concatenated, which is the one non-obvious thing about reading it.

🤖 Generated with Claude Code

The shared-scan batch node kept every field private, so a caller that
matched it in a plan could not read the query, the number of vectors in
it, or the dataset and index metadata behind it — the accessors
ANNIvfSubIndexExec has had all along. Sophon's WAL union needs them to
build a fresh-tier arm for a batch vector search and to rebuild the node
with an inflated candidate k.

Also re-export the node and QUERY_INDEX_COL from `lance::io::exec`,
alongside the single-query nodes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the enhancement New feature or request label Sep 16, 2026
@hamersaw
hamersaw marked this pull request as ready for review September 16, 2026 14:56
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 16, 2026
The accessors and the `io::exec` re-export had no repository coverage, so a
regression in either would go unnoticed here. Plan a batch indexed search,
downcast the node through the public path, and assert the five accessors hand
back the scanner's inputs — with and without a prefilter, so
`prefilter_source()` is exercised in both shapes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 16, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 16, 2026
Two breaks from this branch:

- The plan walk used `as_any().downcast_ref()`, but DataFusion 54 puts
  `downcast_ref` on `dyn ExecutionPlan` itself, so the test target did not
  compile. Match `find_filtered_read`, which already walks plans this way.
- Re-exporting `ANNIvfBatchExec` brought its doc comment into the public docs,
  where its intra-doc link to the private `build_dataset_prefilter` is a
  rustdoc error. Keep the reference, drop the link.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 16, 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.

The public batch-plan inspection surface is now covered through the intended lance::io::exec re-export, and the focused accessor tests compile and pass on the current head. I found no remaining material issue.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 16, 2026
}
}

/// Finds the batch vector-search node in a physical plan.

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.

can there be more than one?

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.

I see, it's just test code

@hamersaw
hamersaw merged commit 51ed498 into lance-format:main Sep 16, 2026
50 of 51 checks passed
@hamersaw
hamersaw deleted the feature/ann-ivf-batch-accessors branch September 16, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants