Comparing version 0.11.0-beta.1 to 0.11.0
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Schema, Table as ArrowTable, type Float } from "apache-arrow"; | ||
@@ -3,0 +4,0 @@ import { type EmbeddingFunction } from "./index"; |
@@ -507,5 +507,5 @@ import { type Schema, Table as ArrowTable } from "apache-arrow"; | ||
numUnindexedRows: number | null; | ||
indexType: string | null; | ||
distanceType: string | null; | ||
completedAt: string | null; | ||
indexType: string; | ||
distanceType?: string; | ||
numIndices?: number; | ||
} | ||
@@ -512,0 +512,0 @@ /** |
@@ -18,2 +18,3 @@ "use strict"; | ||
const chai = require("chai"); | ||
const chai_1 = require("chai"); | ||
const chaiAsPromised = require("chai-as-promised"); | ||
@@ -25,3 +26,2 @@ const uuid_1 = require("uuid"); | ||
const path = require("path"); | ||
const assert = chai.assert; | ||
chai.use(chaiAsPromised); | ||
@@ -40,3 +40,3 @@ (0, mocha_1.describe)('LanceDB AWS Integration test', function () { | ||
table = await conn.openTable(tableName); | ||
assert.equal(await table.countRows(), 6); | ||
chai_1.assert.equal(await table.countRows(), 6); | ||
}); | ||
@@ -62,10 +62,10 @@ }); | ||
// there should be three dirs | ||
assert.equal(files.length, 3); | ||
assert.isTrue(files[0].isDirectory()); | ||
assert.isTrue(files[1].isDirectory()); | ||
chai_1.assert.equal(files.length, 3); | ||
chai_1.assert.isTrue(files[0].isDirectory()); | ||
chai_1.assert.isTrue(files[1].isDirectory()); | ||
fs.readdir(path.join(mirroredPath, '_transactions'), { withFileTypes: true }, (err, files) => { | ||
if (err != null) | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.txn')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.txn')); | ||
}); | ||
@@ -75,4 +75,4 @@ fs.readdir(path.join(mirroredPath, '_versions'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.manifest')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.manifest')); | ||
}); | ||
@@ -82,4 +82,4 @@ fs.readdir(path.join(mirroredPath, 'data'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.lance')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.lance')); | ||
}); | ||
@@ -93,6 +93,6 @@ }); | ||
// there should be four dirs | ||
assert.equal(files.length, 4); | ||
assert.isTrue(files[0].isDirectory()); | ||
assert.isTrue(files[1].isDirectory()); | ||
assert.isTrue(files[2].isDirectory()); | ||
chai_1.assert.equal(files.length, 4); | ||
chai_1.assert.isTrue(files[0].isDirectory()); | ||
chai_1.assert.isTrue(files[1].isDirectory()); | ||
chai_1.assert.isTrue(files[2].isDirectory()); | ||
// Two TXs now | ||
@@ -102,5 +102,5 @@ fs.readdir(path.join(mirroredPath, '_transactions'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 2); | ||
assert.isTrue(files[0].name.endsWith('.txn')); | ||
assert.isTrue(files[1].name.endsWith('.txn')); | ||
chai_1.assert.equal(files.length, 2); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.txn')); | ||
chai_1.assert.isTrue(files[1].name.endsWith('.txn')); | ||
}); | ||
@@ -110,4 +110,4 @@ fs.readdir(path.join(mirroredPath, 'data'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.lance')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.lance')); | ||
}); | ||
@@ -117,10 +117,10 @@ fs.readdir(path.join(mirroredPath, '_indices'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].isDirectory()); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].isDirectory()); | ||
fs.readdir(path.join(mirroredPath, '_indices', files[0].name), { withFileTypes: true }, (err, files) => { | ||
if (err != null) | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].isFile()); | ||
assert.isTrue(files[0].name.endsWith('.idx')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].isFile()); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.idx')); | ||
}); | ||
@@ -135,8 +135,8 @@ }); | ||
// there should be five dirs | ||
assert.equal(files.length, 5); | ||
assert.isTrue(files[0].isDirectory()); | ||
assert.isTrue(files[1].isDirectory()); | ||
assert.isTrue(files[2].isDirectory()); | ||
assert.isTrue(files[3].isDirectory()); | ||
assert.isTrue(files[4].isDirectory()); | ||
chai_1.assert.equal(files.length, 5); | ||
chai_1.assert.isTrue(files[0].isDirectory()); | ||
chai_1.assert.isTrue(files[1].isDirectory()); | ||
chai_1.assert.isTrue(files[2].isDirectory()); | ||
chai_1.assert.isTrue(files[3].isDirectory()); | ||
chai_1.assert.isTrue(files[4].isDirectory()); | ||
// Three TXs now | ||
@@ -146,5 +146,5 @@ fs.readdir(path.join(mirroredPath, '_transactions'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 3); | ||
assert.isTrue(files[0].name.endsWith('.txn')); | ||
assert.isTrue(files[1].name.endsWith('.txn')); | ||
chai_1.assert.equal(files.length, 3); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.txn')); | ||
chai_1.assert.isTrue(files[1].name.endsWith('.txn')); | ||
}); | ||
@@ -154,4 +154,4 @@ fs.readdir(path.join(mirroredPath, 'data'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.lance')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.lance')); | ||
}); | ||
@@ -161,10 +161,10 @@ fs.readdir(path.join(mirroredPath, '_indices'), { withFileTypes: true }, (err, files) => { | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].isDirectory()); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].isDirectory()); | ||
fs.readdir(path.join(mirroredPath, '_indices', files[0].name), { withFileTypes: true }, (err, files) => { | ||
if (err != null) | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].isFile()); | ||
assert.isTrue(files[0].name.endsWith('.idx')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].isFile()); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.idx')); | ||
}); | ||
@@ -175,4 +175,4 @@ }); | ||
throw err; | ||
assert.equal(files.length, 1); | ||
assert.isTrue(files[0].name.endsWith('.arrow')); | ||
chai_1.assert.equal(files.length, 1); | ||
chai_1.assert.isTrue(files[0].name.endsWith('.arrow')); | ||
}); | ||
@@ -179,0 +179,0 @@ }); |
import { type ResponseType } from 'axios'; | ||
import { type Table as ArrowTable } from 'apache-arrow'; | ||
import { type RemoteResponse, type RemoteRequest } from '../middleware'; | ||
import type { MetricType } from '..'; | ||
interface HttpLancedbClientMiddleware { | ||
@@ -15,3 +16,3 @@ onRemoteRequest(req: RemoteRequest, next: (req: RemoteRequest) => Promise<RemoteResponse>): Promise<RemoteResponse>; | ||
get uri(): string; | ||
search(tableName: string, vector: number[], k: number, nprobes: number, prefilter: boolean, refineFactor?: number, columns?: string[], filter?: string, fastSearch?: boolean): Promise<ArrowTable<any>>; | ||
search(tableName: string, vector: number[], k: number, nprobes: number, prefilter: boolean, refineFactor?: number, columns?: string[], filter?: string, metricType?: MetricType, fastSearch?: boolean): Promise<ArrowTable<any>>; | ||
/** | ||
@@ -18,0 +19,0 @@ * Sent GET request. |
@@ -95,3 +95,3 @@ "use strict"; | ||
} | ||
async search(tableName, vector, k, nprobes, prefilter, refineFactor, columns, filter, fastSearch) { | ||
async search(tableName, vector, k, nprobes, prefilter, refineFactor, columns, filter, metricType, fastSearch) { | ||
const result = await this.post(`/v1/table/${tableName}/query/`, { | ||
@@ -101,6 +101,7 @@ vector, | ||
nprobes, | ||
refineFactor, | ||
refine_factor: refineFactor, | ||
columns, | ||
filter, | ||
prefilter, | ||
metric: metricType, | ||
fast_search: fastSearch | ||
@@ -107,0 +108,0 @@ }, undefined, undefined, 'arraybuffer'); |
@@ -164,3 +164,3 @@ "use strict"; | ||
} | ||
const data = await this._client.search(this._name, queryVector, this._limit, this._nprobes, this._prefilter, this._refineFactor, this._select, this._filter, this._fastSearch); | ||
const data = await this._client.search(this._name, queryVector, this._limit, this._nprobes, this._prefilter, this._refineFactor, this._select, this._filter, this._metricType, this._fastSearch); | ||
return data.toArray().map((entry) => { | ||
@@ -385,4 +385,3 @@ const newObject = {}; | ||
indexType: body?.index_type, | ||
distanceType: body?.distance_type, | ||
completedAt: body?.completed_at | ||
distanceType: body?.distance_type | ||
}; | ||
@@ -389,0 +388,0 @@ } |
@@ -18,2 +18,3 @@ "use strict"; | ||
const temp_1 = require("temp"); | ||
const chai_1 = require("chai"); | ||
const chai = require("chai"); | ||
@@ -24,4 +25,2 @@ const chaiAsPromised = require("chai-as-promised"); | ||
const apache_arrow_1 = require("apache-arrow"); | ||
const expect = chai.expect; | ||
const assert = chai.assert; | ||
chai.use(chaiAsPromised); | ||
@@ -33,3 +32,3 @@ (0, mocha_1.describe)("LanceDB client", function () { | ||
const con = await lancedb.connect(uri); | ||
assert.equal(con.uri, uri); | ||
chai_1.assert.equal(con.uri, uri); | ||
}); | ||
@@ -39,3 +38,3 @@ it("should accept an options object", async function () { | ||
const con = await lancedb.connect({ uri }); | ||
assert.equal(con.uri, uri); | ||
chai_1.assert.equal(con.uri, uri); | ||
}); | ||
@@ -52,3 +51,3 @@ it("should accept custom aws credentials", async function () { | ||
}); | ||
assert.equal(con.uri, uri); | ||
chai_1.assert.equal(con.uri, uri); | ||
}); | ||
@@ -65,3 +64,3 @@ it("should accept custom storage options", async function () { | ||
}); | ||
assert.equal(con.uri, uri); | ||
chai_1.assert.equal(con.uri, uri); | ||
}); | ||
@@ -71,3 +70,3 @@ it("should return the existing table names", async function () { | ||
const con = await lancedb.connect(uri); | ||
assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
}); | ||
@@ -83,3 +82,3 @@ it("read consistency level", async function () { | ||
const table2 = await db2.openTable("vectors"); | ||
assert.equal(await table2.countRows(), 2); | ||
chai_1.assert.equal(await table2.countRows(), 2); | ||
await table1.add([ | ||
@@ -94,3 +93,3 @@ { | ||
]); | ||
assert.equal(await table2.countRows(), 3); | ||
chai_1.assert.equal(await table2.countRows(), 3); | ||
}); | ||
@@ -103,3 +102,3 @@ }); | ||
const table = await con.openTable("vectors"); | ||
assert.equal(table.name, "vectors"); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
}); | ||
@@ -111,7 +110,7 @@ it("execute a query", async function () { | ||
const results = await table.search([0.1, 0.3]).execute(); | ||
assert.equal(results.length, 2); | ||
assert.equal(results[0].price, 10); | ||
chai_1.assert.equal(results.length, 2); | ||
chai_1.assert.equal(results[0].price, 10); | ||
const vector = results[0].vector; | ||
assert.approximately(vector[0], 0.0, 0.2); | ||
assert.approximately(vector[0], 0.1, 0.3); | ||
chai_1.assert.approximately(vector[0], 0.0, 0.2); | ||
chai_1.assert.approximately(vector[0], 0.1, 0.3); | ||
}); | ||
@@ -123,7 +122,7 @@ it("limits # of results", async function () { | ||
let results = await table.search([0.1, 0.3]).limit(1).execute(); | ||
assert.equal(results.length, 1); | ||
assert.equal(results[0].id, 1); | ||
chai_1.assert.equal(results.length, 1); | ||
chai_1.assert.equal(results[0].id, 1); | ||
// there is a default limit if unspecified | ||
results = await table.search([0.1, 0.3]).execute(); | ||
assert.equal(results.length, 10); | ||
chai_1.assert.equal(results.length, 10); | ||
}); | ||
@@ -133,3 +132,3 @@ it("uses a filter / where clause without vector search", async function () { | ||
const assertResults = (results) => { | ||
assert.equal(results.length, 50); | ||
chai_1.assert.equal(results.length, 50); | ||
}; | ||
@@ -144,3 +143,3 @@ const uri = await createTestDB(2, 100); | ||
// Should reject a bad filter | ||
await expect(table.filter("id % 2 = 0 AND").execute()).to.be.rejectedWith(/.*sql parser error: Expected an expression:, found: EOF.*/); | ||
await (0, chai_1.expect)(table.filter("id % 2 = 0 AND").execute()).to.be.rejectedWith(/.*sql parser error: .*/); | ||
}); | ||
@@ -150,4 +149,4 @@ it("uses a filter / where clause", async function () { | ||
const assertResults = (results) => { | ||
assert.equal(results.length, 1); | ||
assert.equal(results[0].id, 2); | ||
chai_1.assert.equal(results.length, 1); | ||
chai_1.assert.equal(results[0].id, 2); | ||
}; | ||
@@ -180,3 +179,3 @@ const uri = await createTestDB(); | ||
.execute(); | ||
assert.isTrue(results.length < 10); | ||
chai_1.assert.isTrue(results.length < 10); | ||
// pre filter should return exactly the limit | ||
@@ -189,3 +188,3 @@ results = await table | ||
.execute(); | ||
assert.isTrue(results.length === 10); | ||
chai_1.assert.isTrue(results.length === 10); | ||
}); | ||
@@ -204,3 +203,3 @@ it("should allow creation and use of scalar indices", async function () { | ||
.execute(); | ||
assert.isTrue(results.length === 10); | ||
chai_1.assert.isTrue(results.length === 10); | ||
}); | ||
@@ -215,10 +214,10 @@ it("select only a subset of columns", async function () { | ||
.execute(); | ||
assert.equal(results.length, 2); | ||
chai_1.assert.equal(results.length, 2); | ||
// vector and _distance are always returned | ||
assert.isDefined(results[0].vector); | ||
assert.isDefined(results[0]._distance); | ||
assert.isDefined(results[0].is_active); | ||
assert.isUndefined(results[0].id); | ||
assert.isUndefined(results[0].name); | ||
assert.isUndefined(results[0].price); | ||
chai_1.assert.isDefined(results[0].vector); | ||
chai_1.assert.isDefined(results[0]._distance); | ||
chai_1.assert.isDefined(results[0].is_active); | ||
chai_1.assert.isUndefined(results[0].id); | ||
chai_1.assert.isUndefined(results[0].name); | ||
chai_1.assert.isUndefined(results[0].price); | ||
}); | ||
@@ -238,4 +237,4 @@ }); | ||
}); | ||
assert.equal(table.name, "vectors"); | ||
assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
}); | ||
@@ -268,4 +267,4 @@ it("create a table with a schema and records", async function () { | ||
}); | ||
assert.equal(table.name, "vectors"); | ||
assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
}); | ||
@@ -284,4 +283,4 @@ it("create a table with a empty data array", async function () { | ||
}); | ||
assert.equal(table.name, "vectors"); | ||
assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
}); | ||
@@ -299,6 +298,6 @@ it("create a table from an Arrow Table", async function () { | ||
}); | ||
assert.equal(table.name, "vectors"); | ||
assert.equal(await table.countRows(), 10); | ||
assert.equal(await table.countRows("vector IS NULL"), 0); | ||
assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
chai_1.assert.equal(await table.countRows(), 10); | ||
chai_1.assert.equal(await table.countRows("vector IS NULL"), 0); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["vectors"]); | ||
}); | ||
@@ -318,4 +317,4 @@ it("creates a new table from javascript objects", async function () { | ||
const table = await con.createTable(tableName, data); | ||
assert.equal(table.name, tableName); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(table.name, tableName); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
}); | ||
@@ -341,8 +340,8 @@ it("creates a new table from javascript objects with variable sized list", async function () { | ||
const table = (await con.createTable(tableName, data)); | ||
assert.equal(table.name, tableName); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(table.name, tableName); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
const rs = await table.filter("id>1").execute(); | ||
assert.equal(rs.length, 1); | ||
assert.deepEqual(rs[0].list_of_str, ["x", "y"]); | ||
assert.isTrue(rs[0].list_of_num instanceof Array); | ||
chai_1.assert.equal(rs.length, 1); | ||
chai_1.assert.deepEqual(rs[0].list_of_str, ["x", "y"]); | ||
chai_1.assert.isTrue(rs[0].list_of_num instanceof Array); | ||
}); | ||
@@ -363,7 +362,7 @@ it("create table from arrow table", async () => { | ||
const table = await con.createTable("f16", data); | ||
assert.equal(table.name, "f16"); | ||
assert.equal(await table.countRows(), total); | ||
assert.equal(await table.countRows("id < 5"), 5); | ||
assert.deepEqual(await con.tableNames(), ["f16"]); | ||
assert.deepEqual(await table.schema, schema); | ||
chai_1.assert.equal(table.name, "f16"); | ||
chai_1.assert.equal(await table.countRows(), total); | ||
chai_1.assert.equal(await table.countRows("id < 5"), 5); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["f16"]); | ||
chai_1.assert.deepEqual(await table.schema, schema); | ||
await table.createIndex({ | ||
@@ -376,6 +375,6 @@ num_sub_vectors: 2, | ||
const r = await table.search(q).limit(5).execute(); | ||
assert.equal(r.length, 5); | ||
chai_1.assert.equal(r.length, 5); | ||
r.forEach((v) => { | ||
assert.equal(Object.prototype.hasOwnProperty.call(v, "vector"), true); | ||
assert.equal(v.vector?.constructor.name, "Array", "vector column is list of floats"); | ||
chai_1.assert.equal(Object.prototype.hasOwnProperty.call(v, "vector"), true); | ||
chai_1.assert.equal(v.vector?.constructor.name, "Array", "vector column is list of floats"); | ||
}); | ||
@@ -405,8 +404,8 @@ }).timeout(120000); | ||
]; | ||
await expect(con.createTable(tableName, newData)).to.be.rejectedWith(Error, "already exists"); | ||
await (0, chai_1.expect)(con.createTable(tableName, newData)).to.be.rejectedWith(Error, "already exists"); | ||
const table = await con.createTable(tableName, newData, { | ||
writeMode: index_1.WriteMode.Overwrite | ||
}); | ||
assert.equal(table.name, tableName); | ||
assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(table.name, tableName); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
}); | ||
@@ -431,3 +430,3 @@ it("appends records to an existing table ", async function () { | ||
const table = await con.createTable("vectors", data); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
const dataAdd = [ | ||
@@ -448,3 +447,3 @@ { | ||
await table.add(dataAdd); | ||
assert.equal(await table.countRows(), 4); | ||
chai_1.assert.equal(await table.countRows(), 4); | ||
}); | ||
@@ -484,3 +483,3 @@ it("appends records with fields in a different order", async function () { | ||
await table.add(dataAdd); | ||
assert.equal(await table.countRows(), 4); | ||
chai_1.assert.equal(await table.countRows(), 4); | ||
}); | ||
@@ -491,3 +490,3 @@ it("overwrite all records in a table", async function () { | ||
const table = await con.openTable("vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
const dataOver = [ | ||
@@ -506,3 +505,3 @@ { | ||
await table.overwrite(dataOver); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
}); | ||
@@ -525,4 +524,4 @@ it("can merge insert records into the table", async function () { | ||
}); | ||
assert.equal(await table.countRows(), 3); | ||
assert.equal(await table.countRows("age = 2"), 1); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(await table.countRows("age = 2"), 1); | ||
// conditional update | ||
@@ -536,5 +535,5 @@ newData = [ | ||
}); | ||
assert.equal(await table.countRows(), 3); | ||
assert.equal(await table.countRows("age = 1"), 1); | ||
assert.equal(await table.countRows("age = 3"), 1); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(await table.countRows("age = 1"), 1); | ||
chai_1.assert.equal(await table.countRows("age = 3"), 1); | ||
newData = [ | ||
@@ -548,4 +547,4 @@ { id: 3, age: 4 }, | ||
}); | ||
assert.equal(await table.countRows(), 4); | ||
assert.equal((await table.filter("age = 4").execute()).length, 2); | ||
chai_1.assert.equal(await table.countRows(), 4); | ||
chai_1.assert.equal((await table.filter("age = 4").execute()).length, 2); | ||
newData = [{ id: 5, age: 5 }]; | ||
@@ -557,3 +556,3 @@ await table.mergeInsert("id", newData, { | ||
}); | ||
assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
await table.mergeInsert("id", newData, { | ||
@@ -564,3 +563,3 @@ whenNotMatchedInsertAll: true, | ||
}); | ||
assert.equal(await table.countRows(), 1); | ||
chai_1.assert.equal(await table.countRows(), 1); | ||
}); | ||
@@ -571,3 +570,3 @@ it("can update records in the table", async function () { | ||
const table = await con.openTable("vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
await table.update({ | ||
@@ -578,4 +577,4 @@ where: "price = 10", | ||
const results = await table.search([0.1, 0.2]).execute(); | ||
assert.equal(results[0].price, 100); | ||
assert.equal(results[1].price, 11); | ||
chai_1.assert.equal(results[0].price, 100); | ||
chai_1.assert.equal(results[1].price, 11); | ||
}); | ||
@@ -586,3 +585,3 @@ it("can update the records using a literal value", async function () { | ||
const table = await con.openTable("vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
await table.update({ | ||
@@ -593,4 +592,4 @@ where: "price = 10", | ||
const results = await table.search([0.1, 0.2]).execute(); | ||
assert.equal(results[0].price, 100); | ||
assert.equal(results[1].price, 11); | ||
chai_1.assert.equal(results[0].price, 100); | ||
chai_1.assert.equal(results[1].price, 11); | ||
}); | ||
@@ -601,7 +600,7 @@ it("can update every record in the table", async function () { | ||
const table = await con.openTable("vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
await table.update({ valuesSql: { price: "100" } }); | ||
const results = await table.search([0.1, 0.2]).execute(); | ||
assert.equal(results[0].price, 100); | ||
assert.equal(results[1].price, 100); | ||
chai_1.assert.equal(results[0].price, 100); | ||
chai_1.assert.equal(results[1].price, 100); | ||
}); | ||
@@ -612,5 +611,5 @@ it("can delete records from a table", async function () { | ||
const table = await con.openTable("vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
await table.delete("price = 10"); | ||
assert.equal(await table.countRows(), 1); | ||
chai_1.assert.equal(await table.countRows(), 1); | ||
}); | ||
@@ -634,5 +633,5 @@ it("can manually provide embedding columns", async function () { | ||
}); | ||
assert.equal(table.name, "embed_vectors"); | ||
chai_1.assert.equal(table.name, "embed_vectors"); | ||
table = await con.openTable("embed_vectors"); | ||
assert.equal(await table.countRows(), 2); | ||
chai_1.assert.equal(await table.countRows(), 2); | ||
}); | ||
@@ -656,3 +655,3 @@ it("will error if no implementation for embedding column found", async function () { | ||
}); | ||
await assert.isRejected(table); | ||
await chai_1.assert.isRejected(table); | ||
}); | ||
@@ -672,3 +671,3 @@ }); | ||
const result = await table.search(Array(128).fill(0.1)).execute(); | ||
assert.isEmpty(result); | ||
chai_1.assert.isEmpty(result); | ||
}); | ||
@@ -691,3 +690,3 @@ }); | ||
const result = await table.search(Array(128).fill(0.1)).execute(); | ||
assert.isEmpty(result); | ||
chai_1.assert.isEmpty(result); | ||
}); | ||
@@ -720,3 +719,3 @@ }); | ||
// Replace should fail if the index already exists | ||
await expect(table.createIndex({ | ||
await (0, chai_1.expect)(table.createIndex({ | ||
type: "ivf_pq", | ||
@@ -749,3 +748,3 @@ column: "vector", | ||
}); | ||
await expect(createIndex).to.be.rejectedWith("index cannot be created on the column `name` which has data type Utf8"); | ||
await (0, chai_1.expect)(createIndex).to.be.rejectedWith("index cannot be created on the column `name` which has data type Utf8"); | ||
}); | ||
@@ -763,3 +762,3 @@ it("it should fail when num_partitions is invalid", async function () { | ||
}); | ||
await expect(createIndex).to.be.rejectedWith("num_partitions: must be > 0"); | ||
await (0, chai_1.expect)(createIndex).to.be.rejectedWith("num_partitions: must be > 0"); | ||
}); | ||
@@ -778,10 +777,13 @@ it("should be able to list index and stats", async function () { | ||
const indices = await table.listIndices(); | ||
expect(indices).to.have.lengthOf(1); | ||
expect(indices[0].name).to.equal("vector_idx"); | ||
expect(indices[0].uuid).to.not.be.equal(undefined); | ||
expect(indices[0].columns).to.have.lengthOf(1); | ||
expect(indices[0].columns[0]).to.equal("vector"); | ||
const stats = await table.indexStats(indices[0].uuid); | ||
expect(stats.numIndexedRows).to.equal(300); | ||
expect(stats.numUnindexedRows).to.equal(0); | ||
(0, chai_1.expect)(indices).to.have.lengthOf(1); | ||
(0, chai_1.expect)(indices[0].name).to.equal("vector_idx"); | ||
(0, chai_1.expect)(indices[0].uuid).to.not.be.equal(undefined); | ||
(0, chai_1.expect)(indices[0].columns).to.have.lengthOf(1); | ||
(0, chai_1.expect)(indices[0].columns[0]).to.equal("vector"); | ||
const stats = await table.indexStats(indices[0].name); | ||
(0, chai_1.expect)(stats.numIndexedRows).to.equal(300); | ||
(0, chai_1.expect)(stats.numUnindexedRows).to.equal(0); | ||
(0, chai_1.expect)(stats.indexType).to.equal("IVF_PQ"); | ||
(0, chai_1.expect)(stats.distanceType).to.equal("l2"); | ||
(0, chai_1.expect)(stats.numIndices).to.equal(1); | ||
}).timeout(50000); | ||
@@ -820,3 +822,3 @@ }); | ||
const results = await table.search("foo").execute(); | ||
assert.equal(results.length, 2); | ||
chai_1.assert.equal(results.length, 2); | ||
}); | ||
@@ -834,5 +836,5 @@ it("should create embeddings for Arrow Table", async function () { | ||
}); | ||
assert.equal(table.name, "vectors"); | ||
chai_1.assert.equal(table.name, "vectors"); | ||
const results = await table.search("foo").execute(); | ||
assert.equal(results.length, 2); | ||
chai_1.assert.equal(results.length, 2); | ||
}); | ||
@@ -855,3 +857,3 @@ }); | ||
const schema = await table.schema; | ||
assert.deepEqual(expectedSchema, schema); | ||
chai_1.assert.deepEqual(expectedSchema, schema); | ||
}); | ||
@@ -873,3 +875,3 @@ }); | ||
catch (err) { | ||
expect(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
(0, chai_1.expect)(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
} | ||
@@ -884,3 +886,3 @@ // POST | ||
catch (err) { | ||
expect(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
(0, chai_1.expect)(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
} | ||
@@ -908,3 +910,3 @@ // Search | ||
catch (err) { | ||
expect(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
(0, chai_1.expect)(err).to.have.property("message", "Network Error: getaddrinfo ENOTFOUND test-1234.asdfasfasfdf.api.lancedb.com"); | ||
} | ||
@@ -922,7 +924,7 @@ }); | ||
.nprobes(20); | ||
assert.equal(query._limit, 1); | ||
assert.equal(query._metricType, index_1.MetricType.Cosine); | ||
assert.equal(query._refineFactor, 100); | ||
assert.equal(query._nprobes, 20); | ||
assert.deepEqual(query._select, ["a", "b"]); | ||
chai_1.assert.equal(query._limit, 1); | ||
chai_1.assert.equal(query._metricType, index_1.MetricType.Cosine); | ||
chai_1.assert.equal(query._refineFactor, 100); | ||
chai_1.assert.equal(query._nprobes, 20); | ||
chai_1.assert.deepEqual(query._select, ["a", "b"]); | ||
}); | ||
@@ -968,5 +970,5 @@ }); | ||
await con.createTable("t2", data); | ||
assert.deepEqual(await con.tableNames(), ["t1", "t2"]); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["t1", "t2"]); | ||
await con.dropTable("t1"); | ||
assert.deepEqual(await con.tableNames(), ["t2"]); | ||
chai_1.assert.deepEqual(await con.tableNames(), ["t2"]); | ||
}); | ||
@@ -977,12 +979,12 @@ }); | ||
it("should not match empty object", function () { | ||
assert.equal((0, index_1.isWriteOptions)({}), false); | ||
chai_1.assert.equal((0, index_1.isWriteOptions)({}), false); | ||
}); | ||
it("should match write options", function () { | ||
assert.equal((0, index_1.isWriteOptions)({ writeMode: index_1.WriteMode.Create }), true); | ||
chai_1.assert.equal((0, index_1.isWriteOptions)({ writeMode: index_1.WriteMode.Create }), true); | ||
}); | ||
it("should match undefined write mode", function () { | ||
assert.equal((0, index_1.isWriteOptions)({ writeMode: undefined }), true); | ||
chai_1.assert.equal((0, index_1.isWriteOptions)({ writeMode: undefined }), true); | ||
}); | ||
it("should match default write options", function () { | ||
assert.equal((0, index_1.isWriteOptions)(new index_1.DefaultWriteOptions()), true); | ||
chai_1.assert.equal((0, index_1.isWriteOptions)(new index_1.DefaultWriteOptions()), true); | ||
}); | ||
@@ -1019,7 +1021,7 @@ }); | ||
}); | ||
assert.equal(compactionMetrics.fragmentsRemoved, 2); | ||
assert.equal(compactionMetrics.fragmentsAdded, 1); | ||
assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(compactionMetrics.fragmentsRemoved, 2); | ||
chai_1.assert.equal(compactionMetrics.fragmentsAdded, 1); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
await table.cleanupOldVersions(); | ||
assert.equal(await table.countRows(), 3); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
// should have no effect, but this validates the arguments are parsed. | ||
@@ -1034,5 +1036,5 @@ await table.compactFiles({ | ||
const cleanupMetrics = await table.cleanupOldVersions(0, true); | ||
assert.isAtLeast(cleanupMetrics.bytesRemoved, 1); | ||
assert.isAtLeast(cleanupMetrics.oldVersions, 1); | ||
assert.equal(await table.countRows(), 3); | ||
chai_1.assert.isAtLeast(cleanupMetrics.bytesRemoved, 1); | ||
chai_1.assert.isAtLeast(cleanupMetrics.oldVersions, 1); | ||
chai_1.assert.equal(await table.countRows(), 3); | ||
}); | ||
@@ -1056,3 +1058,3 @@ }); | ||
]); | ||
expect(await table.schema).to.deep.equal(expectedSchema); | ||
(0, chai_1.expect)(await table.schema).to.deep.equal(expectedSchema); | ||
}); | ||
@@ -1070,3 +1072,3 @@ it("can alter the columns in the schema", async function () { | ||
]); | ||
expect(await table.schema).to.deep.equal(schema); | ||
(0, chai_1.expect)(await table.schema).to.deep.equal(schema); | ||
await table.alterColumns([ | ||
@@ -1081,3 +1083,3 @@ { path: "id", rename: "new_id" }, | ||
]); | ||
expect(await table.schema).to.deep.equal(expectedSchema); | ||
(0, chai_1.expect)(await table.schema).to.deep.equal(expectedSchema); | ||
}); | ||
@@ -1092,5 +1094,5 @@ it("can drop a column from the schema", async function () { | ||
const expectedSchema = new apache_arrow_1.Schema([new apache_arrow_1.Field("id", new apache_arrow_1.Int64(), false)]); | ||
expect(await table.schema).to.deep.equal(expectedSchema); | ||
(0, chai_1.expect)(await table.schema).to.deep.equal(expectedSchema); | ||
}); | ||
}); | ||
//# sourceMappingURL=test.js.map |
{ | ||
"name": "vectordb", | ||
"version": "0.11.0-beta.1", | ||
"version": "0.11.0", | ||
"description": " Serverless, low-latency vector database for AI applications", | ||
@@ -61,3 +61,3 @@ "main": "dist/index.js", | ||
"typedoc-plugin-markdown": "^3.15.3", | ||
"typescript": "*", | ||
"typescript": "^5.1.0", | ||
"uuid": "^9.0.0" | ||
@@ -92,8 +92,8 @@ }, | ||
"optionalDependencies": { | ||
"@lancedb/vectordb-darwin-arm64": "0.4.20", | ||
"@lancedb/vectordb-darwin-x64": "0.4.20", | ||
"@lancedb/vectordb-linux-arm64-gnu": "0.4.20", | ||
"@lancedb/vectordb-linux-x64-gnu": "0.4.20", | ||
"@lancedb/vectordb-win32-x64-msvc": "0.4.20" | ||
"@lancedb/vectordb-darwin-arm64": "0.11.0", | ||
"@lancedb/vectordb-darwin-x64": "0.11.0", | ||
"@lancedb/vectordb-linux-arm64-gnu": "0.11.0", | ||
"@lancedb/vectordb-linux-x64-gnu": "0.11.0", | ||
"@lancedb/vectordb-win32-x64-msvc": "0.11.0" | ||
} | ||
} |
@@ -727,5 +727,5 @@ // Copyright 2023 Lance Developers. | ||
numUnindexedRows: number | null | ||
indexType: string | null | ||
distanceType: string | null | ||
completedAt: string | null | ||
indexType: string | ||
distanceType?: string | ||
numIndices?: number | ||
} | ||
@@ -732,0 +732,0 @@ |
@@ -17,2 +17,3 @@ // Copyright 2023 LanceDB Developers. | ||
import * as chai from 'chai' | ||
import { assert } from 'chai' | ||
import * as chaiAsPromised from 'chai-as-promised' | ||
@@ -26,3 +27,2 @@ import { v4 as uuidv4 } from 'uuid' | ||
const assert = chai.assert | ||
chai.use(chaiAsPromised) | ||
@@ -29,0 +29,0 @@ |
@@ -115,3 +115,3 @@ // Copyright 2023 LanceDB Developers. | ||
/** | ||
/** | ||
* Skip searching un-indexed data. This can make search faster, but will miss | ||
@@ -146,5 +146,5 @@ * any data that is not yet indexed. | ||
// toJSON() returns f16 array correctly | ||
newObject[key] = (entry[key] as Vector).toJSON() | ||
newObject[key] = (entry[key] as any).toJSON() | ||
} else { | ||
newObject[key] = entry[key] | ||
newObject[key] = entry[key] as any | ||
} | ||
@@ -151,0 +151,0 @@ }) |
@@ -20,2 +20,3 @@ // Copyright 2023 LanceDB Developers. | ||
import { type RemoteResponse, type RemoteRequest, Method } from '../middleware' | ||
import type { MetricType } from '..' | ||
@@ -156,2 +157,3 @@ interface HttpLancedbClientMiddleware { | ||
filter?: string, | ||
metricType?: MetricType, | ||
fastSearch?: boolean | ||
@@ -165,6 +167,7 @@ ): Promise<ArrowTable<any>> { | ||
nprobes, | ||
refineFactor, | ||
refine_factor: refineFactor, | ||
columns, | ||
filter, | ||
prefilter, | ||
metric: metricType, | ||
fast_search: fastSearch | ||
@@ -171,0 +174,0 @@ }, |
@@ -242,2 +242,3 @@ // Copyright 2023 LanceDB Developers. | ||
(this as any)._filter, | ||
(this as any)._metricType, | ||
(this as any)._fastSearch | ||
@@ -250,5 +251,5 @@ ) | ||
if (entry[key] instanceof Vector) { | ||
newObject[key] = (entry[key] as Vector).toArray() | ||
newObject[key] = (entry[key] as any).toArray() | ||
} else { | ||
newObject[key] = entry[key] | ||
newObject[key] = entry[key] as any | ||
} | ||
@@ -530,4 +531,3 @@ }) | ||
indexType: body?.index_type, | ||
distanceType: body?.distance_type, | ||
completedAt: body?.completed_at | ||
distanceType: body?.distance_type | ||
} | ||
@@ -534,0 +534,0 @@ } |
@@ -17,2 +17,3 @@ // Copyright 2023 LanceDB Developers. | ||
import { track } from "temp"; | ||
import { assert, expect } from 'chai' | ||
import * as chai from "chai"; | ||
@@ -48,4 +49,2 @@ import * as chaiAsPromised from "chai-as-promised"; | ||
const expect = chai.expect; | ||
const assert = chai.assert; | ||
chai.use(chaiAsPromised); | ||
@@ -174,3 +173,3 @@ | ||
await expect(table.filter("id % 2 = 0 AND").execute()).to.be.rejectedWith( | ||
/.*sql parser error: Expected an expression:, found: EOF.*/ | ||
/.*sql parser error: .*/ | ||
); | ||
@@ -894,5 +893,8 @@ }); | ||
const stats = await table.indexStats(indices[0].uuid); | ||
const stats = await table.indexStats(indices[0].name); | ||
expect(stats.numIndexedRows).to.equal(300); | ||
expect(stats.numUnindexedRows).to.equal(0); | ||
expect(stats.indexType).to.equal("IVF_PQ"); | ||
expect(stats.distanceType).to.equal("l2"); | ||
expect(stats.numIndices).to.equal(1); | ||
}).timeout(50_000); | ||
@@ -899,0 +901,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
539244
10651