@lancedb/lancedb 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +3 -3
- package/biome.json +19 -3
- package/dist/arrow.d.ts +41 -8
- package/dist/arrow.js +4 -4
- package/dist/connection.d.ts +49 -29
- package/dist/connection.js +21 -73
- package/dist/embedding/embedding_function.d.ts +9 -1
- package/dist/embedding/embedding_function.js +6 -0
- package/dist/embedding/openai.d.ts +6 -5
- package/dist/embedding/openai.js +4 -2
- package/dist/embedding/registry.d.ts +6 -11
- package/dist/index.d.ts +51 -3
- package/dist/index.js +28 -4
- package/dist/merge.d.ts +54 -0
- package/dist/merge.js +64 -0
- package/dist/native.d.ts +29 -3
- package/dist/native.js +26 -9
- package/dist/query.d.ts +33 -10
- package/dist/query.js +100 -13
- package/dist/remote/client.d.ts +28 -0
- package/dist/remote/client.js +172 -0
- package/dist/remote/connection.d.ts +25 -0
- package/dist/remote/connection.js +110 -0
- package/dist/remote/index.d.ts +3 -0
- package/dist/remote/index.js +9 -0
- package/dist/remote/table.d.ts +42 -0
- package/dist/remote/table.js +179 -0
- package/dist/sanitize.d.ts +3 -2
- package/dist/sanitize.js +55 -1
- package/dist/table.d.ts +105 -30
- package/dist/table.js +94 -237
- package/dist/util.d.ts +14 -0
- package/dist/util.js +65 -0
- package/examples/ann_indexes.ts +49 -0
- package/examples/basic.ts +149 -0
- package/examples/embedding.ts +83 -0
- package/examples/filtering.ts +34 -0
- package/examples/jsconfig.json +27 -0
- package/examples/package-lock.json +79 -0
- package/examples/package.json +18 -0
- package/examples/search.ts +37 -0
- package/lancedb/arrow.ts +80 -23
- package/lancedb/connection.ts +107 -92
- package/lancedb/embedding/embedding_function.ts +12 -1
- package/lancedb/embedding/openai.ts +11 -6
- package/lancedb/embedding/registry.ts +34 -22
- package/lancedb/index.ts +101 -2
- package/lancedb/merge.ts +70 -0
- package/lancedb/query.ts +114 -28
- package/lancedb/remote/client.ts +221 -0
- package/lancedb/remote/connection.ts +201 -0
- package/lancedb/remote/index.ts +3 -0
- package/lancedb/remote/table.ts +226 -0
- package/lancedb/sanitize.ts +73 -1
- package/lancedb/table.ts +320 -132
- package/lancedb/util.ts +69 -0
- package/native.d.ts +208 -0
- package/nodejs-artifacts/arrow.d.ts +41 -8
- package/nodejs-artifacts/arrow.js +4 -4
- package/nodejs-artifacts/connection.d.ts +49 -29
- package/nodejs-artifacts/connection.js +21 -73
- package/nodejs-artifacts/embedding/embedding_function.d.ts +9 -1
- package/nodejs-artifacts/embedding/embedding_function.js +6 -0
- package/nodejs-artifacts/embedding/openai.d.ts +6 -5
- package/nodejs-artifacts/embedding/openai.js +4 -2
- package/nodejs-artifacts/embedding/registry.d.ts +6 -11
- package/nodejs-artifacts/index.d.ts +51 -3
- package/nodejs-artifacts/index.js +28 -4
- package/nodejs-artifacts/merge.d.ts +54 -0
- package/nodejs-artifacts/merge.js +64 -0
- package/nodejs-artifacts/native.d.ts +29 -3
- package/nodejs-artifacts/native.js +26 -9
- package/nodejs-artifacts/query.d.ts +33 -10
- package/nodejs-artifacts/query.js +100 -13
- package/nodejs-artifacts/remote/client.d.ts +28 -0
- package/nodejs-artifacts/remote/client.js +172 -0
- package/nodejs-artifacts/remote/connection.d.ts +25 -0
- package/nodejs-artifacts/remote/connection.js +110 -0
- package/nodejs-artifacts/remote/index.d.ts +3 -0
- package/nodejs-artifacts/remote/index.js +9 -0
- package/nodejs-artifacts/remote/table.d.ts +42 -0
- package/nodejs-artifacts/remote/table.js +179 -0
- package/nodejs-artifacts/sanitize.d.ts +3 -2
- package/nodejs-artifacts/sanitize.js +55 -1
- package/nodejs-artifacts/table.d.ts +105 -30
- package/nodejs-artifacts/table.js +94 -237
- package/nodejs-artifacts/util.d.ts +14 -0
- package/nodejs-artifacts/util.js +65 -0
- package/package.json +25 -11
|
@@ -29,7 +29,9 @@ const registry_1 = require("./registry");
|
|
|
29
29
|
let OpenAIEmbeddingFunction = class OpenAIEmbeddingFunction extends embedding_function_1.EmbeddingFunction {
|
|
30
30
|
#openai;
|
|
31
31
|
#modelName;
|
|
32
|
-
constructor(options = {
|
|
32
|
+
constructor(options = {
|
|
33
|
+
model: "text-embedding-ada-002",
|
|
34
|
+
}) {
|
|
33
35
|
super();
|
|
34
36
|
const openAIKey = options?.apiKey ?? process.env.OPENAI_API_KEY;
|
|
35
37
|
if (!openAIKey) {
|
|
@@ -68,7 +70,7 @@ let OpenAIEmbeddingFunction = class OpenAIEmbeddingFunction extends embedding_fu
|
|
|
68
70
|
case "text-embedding-3-small":
|
|
69
71
|
return 1536;
|
|
70
72
|
default:
|
|
71
|
-
|
|
73
|
+
throw new Error(`Unknown model: ${this.#modelName}`);
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
embeddingDataType() {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EmbeddingFunction, type EmbeddingFunctionConstructor } from "./embedding_function";
|
|
2
2
|
import "reflect-metadata";
|
|
3
|
-
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface EmbeddingFunctionFactory<T extends EmbeddingFunction = EmbeddingFunction> {
|
|
7
|
-
new (modelOptions?: EmbeddingFunctionOptions): T;
|
|
8
|
-
}
|
|
3
|
+
import { OpenAIEmbeddingFunction } from "./openai";
|
|
9
4
|
interface EmbeddingFunctionCreate<T extends EmbeddingFunction> {
|
|
10
|
-
create(options?:
|
|
5
|
+
create(options?: T["TOptions"]): T;
|
|
11
6
|
}
|
|
12
7
|
/**
|
|
13
8
|
* This is a singleton class used to register embedding functions
|
|
@@ -23,12 +18,12 @@ export declare class EmbeddingFunctionRegistry {
|
|
|
23
18
|
* @param func The function to register
|
|
24
19
|
* @throws Error if the function is already registered
|
|
25
20
|
*/
|
|
26
|
-
register<T extends
|
|
21
|
+
register<T extends EmbeddingFunctionConstructor = EmbeddingFunctionConstructor>(this: EmbeddingFunctionRegistry, alias?: string): (ctor: T) => any;
|
|
27
22
|
/**
|
|
28
23
|
* Fetch an embedding function by name
|
|
29
24
|
* @param name The name of the function
|
|
30
25
|
*/
|
|
31
|
-
get<T extends EmbeddingFunction<unknown
|
|
26
|
+
get<T extends EmbeddingFunction<unknown>, Name extends string = "">(name: Name extends "openai" ? "openai" : string): Name extends "openai" ? EmbeddingFunctionCreate<OpenAIEmbeddingFunction> : EmbeddingFunctionCreate<T> | undefined;
|
|
32
27
|
/**
|
|
33
28
|
* reset the registry to the initial state
|
|
34
29
|
*/
|
|
@@ -40,7 +35,7 @@ export declare class EmbeddingFunctionRegistry {
|
|
|
40
35
|
functionToMetadata(conf: EmbeddingFunctionConfig): Record<string, any>;
|
|
41
36
|
getTableMetadata(functions: EmbeddingFunctionConfig[]): Map<string, string>;
|
|
42
37
|
}
|
|
43
|
-
export declare function register(name?: string): (ctor:
|
|
38
|
+
export declare function register(name?: string): (ctor: EmbeddingFunctionConstructor<EmbeddingFunction<any, import("./embedding_function").FunctionOptions>>) => any;
|
|
44
39
|
/**
|
|
45
40
|
* Utility function to get the global instance of the registry
|
|
46
41
|
* @returns `EmbeddingFunctionRegistry` The global instance of the registry
|
|
@@ -1,7 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import { Connection } from "./connection";
|
|
2
|
+
import { ConnectionOptions } from "./native.js";
|
|
3
|
+
import { RemoteConnectionOptions } from "./remote";
|
|
4
|
+
export { WriteOptions, WriteMode, AddColumnsSql, ColumnAlteration, ConnectionOptions, IndexStatistics, IndexMetadata, IndexConfig, } from "./native.js";
|
|
2
5
|
export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
|
|
3
|
-
export {
|
|
6
|
+
export { Connection, CreateTableOptions, TableNamesOptions, } from "./connection";
|
|
4
7
|
export { ExecutableQuery, Query, QueryBase, VectorQuery, RecordBatchIterator, } from "./query";
|
|
5
8
|
export { Index, IndexOptions, IvfPqOptions } from "./indices";
|
|
6
|
-
export { Table, AddDataOptions,
|
|
9
|
+
export { Table, AddDataOptions, UpdateOptions } from "./table";
|
|
7
10
|
export * as embedding from "./embedding";
|
|
11
|
+
/**
|
|
12
|
+
* Connect to a LanceDB instance at the given URI.
|
|
13
|
+
*
|
|
14
|
+
* Accepted formats:
|
|
15
|
+
*
|
|
16
|
+
* - `/path/to/database` - local database
|
|
17
|
+
* - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
|
|
18
|
+
* - `db://host:port` - remote database (LanceDB cloud)
|
|
19
|
+
* @param {string} uri - The uri of the database. If the database uri starts
|
|
20
|
+
* with `db://` then it connects to a remote database.
|
|
21
|
+
* @see {@link ConnectionOptions} for more details on the URI format.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const conn = await connect("/path/to/database");
|
|
25
|
+
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const conn = await connect(
|
|
29
|
+
* "s3://bucket/path/to/database",
|
|
30
|
+
* {storageOptions: {timeout: "60s"}
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function connect(uri: string, opts?: Partial<ConnectionOptions | RemoteConnectionOptions>): Promise<Connection>;
|
|
35
|
+
/**
|
|
36
|
+
* Connect to a LanceDB instance at the given URI.
|
|
37
|
+
*
|
|
38
|
+
* Accepted formats:
|
|
39
|
+
*
|
|
40
|
+
* - `/path/to/database` - local database
|
|
41
|
+
* - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
|
|
42
|
+
* - `db://host:port` - remote database (LanceDB cloud)
|
|
43
|
+
* @param options - The options to use when connecting to the database
|
|
44
|
+
* @see {@link ConnectionOptions} for more details on the URI format.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const conn = await connect({
|
|
48
|
+
* uri: "/path/to/database",
|
|
49
|
+
* storageOptions: {timeout: "60s"}
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function connect(opts: Partial<RemoteConnectionOptions | ConnectionOptions> & {
|
|
54
|
+
uri: string;
|
|
55
|
+
}): Promise<Connection>;
|
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.
|
|
16
|
+
exports.connect = exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = void 0;
|
|
17
|
+
const connection_1 = require("./connection");
|
|
18
|
+
const native_js_1 = require("./native.js");
|
|
19
|
+
const remote_1 = require("./remote");
|
|
17
20
|
var arrow_1 = require("./arrow");
|
|
18
21
|
Object.defineProperty(exports, "makeArrowTable", { enumerable: true, get: function () { return arrow_1.makeArrowTable; } });
|
|
19
22
|
Object.defineProperty(exports, "MakeArrowTableOptions", { enumerable: true, get: function () { return arrow_1.MakeArrowTableOptions; } });
|
|
20
23
|
Object.defineProperty(exports, "VectorColumnOptions", { enumerable: true, get: function () { return arrow_1.VectorColumnOptions; } });
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
-
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
|
|
24
|
+
var connection_2 = require("./connection");
|
|
25
|
+
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_2.Connection; } });
|
|
24
26
|
var query_1 = require("./query");
|
|
25
27
|
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
|
26
28
|
Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
|
|
@@ -31,3 +33,25 @@ Object.defineProperty(exports, "Index", { enumerable: true, get: function () { r
|
|
|
31
33
|
var table_1 = require("./table");
|
|
32
34
|
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
|
|
33
35
|
exports.embedding = require("./embedding");
|
|
36
|
+
async function connect(uriOrOptions, opts = {}) {
|
|
37
|
+
let uri;
|
|
38
|
+
if (typeof uriOrOptions !== "string") {
|
|
39
|
+
const { uri: uri_, ...options } = uriOrOptions;
|
|
40
|
+
uri = uri_;
|
|
41
|
+
opts = options;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
uri = uriOrOptions;
|
|
45
|
+
}
|
|
46
|
+
if (!uri) {
|
|
47
|
+
throw new Error("uri is required");
|
|
48
|
+
}
|
|
49
|
+
if (uri?.startsWith("db://")) {
|
|
50
|
+
return new remote_1.RemoteConnection(uri, opts);
|
|
51
|
+
}
|
|
52
|
+
opts = opts ?? {};
|
|
53
|
+
opts.storageOptions = (0, connection_1.cleanseStorageOptions)(opts.storageOptions);
|
|
54
|
+
const nativeConn = await native_js_1.Connection.new(uri, opts);
|
|
55
|
+
return new connection_1.LocalConnection(nativeConn);
|
|
56
|
+
}
|
|
57
|
+
exports.connect = connect;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Data } from "./arrow";
|
|
2
|
+
import { NativeMergeInsertBuilder } from "./native";
|
|
3
|
+
/** A builder used to create and run a merge insert operation */
|
|
4
|
+
export declare class MergeInsertBuilder {
|
|
5
|
+
#private;
|
|
6
|
+
/** Construct a MergeInsertBuilder. __Internal use only.__ */
|
|
7
|
+
constructor(native: NativeMergeInsertBuilder);
|
|
8
|
+
/**
|
|
9
|
+
* Rows that exist in both the source table (new data) and
|
|
10
|
+
* the target table (old data) will be updated, replacing
|
|
11
|
+
* the old row with the corresponding matching row.
|
|
12
|
+
*
|
|
13
|
+
* If there are multiple matches then the behavior is undefined.
|
|
14
|
+
* Currently this causes multiple copies of the row to be created
|
|
15
|
+
* but that behavior is subject to change.
|
|
16
|
+
*
|
|
17
|
+
* An optional condition may be specified. If it is, then only
|
|
18
|
+
* matched rows that satisfy the condtion will be updated. Any
|
|
19
|
+
* rows that do not satisfy the condition will be left as they
|
|
20
|
+
* are. Failing to satisfy the condition does not cause a
|
|
21
|
+
* "matched row" to become a "not matched" row.
|
|
22
|
+
*
|
|
23
|
+
* The condition should be an SQL string. Use the prefix
|
|
24
|
+
* target. to refer to rows in the target table (old data)
|
|
25
|
+
* and the prefix source. to refer to rows in the source
|
|
26
|
+
* table (new data).
|
|
27
|
+
*
|
|
28
|
+
* For example, "target.last_update < source.last_update"
|
|
29
|
+
*/
|
|
30
|
+
whenMatchedUpdateAll(options?: {
|
|
31
|
+
where: string;
|
|
32
|
+
}): MergeInsertBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Rows that exist only in the source table (new data) should
|
|
35
|
+
* be inserted into the target table.
|
|
36
|
+
*/
|
|
37
|
+
whenNotMatchedInsertAll(): MergeInsertBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Rows that exist only in the target table (old data) will be
|
|
40
|
+
* deleted. An optional condition can be provided to limit what
|
|
41
|
+
* data is deleted.
|
|
42
|
+
*
|
|
43
|
+
* @param options.where - An optional condition to limit what data is deleted
|
|
44
|
+
*/
|
|
45
|
+
whenNotMatchedBySourceDelete(options?: {
|
|
46
|
+
where: string;
|
|
47
|
+
}): MergeInsertBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Executes the merge insert operation
|
|
50
|
+
*
|
|
51
|
+
* Nothing is returned but the `Table` is updated
|
|
52
|
+
*/
|
|
53
|
+
execute(data: Data): Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MergeInsertBuilder = void 0;
|
|
4
|
+
const arrow_1 = require("./arrow");
|
|
5
|
+
/** A builder used to create and run a merge insert operation */
|
|
6
|
+
class MergeInsertBuilder {
|
|
7
|
+
#native;
|
|
8
|
+
/** Construct a MergeInsertBuilder. __Internal use only.__ */
|
|
9
|
+
constructor(native) {
|
|
10
|
+
this.#native = native;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Rows that exist in both the source table (new data) and
|
|
14
|
+
* the target table (old data) will be updated, replacing
|
|
15
|
+
* the old row with the corresponding matching row.
|
|
16
|
+
*
|
|
17
|
+
* If there are multiple matches then the behavior is undefined.
|
|
18
|
+
* Currently this causes multiple copies of the row to be created
|
|
19
|
+
* but that behavior is subject to change.
|
|
20
|
+
*
|
|
21
|
+
* An optional condition may be specified. If it is, then only
|
|
22
|
+
* matched rows that satisfy the condtion will be updated. Any
|
|
23
|
+
* rows that do not satisfy the condition will be left as they
|
|
24
|
+
* are. Failing to satisfy the condition does not cause a
|
|
25
|
+
* "matched row" to become a "not matched" row.
|
|
26
|
+
*
|
|
27
|
+
* The condition should be an SQL string. Use the prefix
|
|
28
|
+
* target. to refer to rows in the target table (old data)
|
|
29
|
+
* and the prefix source. to refer to rows in the source
|
|
30
|
+
* table (new data).
|
|
31
|
+
*
|
|
32
|
+
* For example, "target.last_update < source.last_update"
|
|
33
|
+
*/
|
|
34
|
+
whenMatchedUpdateAll(options) {
|
|
35
|
+
return new MergeInsertBuilder(this.#native.whenMatchedUpdateAll(options?.where));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Rows that exist only in the source table (new data) should
|
|
39
|
+
* be inserted into the target table.
|
|
40
|
+
*/
|
|
41
|
+
whenNotMatchedInsertAll() {
|
|
42
|
+
return new MergeInsertBuilder(this.#native.whenNotMatchedInsertAll());
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Rows that exist only in the target table (old data) will be
|
|
46
|
+
* deleted. An optional condition can be provided to limit what
|
|
47
|
+
* data is deleted.
|
|
48
|
+
*
|
|
49
|
+
* @param options.where - An optional condition to limit what data is deleted
|
|
50
|
+
*/
|
|
51
|
+
whenNotMatchedBySourceDelete(options) {
|
|
52
|
+
return new MergeInsertBuilder(this.#native.whenNotMatchedBySourceDelete(options?.where));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Executes the merge insert operation
|
|
56
|
+
*
|
|
57
|
+
* Nothing is returned but the `Table` is updated
|
|
58
|
+
*/
|
|
59
|
+
async execute(data) {
|
|
60
|
+
const buffer = await (0, arrow_1.fromDataToBuffer)(data);
|
|
61
|
+
await this.#native.execute(buffer);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.MergeInsertBuilder = MergeInsertBuilder;
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
/** A description of an index currently configured on a column */
|
|
7
7
|
export interface IndexConfig {
|
|
8
|
+
/** The name of the index */
|
|
9
|
+
name: string
|
|
8
10
|
/** The type of the index */
|
|
9
11
|
indexType: string
|
|
10
12
|
/**
|
|
11
13
|
* The columns in the index
|
|
12
14
|
*
|
|
13
|
-
* Currently this is always an array of size 1.
|
|
15
|
+
* Currently this is always an array of size 1. In the future there may
|
|
14
16
|
* be more columns to represent composite indices.
|
|
15
17
|
*/
|
|
16
18
|
columns: Array<string>
|
|
@@ -72,9 +74,21 @@ export interface AddColumnsSql {
|
|
|
72
74
|
*/
|
|
73
75
|
valueSql: string
|
|
74
76
|
}
|
|
77
|
+
export interface IndexStatistics {
|
|
78
|
+
/** The number of rows indexed by the index */
|
|
79
|
+
numIndexedRows: number
|
|
80
|
+
/** The number of rows not indexed */
|
|
81
|
+
numUnindexedRows: number
|
|
82
|
+
/** The type of the index */
|
|
83
|
+
indexType?: string
|
|
84
|
+
/** The metadata for each index */
|
|
85
|
+
indices: Array<IndexMetadata>
|
|
86
|
+
}
|
|
87
|
+
export interface IndexMetadata {
|
|
88
|
+
metricType?: string
|
|
89
|
+
indexType?: string
|
|
90
|
+
}
|
|
75
91
|
export interface ConnectionOptions {
|
|
76
|
-
apiKey?: string
|
|
77
|
-
hostOverride?: string
|
|
78
92
|
/**
|
|
79
93
|
* (For LanceDB OSS only): The interval, in seconds, at which to check for
|
|
80
94
|
* updates to the table from other processes. If None, then consistency is not
|
|
@@ -138,12 +152,20 @@ export class Index {
|
|
|
138
152
|
export class RecordBatchIterator {
|
|
139
153
|
next(): Promise<Buffer | null>
|
|
140
154
|
}
|
|
155
|
+
/** A builder used to create and run a merge insert operation */
|
|
156
|
+
export class NativeMergeInsertBuilder {
|
|
157
|
+
whenMatchedUpdateAll(condition?: string | undefined | null): NativeMergeInsertBuilder
|
|
158
|
+
whenNotMatchedInsertAll(): NativeMergeInsertBuilder
|
|
159
|
+
whenNotMatchedBySourceDelete(filter?: string | undefined | null): NativeMergeInsertBuilder
|
|
160
|
+
execute(buf: Buffer): Promise<void>
|
|
161
|
+
}
|
|
141
162
|
export class Query {
|
|
142
163
|
onlyIf(predicate: string): void
|
|
143
164
|
select(columns: Array<[string, string]>): void
|
|
144
165
|
limit(limit: number): void
|
|
145
166
|
nearestTo(vector: Float32Array): VectorQuery
|
|
146
167
|
execute(maxBatchLength?: number | undefined | null): Promise<RecordBatchIterator>
|
|
168
|
+
explainPlan(verbose: boolean): Promise<string>
|
|
147
169
|
}
|
|
148
170
|
export class VectorQuery {
|
|
149
171
|
column(column: string): void
|
|
@@ -156,8 +178,10 @@ export class VectorQuery {
|
|
|
156
178
|
select(columns: Array<[string, string]>): void
|
|
157
179
|
limit(limit: number): void
|
|
158
180
|
execute(maxBatchLength?: number | undefined | null): Promise<RecordBatchIterator>
|
|
181
|
+
explainPlan(verbose: boolean): Promise<string>
|
|
159
182
|
}
|
|
160
183
|
export class Table {
|
|
184
|
+
name: string
|
|
161
185
|
display(): string
|
|
162
186
|
isOpen(): boolean
|
|
163
187
|
close(): void
|
|
@@ -179,4 +203,6 @@ export class Table {
|
|
|
179
203
|
restore(): Promise<void>
|
|
180
204
|
optimize(olderThanMs?: number | undefined | null): Promise<OptimizeStats>
|
|
181
205
|
listIndices(): Promise<Array<IndexConfig>>
|
|
206
|
+
indexStats(indexName: string): Promise<IndexStatistics | null>
|
|
207
|
+
mergeInsert(on: Array<string>): NativeMergeInsertBuilder
|
|
182
208
|
}
|
|
@@ -233,17 +233,33 @@ switch (platform) {
|
|
|
233
233
|
}
|
|
234
234
|
break;
|
|
235
235
|
case 'arm':
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
if (isMusl()) {
|
|
237
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm-musleabihf.node'));
|
|
238
|
+
try {
|
|
239
|
+
if (localFileExisted) {
|
|
240
|
+
nativeBinding = require('./lancedb.linux-arm-musleabihf.node');
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm-musleabihf');
|
|
244
|
+
}
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
|
|
246
|
+
catch (e) {
|
|
247
|
+
loadError = e;
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
|
-
|
|
246
|
-
|
|
250
|
+
else {
|
|
251
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm-gnueabihf.node'));
|
|
252
|
+
try {
|
|
253
|
+
if (localFileExisted) {
|
|
254
|
+
nativeBinding = require('./lancedb.linux-arm-gnueabihf.node');
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm-gnueabihf');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
loadError = e;
|
|
262
|
+
}
|
|
247
263
|
}
|
|
248
264
|
break;
|
|
249
265
|
case 'riscv64':
|
|
@@ -303,10 +319,11 @@ if (!nativeBinding) {
|
|
|
303
319
|
}
|
|
304
320
|
throw new Error(`Failed to load native binding`);
|
|
305
321
|
}
|
|
306
|
-
const { Connection, Index, RecordBatchIterator, Query, VectorQuery, Table, WriteMode } = nativeBinding;
|
|
322
|
+
const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, Table, WriteMode } = nativeBinding;
|
|
307
323
|
module.exports.Connection = Connection;
|
|
308
324
|
module.exports.Index = Index;
|
|
309
325
|
module.exports.RecordBatchIterator = RecordBatchIterator;
|
|
326
|
+
module.exports.NativeMergeInsertBuilder = NativeMergeInsertBuilder;
|
|
310
327
|
module.exports.Query = Query;
|
|
311
328
|
module.exports.VectorQuery = VectorQuery;
|
|
312
329
|
module.exports.Table = Table;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Table as ArrowTable, type IntoVector, RecordBatch } from "./arrow";
|
|
2
|
+
import { type IvfPqOptions } from "./indices";
|
|
2
3
|
import { RecordBatchIterator as NativeBatchIterator, Query as NativeQuery, Table as NativeTable, VectorQuery as NativeVectorQuery } from "./native";
|
|
3
4
|
export declare class RecordBatchIterator implements AsyncIterator<RecordBatch> {
|
|
4
5
|
private promisedInner?;
|
|
@@ -19,9 +20,10 @@ export interface QueryExecutionOptions {
|
|
|
19
20
|
maxBatchLength?: number;
|
|
20
21
|
}
|
|
21
22
|
/** Common methods supported by all query types */
|
|
22
|
-
export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery
|
|
23
|
-
protected inner: NativeQueryType
|
|
24
|
-
protected constructor(inner: NativeQueryType);
|
|
23
|
+
export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery> implements AsyncIterable<RecordBatch> {
|
|
24
|
+
protected inner: NativeQueryType | Promise<NativeQueryType>;
|
|
25
|
+
protected constructor(inner: NativeQueryType | Promise<NativeQueryType>);
|
|
26
|
+
protected doCall(fn: (inner: NativeQueryType) => void): void;
|
|
25
27
|
/**
|
|
26
28
|
* A filter statement to be applied to this query.
|
|
27
29
|
*
|
|
@@ -34,7 +36,13 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
|
|
|
34
36
|
* Filtering performance can often be improved by creating a scalar index
|
|
35
37
|
* on the filter column(s).
|
|
36
38
|
*/
|
|
37
|
-
where(predicate: string):
|
|
39
|
+
where(predicate: string): this;
|
|
40
|
+
/**
|
|
41
|
+
* A filter statement to be applied to this query.
|
|
42
|
+
* @alias where
|
|
43
|
+
* @deprecated Use `where` instead
|
|
44
|
+
*/
|
|
45
|
+
filter(predicate: string): this;
|
|
38
46
|
/**
|
|
39
47
|
* Return only the specified columns.
|
|
40
48
|
*
|
|
@@ -65,14 +73,14 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
|
|
|
65
73
|
* uses `Object.entries` which should preserve the insertion order of the object. However,
|
|
66
74
|
* object insertion order is easy to get wrong and `Map` is more foolproof.
|
|
67
75
|
*/
|
|
68
|
-
select(columns: string[] | Map<string, string> | Record<string, string> | string):
|
|
76
|
+
select(columns: string[] | Map<string, string> | Record<string, string> | string): this;
|
|
69
77
|
/**
|
|
70
78
|
* Set the maximum number of results to return.
|
|
71
79
|
*
|
|
72
80
|
* By default, a plain search has no limit. If this method is not
|
|
73
81
|
* called then every valid row from the table will be returned.
|
|
74
82
|
*/
|
|
75
|
-
limit(limit: number):
|
|
83
|
+
limit(limit: number): this;
|
|
76
84
|
protected nativeExecute(options?: Partial<QueryExecutionOptions>): Promise<NativeBatchIterator>;
|
|
77
85
|
/**
|
|
78
86
|
* Execute the query and return the results as an @see {@link AsyncIterator}
|
|
@@ -91,6 +99,21 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
|
|
|
91
99
|
toArrow(options?: Partial<QueryExecutionOptions>): Promise<ArrowTable>;
|
|
92
100
|
/** Collect the results as an array of objects. */
|
|
93
101
|
toArray(options?: Partial<QueryExecutionOptions>): Promise<any[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Generates an explanation of the query execution plan.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* import * as lancedb from "@lancedb/lancedb"
|
|
107
|
+
* const db = await lancedb.connect("./.lancedb");
|
|
108
|
+
* const table = await db.createTable("my_table", [
|
|
109
|
+
* { vector: [1.1, 0.9], id: "1" },
|
|
110
|
+
* ]);
|
|
111
|
+
* const plan = await table.query().nearestTo([0.5, 0.2]).explainPlan();
|
|
112
|
+
*
|
|
113
|
+
* @param verbose - If true, provides a more detailed explanation. Defaults to false.
|
|
114
|
+
* @returns A Promise that resolves to a string containing the query execution plan explanation.
|
|
115
|
+
*/
|
|
116
|
+
explainPlan(verbose?: boolean): Promise<string>;
|
|
94
117
|
}
|
|
95
118
|
/**
|
|
96
119
|
* An interface for a query that can be executed
|
|
@@ -104,8 +127,8 @@ export interface ExecutableQuery {
|
|
|
104
127
|
*
|
|
105
128
|
* This builder can be reused to execute the query many times.
|
|
106
129
|
*/
|
|
107
|
-
export declare class VectorQuery extends QueryBase<NativeVectorQuery
|
|
108
|
-
constructor(inner: NativeVectorQuery);
|
|
130
|
+
export declare class VectorQuery extends QueryBase<NativeVectorQuery> {
|
|
131
|
+
constructor(inner: NativeVectorQuery | Promise<NativeVectorQuery>);
|
|
109
132
|
/**
|
|
110
133
|
* Set the number of partitions to search (probe)
|
|
111
134
|
*
|
|
@@ -153,7 +176,7 @@ export declare class VectorQuery extends QueryBase<NativeVectorQuery, VectorQuer
|
|
|
153
176
|
*
|
|
154
177
|
* By default "l2" is used.
|
|
155
178
|
*/
|
|
156
|
-
distanceType(distanceType:
|
|
179
|
+
distanceType(distanceType: Required<IvfPqOptions>["distanceType"]): VectorQuery;
|
|
157
180
|
/**
|
|
158
181
|
* A multiplier to control how many additional rows are taken during the refine step
|
|
159
182
|
*
|
|
@@ -217,7 +240,7 @@ export declare class VectorQuery extends QueryBase<NativeVectorQuery, VectorQuer
|
|
|
217
240
|
bypassVectorIndex(): VectorQuery;
|
|
218
241
|
}
|
|
219
242
|
/** A builder for LanceDB queries. */
|
|
220
|
-
export declare class Query extends QueryBase<NativeQuery
|
|
243
|
+
export declare class Query extends QueryBase<NativeQuery> {
|
|
221
244
|
constructor(tbl: NativeTable);
|
|
222
245
|
/**
|
|
223
246
|
* Find the nearest vectors to the given query vector.
|