feat(node): expose ZoneMap and BloomFilter index configs (#4962)

## Summary

Refs #4931 (TypeScript portion).

Expose the existing Rust ZoneMap and BloomFilter builders through
`Index.zoneMap()` and `Index.bloomFilter({ numberOfItems?, probability?
})` for Embedded and Enterprise tables. Export `BloomFilterOptions`,
reject values that cannot be converted losslessly from a positive
JavaScript safe integer to Rust `u64`, and retain the core builder's
probability validation and defaults.

Include API examples, generated documentation, and the ZoneMap
table-capability compatibility warning. Synchronize with main while
preserving its RTree/plugin factories and source-bearing Blob APIs. The
Python portion remains separate.

## Validation

- Built the new native binding on macOS 15.7.9 / arm64 with Rust 1.98.0,
Node 24.22.1, the repository `ci` profile, locked dependencies, and
Rust's bundled LLD scoped to the Node binding. Both lockfiles match
main.
- Four full affected Jest suites: **819 passed, 3 existing
experimental-feature cases skipped**. Coverage includes index
creation/listing, range and membership plans/results, option boundaries,
Enterprise HTTP request bodies, and the newly merged Blob descriptor
API.
- Passed TypeScript compilation, Biome check/format for all 85 Node
files, generated API documentation with warnings treated as errors, Rust
formatting, and `git diff --check`.
- Independent execution in a separate writable snapshot: 56
reviewer-designed boundary cases passed on each of Node 22 and 24; 815
adjacent repository tests passed, with 3 existing skips. TypeScript,
generated docs, Biome, and the compiled package entry point passed. The
final source tree, complete diff, and freshly built native artifact
hashes matched; no actionable findings remained.

The final documentation correction was checked against the pinned Lance
source. TypeScript compilation, Biome, generated API documentation, and
all 19 index option tests passed again. Two real Embedded table probes
confirmed that default ZoneMap creation on string and binary columns
leaves the v1 reader and writer capability bits unset; the string range
query used the scalar index and returned the expected rows. A fresh
independent snapshot also passed the string/binary lifecycle probes on
Node 22 and 24 (24 manifest observations), the 19 repository index
tests, and the documentation/type/lint checks.

Enterprise checks use mock HTTP endpoints. The native linker reports
C-library minimum-macOS-version warnings, so these runs do not establish
compatibility with older macOS versions.

## Merge Danger

**Door:** two-way

The SDK additions can be reverted. ZoneMap write seeds use v0 by
default. A commit that explicitly sets `lance.zone_write_seeds.version`
to `"1"` activates a persistent reader and writer capability; readers
and writers must support it before opting in. Dropping the index or
restoring an older version does not remove that capability from
subsequent snapshots.

**Blast Radius:** TypeScript

Adds index configuration factories and NAPI bindings; reuses existing
core index creation and Enterprise serialization.
This commit is contained in:
Kevin Dong
2026-11-30 20:23:00 +08:00
committed by GitHub
parent 8a27234be2
commit 2ff3bee923
9 changed files with 368 additions and 1 deletions
+68
View File
@@ -27,6 +27,39 @@ is small (i.e., less than a few hundreds).
***
### bloomFilter()
```ts
static bloomFilter(options?): Index
```
Create a Bloom filter index.
Bloom filters accelerate equality and membership filters by skipping groups
of rows that cannot match. Candidate rows are checked to remove false
positives. This index uses less space than a btree or bitmap index, but does
not accelerate range filters. Unset options use Lance's defaults.
#### Parameters
* **options?**: [`BloomFilterOptions`](../interfaces/BloomFilterOptions.md)
#### Returns
[`Index`](Index.md)
#### Example
Tuning a Bloom filter on an Embedded table:
```ts
await table.createIndex("id", {
config: Index.bloomFilter({ numberOfItems: 4096, probability: 0.01 }),
});
```
***
### btree()
```ts
@@ -349,3 +382,38 @@ await table
.where("ST_Intersects(geom, ST_GeomFromText('POLYGON ((0 0, 4 0, 0 4, 0 0))'))")
.toArray();
```
***
### zoneMap()
```ts
static zoneMap(): Index
```
Create a ZoneMap index.
This index stores min/max summaries for ranges of rows and skips ranges that
cannot match a filter. It works best for numeric or temporal columns whose
values are correlated with row order, such as timestamps or sequential IDs.
For strings, binary data, and supported types wider than eight bytes, this
index uses per-fragment write seeds. By default, these use version 0 and do
not activate the version 1 table capability.
A commit that explicitly sets the table configuration key
`lance.zone_write_seeds.version` to `"1"` activates a persistent reader and
writer capability. Upgrade all readers and writers before opting in: clients
that do not support this capability cannot access the resulting snapshots.
Dropping the index or restoring an older version does not remove the
capability from subsequent snapshots.
#### Returns
[`Index`](Index.md)
#### Example
```ts
await table.createIndex("timestamp", { config: Index.zoneMap() });
```
+1
View File
@@ -65,6 +65,7 @@
- [AlterColumnsResult](interfaces/AlterColumnsResult.md)
- [BlobDescriptor](interfaces/BlobDescriptor.md)
- [BlobDescriptorSource](interfaces/BlobDescriptorSource.md)
- [BloomFilterOptions](interfaces/BloomFilterOptions.md)
- [BranchColumnChange](interfaces/BranchColumnChange.md)
- [BranchColumnSummary](interfaces/BranchColumnSummary.md)
- [BranchDiff](interfaces/BranchDiff.md)
@@ -0,0 +1,36 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / BloomFilterOptions
# Interface: BloomFilterOptions
Options to create a Bloom filter index.
## Properties
### numberOfItems?
```ts
optional numberOfItems: number;
```
The number of rows covered by each Bloom filter. Must be a positive safe integer.
Defaults to 8192, unless overridden by Lance's
`LANCE_BLOOMFILTER_DEFAULT_NUMBER_OF_ITEMS` environment variable.
***
### probability?
```ts
optional probability: number;
```
The desired false-positive probability. Must be finite and strictly between zero and one.
Lower values use more space.
Defaults to 0.00057, unless overridden by Lance's
`LANCE_BLOOMFILTER_DEFAULT_PROBABILITY` environment variable.
+44
View File
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import { type BloomFilterOptions, Index } from "../lancedb";
describe("BloomFilter options", () => {
it.each([
0,
-1,
1.5,
Number.NaN,
Number.POSITIVE_INFINITY,
Number.NEGATIVE_INFINITY,
Number.MAX_SAFE_INTEGER + 1,
])("rejects invalid numberOfItems %s", (numberOfItems) => {
expect(() => Index.bloomFilter({ numberOfItems })).toThrow(
"numberOfItems must be a positive safe integer",
);
});
it.each([
-0.1,
0,
1,
1.1,
Number.NaN,
Number.POSITIVE_INFINITY,
Number.NEGATIVE_INFINITY,
])("rejects invalid probability %s", (probability) => {
expect(() => Index.bloomFilter({ probability })).toThrow(
"probability must be finite and strictly between zero and one",
);
});
it.each<BloomFilterOptions>([
{},
{ numberOfItems: 1 },
{ numberOfItems: Number.MAX_SAFE_INTEGER },
{ probability: Number.MIN_VALUE },
{ probability: 1 - Number.EPSILON },
])("accepts valid options %j", (options) => {
expect(() => Index.bloomFilter(options)).not.toThrow();
});
});
+73
View File
@@ -2015,6 +2015,79 @@ describe("remote connection", () => {
]);
});
it.each([
["ZoneMap", () => Index.zoneMap(), { ["index_type"]: "ZONEMAP" }],
[
"default BloomFilter",
() => Index.bloomFilter(),
{ ["index_type"]: "BLOOM_FILTER" },
],
[
"BloomFilter numberOfItems",
() => Index.bloomFilter({ numberOfItems: 64 }),
{ ["index_type"]: "BLOOM_FILTER", ["number_of_items"]: 64 },
],
[
"BloomFilter probability",
() => Index.bloomFilter({ probability: 0.01 }),
{ ["index_type"]: "BLOOM_FILTER", probability: 0.01 },
],
[
"custom BloomFilter",
() => Index.bloomFilter({ numberOfItems: 64, probability: 0.01 }),
{
["index_type"]: "BLOOM_FILTER",
["number_of_items"]: 64,
probability: 0.01,
},
],
[
"BloomFilter with a large numberOfItems",
() => Index.bloomFilter({ numberOfItems: Number.MAX_SAFE_INTEGER }),
{
["index_type"]: "BLOOM_FILTER",
["number_of_items"]: Number.MAX_SAFE_INTEGER,
},
],
])("sends %s options to remote tables", async (_, config, expected) => {
let createIndexBody: Record<string, unknown> | undefined;
await withMockDatabase(
(req, res) => {
if (req.url?.endsWith("/describe/")) {
res.writeHead(200, { "Content-Type": "application/json" }).end(
JSON.stringify({
name: "t",
version: 1,
schema: {
fields: [
{ name: "id", type: { type: "int64" }, nullable: false },
],
},
}),
);
} else if (req.url?.endsWith("/create_index/")) {
let raw = "";
req.on("data", (chunk) => {
raw += chunk;
});
req.on("end", () => {
createIndexBody = JSON.parse(raw);
res.writeHead(200).end();
});
} else {
res.writeHead(404).end();
}
},
async (db) => {
const table = await db.openTable("t");
await table.createIndex("id", { config: config() });
},
);
expect(createIndexBody).toEqual({ column: "id", ...expected });
});
it("diffs and cherry-picks remote branches", async () => {
const sampleDiff = {
fromBranch: "exp",
+35
View File
@@ -1794,6 +1794,41 @@ describe("When creating an index", () => {
expect(fs.readdirSync(indexDir)).toHaveLength(1);
});
test("create a ZoneMap index and use it for range filters", async () => {
await tbl.createIndex("id", { config: Index.zoneMap() });
expect(await tbl.listIndices()).toEqual([
expect.objectContaining({
indexType: "ZoneMap",
columns: ["id"],
}),
]);
const query = tbl.query().where("id >= 100 AND id < 110").select(["id"]);
expect(await query.explainPlan(true)).toContain("ScalarIndexQuery");
expect(
(await query.toArray()).map((row) => row.id).sort((a, b) => a - b),
).toEqual(Array.from({ length: 10 }, (_, i) => i + 100));
});
test.each([
["default", undefined],
["custom", { numberOfItems: 64, probability: 0.01 }],
])("create a BloomFilter index with %s options", async (_, options) => {
await tbl.createIndex("id", { config: Index.bloomFilter(options) });
expect(await tbl.listIndices()).toEqual([
expect.objectContaining({
indexType: "BloomFilter",
columns: ["id"],
}),
]);
const query = tbl.query().where("id IN (42, 142, 999)").select(["id"]);
expect(await query.explainPlan(true)).toContain("ScalarIndexQuery");
expect(
(await query.toArray()).map((row) => row.id).sort((a, b) => a - b),
).toEqual([42, 142]);
});
test("create a hnswPq index", async () => {
await tbl.createIndex("vec", {
config: Index.hnswPq({
+1
View File
@@ -178,6 +178,7 @@ export {
IvfFlatOptions,
HnswPqOptions,
HnswSqOptions,
BloomFilterOptions,
FtsOptions,
RTreeOptions,
BaseTokenizer,
+72
View File
@@ -580,6 +580,28 @@ export type BaseTokenizer =
| `jieba/${string}`
| `lindera/${string}`;
/**
* Options to create a Bloom filter index.
*/
export interface BloomFilterOptions {
/**
* The number of rows covered by each Bloom filter. Must be a positive safe integer.
*
* Defaults to 8192, unless overridden by Lance's
* `LANCE_BLOOMFILTER_DEFAULT_NUMBER_OF_ITEMS` environment variable.
*/
numberOfItems?: number;
/**
* The desired false-positive probability. Must be finite and strictly between zero and one.
* Lower values use more space.
*
* Defaults to 0.00057, unless overridden by Lance's
* `LANCE_BLOOMFILTER_DEFAULT_PROBABILITY` environment variable.
*/
probability?: number;
}
/**
* Options to create a full text search index
*/
@@ -924,6 +946,56 @@ export class Index {
return new Index(LanceDbIndex.plugin(indexType, paramsJson));
}
/**
* Create a ZoneMap index.
*
* This index stores min/max summaries for ranges of rows and skips ranges that
* cannot match a filter. It works best for numeric or temporal columns whose
* values are correlated with row order, such as timestamps or sequential IDs.
*
* For strings, binary data, and supported types wider than eight bytes, this
* index uses per-fragment write seeds. By default, these use version 0 and do
* not activate the version 1 table capability.
*
* A commit that explicitly sets the table configuration key
* `lance.zone_write_seeds.version` to `"1"` activates a persistent reader and
* writer capability. Upgrade all readers and writers before opting in: clients
* that do not support this capability cannot access the resulting snapshots.
* Dropping the index or restoring an older version does not remove the
* capability from subsequent snapshots.
*
* @example
* ```ts
* await table.createIndex("timestamp", { config: Index.zoneMap() });
* ```
*/
static zoneMap() {
return new Index(LanceDbIndex.zoneMap());
}
/**
* Create a Bloom filter index.
*
* Bloom filters accelerate equality and membership filters by skipping groups
* of rows that cannot match. Candidate rows are checked to remove false
* positives. This index uses less space than a btree or bitmap index, but does
* not accelerate range filters. Unset options use Lance's defaults.
*
* @example
* Tuning a Bloom filter on an Embedded table:
*
* ```ts
* await table.createIndex("id", {
* config: Index.bloomFilter({ numberOfItems: 4096, probability: 0.01 }),
* });
* ```
*/
static bloomFilter(options?: BloomFilterOptions) {
return new Index(
LanceDbIndex.bloomFilter(options?.numberOfItems, options?.probability),
);
}
/**
* Create a full text search index
*
+38 -1
View File
@@ -5,7 +5,8 @@ use std::sync::Mutex;
use lancedb::index::Index as LanceDbIndex;
use lancedb::index::scalar::{
BTreeIndexBuilder, FmIndexBuilder, FtsIndexBuilder, PluginIndexBuilder, RTreeIndexBuilder,
BTreeIndexBuilder, BloomFilterIndexBuilder, FmIndexBuilder, FtsIndexBuilder,
PluginIndexBuilder, RTreeIndexBuilder, ZoneMapIndexBuilder,
};
use lancedb::index::vector::{
IvfFlatIndexBuilder, IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, IvfPqIndexBuilder,
@@ -251,6 +252,42 @@ impl Index {
})
}
/// Create a ZoneMap index using the defaults in [`ZoneMapIndexBuilder`].
#[napi(factory)]
pub fn zone_map() -> Self {
Self {
inner: Mutex::new(Some(LanceDbIndex::ZoneMap(ZoneMapIndexBuilder::default()))),
}
}
/// Create a Bloom filter index with validated [`BloomFilterIndexBuilder`] options.
#[napi(factory)]
pub fn bloom_filter(
number_of_items: Option<f64>,
probability: Option<f64>,
) -> napi::Result<Self> {
let mut opts = BloomFilterIndexBuilder::default();
if let Some(number_of_items) = number_of_items {
// JavaScript numbers must be losslessly representable before conversion to u64.
if number_of_items.fract() != 0.0
|| !(1.0..=9_007_199_254_740_991.0).contains(&number_of_items)
{
return Err(napi::Error::from_reason(
"BloomFilter numberOfItems must be a positive safe integer",
));
}
opts = opts
.number_of_items(number_of_items as u64)
.default_error()?;
}
if let Some(probability) = probability {
opts = opts.probability(probability).default_error()?;
}
Ok(Self {
inner: Mutex::new(Some(LanceDbIndex::BloomFilter(opts))),
})
}
#[napi(factory)]
#[allow(clippy::too_many_arguments)]
pub fn fts(