mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
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:
+9
-1
@@ -5,7 +5,7 @@ use std::sync::Mutex;
|
||||
|
||||
use lancedb::index::Index as LanceDbIndex;
|
||||
use lancedb::index::scalar::{
|
||||
BTreeIndexBuilder, BloomFilterIndexBuilder, FmIndexBuilder, FtsIndexBuilder,
|
||||
BTreeIndexBuilder, BloomFilterIndexBuilder, FmIndexBuilder, FtsIndexBuilder, NGramIndexBuilder,
|
||||
PluginIndexBuilder, RTreeIndexBuilder, ZoneMapIndexBuilder,
|
||||
};
|
||||
use lancedb::index::vector::{
|
||||
@@ -377,6 +377,14 @@ impl Index {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create an NGram index using the defaults in [`NGramIndexBuilder`].
|
||||
#[napi(factory)]
|
||||
pub fn ngram() -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(Some(LanceDbIndex::NGram(NGramIndexBuilder::default()))),
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(factory)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn fts(
|
||||
|
||||
Reference in New Issue
Block a user