Repository navigation
feat: expose the RTREE index in the Python and TypeScript SDKs - #4942
Conversation
There was a problem hiding this comment.
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.
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]>
220525a to
c22c865
Compare
wjones127
left a comment
There was a problem hiding this comment.
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.
|
|
||
| [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"] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added it to the description: the macOS arm64 release wheel goes from 69.4 MB to 71.7 MB (+2.4 MB, +3.4%).
| !(Number.isInteger(pageSize) && pageSize >= 2 && pageSize <= 0xffffffff) | ||
| ) { | ||
| throw new Error( | ||
| `RTree page_size must be at least 2 and an integer, got ${pageSize}`, |
There was a problem hiding this comment.
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.
| `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}`, |
There was a problem hiding this comment.
Applied in 3dc7030. The message now names the upper bound and keeps the page_size must be at least 2 prefix.
|
|
||
| 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. |
There was a problem hiding this comment.
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:
lancedb/nodejs/lancedb/indices.ts
Lines 867 to 869 in 8a26bf5
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?
There was a problem hiding this comment.
| <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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
✅ 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).
|
I replaced the description with a short one: what this adds, why |
wjones127
left a comment
There was a problem hiding this comment.
I believe the cargo-deny failure is unrelated. Will merge once rest of CI is passing.
Part of #4554. Supersedes #4555.
This exposes Lance's R-tree index in the Python and TypeScript SDKs. Python gets a
lancedb.index.RTreeconfig with an optionalpage_size, accepted bycreate_index(config=...)on local, async and remote tables. TypeScript getsIndex.rtree({ pageSize })andRTreeOptions. Both map to the Rust crate's existingIndex::RTree, so remote tables sendindex_type: "RTREE". The index acceleratesST_Intersects,ST_Contains,ST_Within,ST_Touches,ST_Crosses,ST_Overlaps,ST_CoversandST_CoveredByfilters 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.geois now a default feature of the Python and Node packages. Without it, a local table can neither build the index nor evaluateST_*filters, and because wheels and npm packages are prebuilt, an opt-in Cargo feature would not reach users. pylance already ships withgeoon. It adds pure-Rust crates under licenses thatdeny.tomlalready allows.Cargo.lockdoesn'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()andupdate(), with and without the index.🤖 Generated with Claude Code