mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-07 12:22:59 +00:00
feat: support binary vector and IVF_FLAT in TypeScript (#2221)
resolve #2218 --------- Signed-off-by: BubbleCal <bubble-cal@outlook.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
Int64,
|
||||
List,
|
||||
Schema,
|
||||
Uint8,
|
||||
Utf8,
|
||||
makeArrowTable,
|
||||
} from "../lancedb/arrow";
|
||||
@@ -740,6 +741,38 @@ describe("When creating an index", () => {
|
||||
expect(stats).toBeUndefined();
|
||||
});
|
||||
|
||||
test("create ivf_flat with binary vectors", async () => {
|
||||
const db = await connect(tmpDir.name);
|
||||
const binarySchema = new Schema([
|
||||
new Field("id", new Int32(), true),
|
||||
new Field("vec", new FixedSizeList(32, new Field("item", new Uint8()))),
|
||||
]);
|
||||
const tbl = await db.createTable(
|
||||
"binary",
|
||||
makeArrowTable(
|
||||
Array(300)
|
||||
.fill(1)
|
||||
.map((_, i) => ({
|
||||
id: i,
|
||||
vec: Array(32)
|
||||
.fill(1)
|
||||
.map(() => Math.floor(Math.random() * 255)),
|
||||
})),
|
||||
{ schema: binarySchema },
|
||||
),
|
||||
);
|
||||
await tbl.createIndex("vec", {
|
||||
config: Index.ivfFlat({ numPartitions: 10, distanceType: "hamming" }),
|
||||
});
|
||||
|
||||
// query with binary vectors
|
||||
const queryVec = Array(32)
|
||||
.fill(1)
|
||||
.map(() => Math.floor(Math.random() * 255));
|
||||
const rst = await tbl.query().limit(5).nearestTo(queryVec).toArrow();
|
||||
expect(rst.numRows).toBe(5);
|
||||
});
|
||||
|
||||
// TODO: Move this test to the query API test (making sure we can reject queries
|
||||
// when the dimension is incorrect)
|
||||
test("two columns with different dimensions", async () => {
|
||||
|
||||
Reference in New Issue
Block a user