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

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](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sarwar Bhuiyan
2026-11-18 16:43:12 -08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 2dd1a6ad25
commit 4b428101dd
25 changed files with 21398 additions and 3107 deletions
+17 -2
View File
@@ -10,7 +10,7 @@ use lancedb::index::{
Index as LanceDbIndex,
scalar::{
BTreeIndexBuilder, DocumentGranularity, FmIndexBuilder, FtsIndexBuilder, NGramIndexBuilder,
ZoneMapIndexBuilder,
RTreeIndexBuilder, ZoneMapIndexBuilder,
},
};
use pyo3::IntoPyObject;
@@ -119,6 +119,16 @@ pub fn extract_index_params(source: &Option<Bound<'_, PyAny>>) -> PyResult<Lance
"Fm" => Ok(LanceDbIndex::Fm(FmIndexBuilder::default())),
"NGram" => Ok(LanceDbIndex::NGram(NGramIndexBuilder::default())),
"ZoneMap" => Ok(LanceDbIndex::ZoneMap(ZoneMapIndexBuilder::default())),
"RTree" => {
let params = source.extract::<RTreeParams>()?;
let mut builder = RTreeIndexBuilder::default();
if let Some(page_size) = params.page_size {
builder = builder
.page_size(page_size)
.map_err(|err| PyValueError::new_err(err.to_string()))?;
}
Ok(LanceDbIndex::RTree(builder))
}
"FTS" => {
let params = source.extract::<FtsParams>()?;
let code_options = CodeAnalyzerOptions {
@@ -293,7 +303,7 @@ pub fn extract_index_params(source: &Option<Bound<'_, PyAny>>) -> PyResult<Lance
Ok(LanceDbIndex::IvfHnswFlat(hnsw_flat_builder))
}
not_supported => Err(PyValueError::new_err(format!(
"Invalid index type '{}'. Must be one of BTree, Bitmap, LabelList, Fm, NGram, ZoneMap, FTS, IvfPq, IvfSq, IvfHnswPq, IvfHnswSq, or IvfHnswFlat",
"Invalid index type '{}'. Must be one of BTree, Bitmap, LabelList, Fm, NGram, ZoneMap, RTree, FTS, IvfPq, IvfSq, IvfHnswPq, IvfHnswSq, or IvfHnswFlat",
not_supported
))),
}
@@ -327,6 +337,11 @@ struct FtsParams {
index_operators: Option<bool>,
}
#[derive(FromPyObject)]
struct RTreeParams {
page_size: Option<u32>,
}
#[derive(FromPyObject)]
struct IvfFlatParams {
distance_type: String,