Skip to content

feat: expose the RTREE index in the Python and TypeScript SDKs - #4942

Merged
wjones127 merged 12 commits into
mainfrom
feat/rtree-index-sdks
Nov 19, 2026
Merged

wjones127 merged 12 commits into
mainfrom
feat/rtree-index-sdks

Conversation

@sarwarbhuiyan

@sarwarbhuiyan sarwarbhuiyan commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Part of #4554. Supersedes #4555.

This exposes Lance's R-tree index in the Python and TypeScript SDKs. Python gets a lancedb.index.RTree config with an optional page_size, accepted by create_index(config=...) on local, async and remote tables. TypeScript gets Index.rtree({ pageSize }) and RTreeOptions. Both map to the Rust crate's existing Index::RTree, so remote tables send index_type: "RTREE". The index accelerates ST_Intersects, ST_Contains, ST_Within, ST_Touches, ST_Crosses, ST_Overlaps, ST_Covers and ST_CoveredBy filters between a GeoArrow column and a constant geometry, in either argument order, including as a prefilter on vector search. The scalar index docs page gets an R-tree section.

geo is now a default feature of the Python and Node packages. Without it, a local table can neither build the index nor evaluate ST_* filters, and because wheels and npm packages are prebuilt, an opt-in Cargo feature would not reach users. pylance already ships with geo on. It adds pure-Rust crates under licenses that deny.toml already allows. Cargo.lock doesn't change, and the third-party license notices are regenerated.

The cost is size: the macOS arm64 release wheel grows from 69.4 MB to 71.7 MB (+2.4 MB, +3.4%).

The tests pin the constant-first predicate bug that held up #4555, which lance-format/lance#10080 fixed, in queries, delete() and update(), with and without the index.

🤖 Generated with Claude Code

@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 enhancement New feature or request Python Python SDK labels Nov 10, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 10, 2026
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 11, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 11, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 12, 2026
sarwarbhuiyan and others added 10 commits November 17, 2026 17:50
Lance's GeoArrow support, the RTREE scalar index and the ST_* functions
from GeoDataFusion, sits behind lancedb's optional `geo` feature. Neither
binding enabled it, so a local table could neither build an R-tree nor
evaluate a spatial filter. Turn it on in both default feature sets; pylance
already ships it through Lance's default features.

The feature adds 32 pure-Rust crates, all under licenses that deny.toml
already allows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `lancedb.index.RTree`, with an optional `page_size`, and accept it in
`create_index(config=...)` on local, remote and async tables. The
deprecated `create_scalar_index` also takes `index_type="RTREE"`. Remote
tables send `index_type: "RTREE"` and, when set, `page_size` to the server.

Tests cover point and polygon columns, spatial filters that use the index,
exact results for candidates that only match on bounding box, a spatial
prefilter on vector search, invalid options, and the remote request body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the `Index.rtree()` factory, with an optional `pageSize`, for GeoArrow
geometry columns, and export `RTreeOptions`. Remote tables send
`index_type: "RTREE"` to the server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add an R-tree section to the scalar index page: storing GeoArrow geometry,
creating the index, the spatial predicates it accelerates, its bounding-box
candidate semantics, spatial prefilters on vector search, and how to check
the query plan. The Python examples come from a new docs test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r_index

Add tests for null geometries, geoarrow.wkb columns, append then optimize,
GeoArrow schema round trips, ST_Crosses/ST_Overlaps/ST_Covers on polygons,
and check every indexed result against the unindexed one. Pin the upstream
GeoDataFusion bugs (constant-first asymmetric predicates in queries, delete
and update; NULL constant geometry panic) as strict xfails so they flag
when Lance picks up the fix.

create_scalar_index is deprecated, so leave RTREE to create_index(config=RTree()).
…rsion

napi wraps negative numbers when converting to u32, so pageSize -1 reached
Rust as 4294967295 and passed the >= 2 check.
…d updates

Lance 15.0.0-beta.15, which main now pins, includes lance-format/lance#10080:
constant-first ST_Contains, ST_Within, ST_Covers and ST_CoveredBy are now
evaluated as their column-first converses, so they return the right rows,
use the R-tree, and no longer panic on a NULL constant geometry.

Replace the strict xfails with regression tests that cover all four
asymmetric predicates plus ST_Intersects, with and without an R-tree, in
queries, delete() and update(). The old update test passed literal values
instead of updates_sql, so it failed for that reason as well; it now uses
updates_sql. Drop the "write the column first" warning from the Python and
TypeScript docstrings and the docs page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe what a remote table does with an RTREE request without naming a
particular server product or its geospatial support.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 18, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 18, 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.

issue(blocking): The PR description was replaced on Nov 18 by the rebase pipeline's task prompt ("## Intent: Rebase the existing lancedb pull request…") and its pipeline log. Could you replace it with a real description?

Please also make it much shorter than the Nov 11 version. The description becomes the squash commit message, so it should be a few readable paragraphs: what this adds, why geo is on by default, and the size cost. This is resolved when the description is the PR's own, concise, and has nothing from the agent prompt left in it.


Thanks for picking this back up after #4555. The SDK side is a thin, consistent wiring of the existing Index::RTree builder across Python sync, async, and remote, plus TypeScript. The constant-first predicate regression tests across query, delete(), and update() are especially nice.

Blocking: the PR description is currently the rebase agent's task prompt. Please replace it with a short, readable description, since it becomes the squash commit message.

Non-blocking: keep one size measurement in the description, a small error-message fix, trimming engine caveats from the docstrings, and the remote-support note in the docs.

I treated the regenerated RUST_THIRD_PARTY_LICENSES.html files as generated output.

Comment thread python/Cargo.toml

[features]
default = ["remote", "lancedb/aws", "lancedb/gcs", "lancedb/azure", "lancedb/dynamodb", "lancedb/oss", "lancedb/huggingface", "lancedb/cos", "lancedb/goosefs", "lancedb/metrics-otel"]
default = ["remote", "lancedb/aws", "lancedb/gcs", "lancedb/azure", "lancedb/dynamodb", "lancedb/oss", "lancedb/huggingface", "lancedb/cos", "lancedb/goosefs", "lancedb/metrics-otel", "lancedb/geo"]

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.

question(non-blocking): Since this turns geo on for every wheel and npm install, could you keep a size measurement in the description?

The macOS arm64 wheel number from the earlier version (+2.4 MB, +3.4%) is enough. You don't need to measure every artifact.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added it to the description: the macOS arm64 release wheel goes from 69.4 MB to 71.7 MB (+2.4 MB, +3.4%).

Comment thread nodejs/lancedb/indices.ts Outdated
!(Number.isInteger(pageSize) && pageSize >= 2 && pageSize <= 0xffffffff)
) {
throw new Error(
`RTree page_size must be at least 2 and an integer, got ${pageSize}`,

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.

nitpick: For 2 ** 32 this says the value must be at least 2 and an integer, which it already is. Could the message include the upper bound? Keeping the page_size must be at least 2 prefix means the test assertion and the Python message still match.

Suggested change
`RTree page_size must be at least 2 and an integer, got ${pageSize}`,
`RTree page_size must be at least 2, at most 4294967295, and an integer, got ${pageSize}`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 3dc7030. The message now names the upper bound and keeps the page_size must be at least 2 prefix.

Comment thread python/python/lancedb/index.py Outdated

Other spatial functions such as ``ST_Distance`` work in filters but scan
every row. Spatial functions are planar, so distances are in the units of
the column's coordinates. ``ST_DWithin`` is not available.

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.

suggestion: Do we need the engine limitations (ST_DWithin is not available, ST_Distance scans every row) in the API docstrings? They're repeated in the TS docstring too:

* Other spatial functions such as `ST_Distance` work in filters but scan
* every row. Spatial functions are planar, so distances are in the units of
* the column's coordinates. `ST_DWithin` is not available.

They're also on the docs page. Once #3794 lands, all three copies need updating. Maybe keep the docstrings to what the config does and which predicates it accelerates, and link to the docs page for the rest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. In 3dc7030 the Python and TypeScript docstrings keep only what the config does and which predicates it accelerates, then link to the scalar index docs page. The ST_Distance, ST_DWithin and planar-distance notes now live only on that page, so #3794 has one place to update.

<Note title="Remote tables">
On a remote table, `create_index` sends the request with the `RTREE` index
type, and spatial filters are sent to the server as written. Whether the
server can build the index and evaluate `ST_*` functions depends on its

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.

suggestion: I believe LanceDB Cloud already supports building RTREE and evaluating ST_*. If that's deployed, I think we can drop "depends on its version" and just say remote tables support it. I'll confirm and follow up here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I'll leave the note as is until you confirm. If Cloud builds RTREE and evaluates ST_*, I'll change it to say remote tables support it.

# evaluated these with the arguments swapped, so a write filter silently matched
# the wrong rows. Only the three interior points are contained, the boundary
# points are also covered, and no point contains or covers the triangle.
CONSTANT_FIRST_CASES = [

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.

praise: Nice. These pin the exact bug that held up #4555, in delete() and update() as well as queries, with and without the index. Those write paths are where it would have hurt most.

…r bound

The Python and TypeScript RTree docstrings now describe what the index
does and which predicates it accelerates, and point to the docs page for
the other spatial functions, planar distances and vector search, so the
engine caveats live in one place. The TypeScript page_size error names
the upper bound as well, since 2 ** 32 is an integer of at least 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 18, 2026

@lancedb-gatekeeper lancedb-gatekeeper 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.

✅ Gate recommendation: approve.

Both SDKs reuse the established Rust R-tree builder and spatial evaluator. The current Lance pin retains the shared evaluator fix for constant-first predicates, and the regression coverage checks the intended rows in reads, deletes and updates. Remote RTREE requests and spatial filters are forwarded, while server support remains a prerequisite.

Documentation: Add TypeScript and Rust counterparts to the new filter, vector-prefilter and query-plan examples; both SDKs support these operations (TypeScript API, Rust API).

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 18, 2026
@sarwarbhuiyan

Copy link
Copy Markdown
Contributor Author

I replaced the description with a short one: what this adds, why geo is on by default, and the wheel size cost. Nothing from the rebase prompt is left. The nits are addressed in 3dc7030, and the remote-note thread is waiting on your confirmation.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 18, 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.

I believe the cargo-deny failure is unrelated. Will merge once rest of CI is passing.

@wjones127
wjones127 merged commit 4b42810 into main Nov 19, 2026
53 of 56 checks passed
@wjones127
wjones127 deleted the feat/rtree-index-sdks branch November 19, 2026 00:43
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. Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants