mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-04 10:52:56 +00:00
feat(nodejs): add bitmap and label list index types in nodejs (#1532)
This commit is contained in:
@@ -31,7 +31,9 @@ import {
|
||||
Float64,
|
||||
Int32,
|
||||
Int64,
|
||||
List,
|
||||
Schema,
|
||||
Utf8,
|
||||
makeArrowTable,
|
||||
} from "../lancedb/arrow";
|
||||
import {
|
||||
@@ -331,6 +333,7 @@ describe("When creating an index", () => {
|
||||
const schema = new Schema([
|
||||
new Field("id", new Int32(), true),
|
||||
new Field("vec", new FixedSizeList(32, new Field("item", new Float32()))),
|
||||
new Field("tags", new List(new Field("item", new Utf8(), true))),
|
||||
]);
|
||||
let tbl: Table;
|
||||
let queryVec: number[];
|
||||
@@ -346,6 +349,7 @@ describe("When creating an index", () => {
|
||||
vec: Array(32)
|
||||
.fill(1)
|
||||
.map(() => Math.random()),
|
||||
tags: ["tag1", "tag2", "tag3"],
|
||||
})),
|
||||
{
|
||||
schema,
|
||||
@@ -428,6 +432,22 @@ describe("When creating an index", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("create a bitmap index", async () => {
|
||||
await tbl.createIndex("id", {
|
||||
config: Index.bitmap(),
|
||||
});
|
||||
const indexDir = path.join(tmpDir.name, "test.lance", "_indices");
|
||||
expect(fs.readdirSync(indexDir)).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("create a label list index", async () => {
|
||||
await tbl.createIndex("tags", {
|
||||
config: Index.labelList(),
|
||||
});
|
||||
const indexDir = path.join(tmpDir.name, "test.lance", "_indices");
|
||||
expect(fs.readdirSync(indexDir)).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("should be able to get index stats", async () => {
|
||||
await tbl.createIndex("id");
|
||||
|
||||
|
||||
@@ -176,6 +176,29 @@ export class Index {
|
||||
return new Index(LanceDbIndex.btree());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a bitmap index.
|
||||
*
|
||||
* A `Bitmap` index stores a bitmap for each distinct value in the column for every row.
|
||||
*
|
||||
* This index works best for low-cardinality columns, where the number of unique values
|
||||
* is small (i.e., less than a few hundreds).
|
||||
*/
|
||||
static bitmap() {
|
||||
return new Index(LanceDbIndex.bitmap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a label list index.
|
||||
*
|
||||
* LabelList index is a scalar index that can be used on `List<T>` columns to
|
||||
* support queries with `array_contains_all` and `array_contains_any`
|
||||
* using an underlying bitmap index.
|
||||
*/
|
||||
static labelList() {
|
||||
return new Index(LanceDbIndex.labelList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a full text search index
|
||||
*
|
||||
|
||||
@@ -151,7 +151,7 @@ export class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery>
|
||||
query: string,
|
||||
options?: Partial<FullTextSearchOptions>,
|
||||
): this {
|
||||
let columns = null;
|
||||
let columns: string[] | null = null;
|
||||
if (options) {
|
||||
if (typeof options.columns === "string") {
|
||||
columns = [options.columns];
|
||||
|
||||
@@ -77,6 +77,20 @@ impl Index {
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(factory)]
|
||||
pub fn bitmap() -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(Some(LanceDbIndex::Bitmap(Default::default()))),
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(factory)]
|
||||
pub fn label_list() -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(Some(LanceDbIndex::LabelList(Default::default()))),
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(factory)]
|
||||
pub fn fts() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user