feat(nodejs): expose the NGram scalar index (#4908)

The Rust core (lancedb::index::scalar::NGramIndexBuilder) and the Python
SDK already support the NGram scalar index, and the Node.js SDK can
create one on Embedded with `Index.plugin("ngram")`. This change adds a
dedicated `Index.ngram()` factory. NGram is a scalar index on a UTF-8
string column that accelerates substring filters such as contains(col,
'needle'), along with some LIKE and regular-expression predicates, by
narrowing a scan to rows that share the query's trigrams.

Add an ngram() napi factory and Index.ngram() in the TypeScript SDK,
mirroring the existing btree and fm scalar index factories, with tests
for both factories. On Embedded, the query plan uses the index and the
exact substring filter excludes rows that only share the query’s
trigrams. On Enterprise, `Index.ngram()` sends `index_type: "NGRAM"`,
while `Index.plugin("ngram")` sends `index_type: "PLUGIN"` with
`plugin_type: "NGRAM"`.

---------

Co-authored-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
BHAWESHBHASKAR
2026-12-01 21:39:01 +08:00
committed by GitHub
co-authored by Xuanwo
parent 144c07cee3
commit fb853bae75
5 changed files with 92 additions and 2 deletions
+28
View File
@@ -294,6 +294,34 @@ using an underlying bitmap index.
***
### ngram()
```ts
static ngram(): Index
```
Create an NGram index.
An `NGram` index is a scalar index on a UTF-8 string column that accelerates
substring filters such as `contains(col, 'needle')`, along with some `LIKE`
and regular-expression predicates. It tokenizes values into overlapping
character trigrams and narrows a scan to the rows that share the query's
trigrams. The exact predicate is then evaluated on those candidates.
Queries shorter than three characters fall back to a scan.
#### Returns
[`Index`](Index.md)
#### Example
```ts
await table.createIndex("text", { config: Index.ngram() });
const rows = await table.query().where("contains(text, 'needle')").toArray();
```
***
### plugin()
```ts