@lancedb/lancedb 0.5.1 → 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 +42 -7
- package/dist/arrow.js +6 -5
- package/dist/connection.d.ts +55 -29
- package/dist/connection.js +22 -74
- package/dist/embedding/embedding_function.d.ts +11 -3
- package/dist/embedding/embedding_function.js +36 -12
- package/dist/embedding/openai.d.ts +6 -5
- package/dist/embedding/openai.js +4 -2
- package/dist/embedding/registry.d.ts +10 -11
- package/dist/embedding/registry.js +4 -0
- 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 +34 -7
- package/dist/native.js +26 -9
- package/dist/query.d.ts +51 -16
- package/dist/query.js +122 -21
- 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 +116 -25
- package/dist/table.js +117 -233
- 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 +87 -24
- package/lancedb/connection.ts +115 -92
- package/lancedb/embedding/embedding_function.ts +48 -16
- package/lancedb/embedding/openai.ts +11 -6
- package/lancedb/embedding/registry.ts +38 -22
- package/lancedb/index.ts +101 -2
- package/lancedb/merge.ts +70 -0
- package/lancedb/query.ts +168 -39
- 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 +344 -101
- package/lancedb/util.ts +69 -0
- package/native.d.ts +208 -0
- package/nodejs-artifacts/arrow.d.ts +42 -7
- package/nodejs-artifacts/arrow.js +6 -5
- package/nodejs-artifacts/connection.d.ts +55 -29
- package/nodejs-artifacts/connection.js +22 -74
- package/nodejs-artifacts/embedding/embedding_function.d.ts +11 -3
- package/nodejs-artifacts/embedding/embedding_function.js +36 -12
- package/nodejs-artifacts/embedding/openai.d.ts +6 -5
- package/nodejs-artifacts/embedding/openai.js +4 -2
- package/nodejs-artifacts/embedding/registry.d.ts +10 -11
- package/nodejs-artifacts/embedding/registry.js +4 -0
- 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 +34 -7
- package/nodejs-artifacts/native.js +26 -9
- package/nodejs-artifacts/query.d.ts +51 -16
- package/nodejs-artifacts/query.js +122 -21
- 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 +116 -25
- package/nodejs-artifacts/table.js +117 -233
- package/nodejs-artifacts/util.d.ts +14 -0
- package/nodejs-artifacts/util.js +65 -0
- package/package.json +25 -11
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteConnection = void 0;
|
|
4
|
+
const arrow_1 = require("../arrow");
|
|
5
|
+
const connection_1 = require("../connection");
|
|
6
|
+
const table_1 = require("../table");
|
|
7
|
+
const util_1 = require("../util");
|
|
8
|
+
const client_1 = require("./client");
|
|
9
|
+
const table_2 = require("./table");
|
|
10
|
+
class RemoteConnection extends connection_1.Connection {
|
|
11
|
+
#dbName;
|
|
12
|
+
#apiKey;
|
|
13
|
+
#region;
|
|
14
|
+
#client;
|
|
15
|
+
#tableCache = new util_1.TTLCache(300000);
|
|
16
|
+
constructor(url, { apiKey, region, hostOverride, connectionTimeout, readTimeout, }) {
|
|
17
|
+
super();
|
|
18
|
+
apiKey = apiKey ?? process.env.LANCEDB_API_KEY;
|
|
19
|
+
region = region ?? process.env.LANCEDB_REGION;
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
throw new Error("apiKey is required when connecting to LanceDB Cloud");
|
|
22
|
+
}
|
|
23
|
+
if (!region) {
|
|
24
|
+
throw new Error("region is required when connecting to LanceDB Cloud");
|
|
25
|
+
}
|
|
26
|
+
const parsed = new URL(url);
|
|
27
|
+
if (parsed.protocol !== "db:") {
|
|
28
|
+
throw new Error(`invalid protocol: ${parsed.protocol}, only accepts db://`);
|
|
29
|
+
}
|
|
30
|
+
this.#dbName = parsed.hostname;
|
|
31
|
+
this.#apiKey = apiKey;
|
|
32
|
+
this.#region = region;
|
|
33
|
+
this.#client = new client_1.RestfulLanceDBClient(this.#dbName, this.#apiKey, this.#region, hostOverride, connectionTimeout, readTimeout);
|
|
34
|
+
}
|
|
35
|
+
isOpen() {
|
|
36
|
+
return this.#client.isOpen();
|
|
37
|
+
}
|
|
38
|
+
close() {
|
|
39
|
+
return this.#client.close();
|
|
40
|
+
}
|
|
41
|
+
display() {
|
|
42
|
+
return `RemoteConnection(${this.#dbName})`;
|
|
43
|
+
}
|
|
44
|
+
async tableNames(options) {
|
|
45
|
+
const response = await this.#client.get("/v1/table/", {
|
|
46
|
+
limit: options?.limit ?? 10,
|
|
47
|
+
// biome-ignore lint/style/useNamingConvention: <explanation>
|
|
48
|
+
page_token: options?.startAfter ?? "",
|
|
49
|
+
});
|
|
50
|
+
const body = await response.body();
|
|
51
|
+
for (const table of body.tables) {
|
|
52
|
+
this.#tableCache.set(table, true);
|
|
53
|
+
}
|
|
54
|
+
return body.tables;
|
|
55
|
+
}
|
|
56
|
+
async openTable(name, _options) {
|
|
57
|
+
if (this.#tableCache.get(name) === undefined) {
|
|
58
|
+
await this.#client.post(`/v1/table/${encodeURIComponent(name)}/describe/`);
|
|
59
|
+
this.#tableCache.set(name, true);
|
|
60
|
+
}
|
|
61
|
+
return new table_2.RemoteTable(this.#client, name, this.#dbName);
|
|
62
|
+
}
|
|
63
|
+
async createTable(nameOrOptions, data, options) {
|
|
64
|
+
if (typeof nameOrOptions !== "string" && "name" in nameOrOptions) {
|
|
65
|
+
const { name, data, ...options } = nameOrOptions;
|
|
66
|
+
return this.createTable(name, data, options);
|
|
67
|
+
}
|
|
68
|
+
if (data === undefined) {
|
|
69
|
+
throw new Error("data is required");
|
|
70
|
+
}
|
|
71
|
+
if (options?.mode) {
|
|
72
|
+
console.warn("option 'mode' is not supported in LanceDB Cloud", "LanceDB Cloud only supports the default 'create' mode.", "If the table already exists, an error will be thrown.");
|
|
73
|
+
}
|
|
74
|
+
if (options?.embeddingFunction) {
|
|
75
|
+
console.warn("embedding_functions is not yet supported on LanceDB Cloud.", "Please vote https://github.com/lancedb/lancedb/issues/626 ", "for this feature.");
|
|
76
|
+
}
|
|
77
|
+
const { buf } = await table_1.Table.parseTableData(data, options, true /** streaming */);
|
|
78
|
+
await this.#client.post(`/v1/table/${encodeURIComponent(nameOrOptions)}/create/`, buf, {
|
|
79
|
+
config: {
|
|
80
|
+
responseType: "arraybuffer",
|
|
81
|
+
},
|
|
82
|
+
headers: { "Content-Type": "application/vnd.apache.arrow.stream" },
|
|
83
|
+
});
|
|
84
|
+
this.#tableCache.set(nameOrOptions, true);
|
|
85
|
+
return new table_2.RemoteTable(this.#client, nameOrOptions, this.#dbName);
|
|
86
|
+
}
|
|
87
|
+
async createEmptyTable(name, schema, options) {
|
|
88
|
+
if (options?.mode) {
|
|
89
|
+
console.warn(`mode is not supported on LanceDB Cloud`);
|
|
90
|
+
}
|
|
91
|
+
if (options?.embeddingFunction) {
|
|
92
|
+
console.warn("embeddingFunction is not yet supported on LanceDB Cloud.", "Please vote https://github.com/lancedb/lancedb/issues/626 ", "for this feature.");
|
|
93
|
+
}
|
|
94
|
+
const emptyTable = (0, arrow_1.makeEmptyTable)(schema);
|
|
95
|
+
const buf = await (0, arrow_1.fromTableToStreamBuffer)(emptyTable);
|
|
96
|
+
await this.#client.post(`/v1/table/${encodeURIComponent(name)}/create/`, buf, {
|
|
97
|
+
config: {
|
|
98
|
+
responseType: "arraybuffer",
|
|
99
|
+
},
|
|
100
|
+
headers: { "Content-Type": "application/vnd.apache.arrow.stream" },
|
|
101
|
+
});
|
|
102
|
+
this.#tableCache.set(name, true);
|
|
103
|
+
return new table_2.RemoteTable(this.#client, name, this.#dbName);
|
|
104
|
+
}
|
|
105
|
+
async dropTable(name) {
|
|
106
|
+
await this.#client.post(`/v1/table/${encodeURIComponent(name)}/drop/`);
|
|
107
|
+
this.#tableCache.delete(name);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.RemoteConnection = RemoteConnection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteTable = exports.RemoteConnection = exports.RestfulLanceDBClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "RestfulLanceDBClient", { enumerable: true, get: function () { return client_1.RestfulLanceDBClient; } });
|
|
6
|
+
var connection_1 = require("./connection");
|
|
7
|
+
Object.defineProperty(exports, "RemoteConnection", { enumerable: true, get: function () { return connection_1.RemoteConnection; } });
|
|
8
|
+
var table_1 = require("./table");
|
|
9
|
+
Object.defineProperty(exports, "RemoteTable", { enumerable: true, get: function () { return table_1.RemoteTable; } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Table as ArrowTable } from "apache-arrow";
|
|
2
|
+
import { Data, IntoVector } from "../arrow";
|
|
3
|
+
import { IndexStatistics } from "..";
|
|
4
|
+
import { IndexOptions } from "../indices";
|
|
5
|
+
import { MergeInsertBuilder } from "../merge";
|
|
6
|
+
import { VectorQuery } from "../query";
|
|
7
|
+
import { AddDataOptions, Table, UpdateOptions } from "../table";
|
|
8
|
+
import { IntoSql } from "../util";
|
|
9
|
+
import { RestfulLanceDBClient } from "./client";
|
|
10
|
+
export declare class RemoteTable extends Table {
|
|
11
|
+
#private;
|
|
12
|
+
get name(): string;
|
|
13
|
+
constructor(client: RestfulLanceDBClient, tableName: string, dbName: string);
|
|
14
|
+
isOpen(): boolean;
|
|
15
|
+
close(): void;
|
|
16
|
+
display(): string;
|
|
17
|
+
schema(): Promise<import("apache-arrow").Schema>;
|
|
18
|
+
add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
|
|
19
|
+
update(optsOrUpdates: (Map<string, string> | Record<string, string>) | ({
|
|
20
|
+
values: Map<string, IntoSql> | Record<string, IntoSql>;
|
|
21
|
+
} & Partial<UpdateOptions>) | ({
|
|
22
|
+
valuesSql: Map<string, string> | Record<string, string>;
|
|
23
|
+
} & Partial<UpdateOptions>), options?: Partial<UpdateOptions>): Promise<void>;
|
|
24
|
+
countRows(filter?: unknown): Promise<number>;
|
|
25
|
+
delete(predicate: unknown): Promise<void>;
|
|
26
|
+
createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
|
|
27
|
+
query(): import("..").Query;
|
|
28
|
+
search(_query: string | IntoVector): VectorQuery;
|
|
29
|
+
vectorSearch(_vector: unknown): import("..").VectorQuery;
|
|
30
|
+
addColumns(_newColumnTransforms: unknown): Promise<void>;
|
|
31
|
+
alterColumns(_columnAlterations: unknown): Promise<void>;
|
|
32
|
+
dropColumns(_columnNames: unknown): Promise<void>;
|
|
33
|
+
version(): Promise<number>;
|
|
34
|
+
checkout(_version: unknown): Promise<void>;
|
|
35
|
+
checkoutLatest(): Promise<void>;
|
|
36
|
+
restore(): Promise<void>;
|
|
37
|
+
optimize(_options?: unknown): Promise<import("../native").OptimizeStats>;
|
|
38
|
+
listIndices(): Promise<import("../native").IndexConfig[]>;
|
|
39
|
+
toArrow(): Promise<ArrowTable>;
|
|
40
|
+
mergeInsert(_on: string | string[]): MergeInsertBuilder;
|
|
41
|
+
indexStats(_name: string): Promise<IndexStatistics | undefined>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2023 LanceDB Developers.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.RemoteTable = void 0;
|
|
17
|
+
const table_1 = require("../table");
|
|
18
|
+
const util_1 = require("../util");
|
|
19
|
+
class RemoteTable extends table_1.Table {
|
|
20
|
+
#client;
|
|
21
|
+
#name;
|
|
22
|
+
// Used in the display() method
|
|
23
|
+
#dbName;
|
|
24
|
+
get #tablePrefix() {
|
|
25
|
+
return `/v1/table/${encodeURIComponent(this.#name)}/`;
|
|
26
|
+
}
|
|
27
|
+
get name() {
|
|
28
|
+
return this.#name;
|
|
29
|
+
}
|
|
30
|
+
constructor(client, tableName, dbName) {
|
|
31
|
+
super();
|
|
32
|
+
this.#client = client;
|
|
33
|
+
this.#name = tableName;
|
|
34
|
+
this.#dbName = dbName;
|
|
35
|
+
}
|
|
36
|
+
isOpen() {
|
|
37
|
+
return !this.#client.isOpen();
|
|
38
|
+
}
|
|
39
|
+
close() {
|
|
40
|
+
this.#client.close();
|
|
41
|
+
}
|
|
42
|
+
display() {
|
|
43
|
+
return `RemoteTable(${this.#dbName}; ${this.#name})`;
|
|
44
|
+
}
|
|
45
|
+
async schema() {
|
|
46
|
+
const resp = await this.#client.post(`${this.#tablePrefix}/describe/`);
|
|
47
|
+
// TODO: parse this into a valid arrow schema
|
|
48
|
+
return resp.schema;
|
|
49
|
+
}
|
|
50
|
+
async add(data, options) {
|
|
51
|
+
const { buf, mode } = await table_1.Table.parseTableData(data, options, true);
|
|
52
|
+
await this.#client.post(`${this.#tablePrefix}/insert/`, buf, {
|
|
53
|
+
params: {
|
|
54
|
+
mode,
|
|
55
|
+
},
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/vnd.apache.arrow.stream",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async update(optsOrUpdates, options) {
|
|
62
|
+
const isValues = "values" in optsOrUpdates && typeof optsOrUpdates.values !== "string";
|
|
63
|
+
const isValuesSql = "valuesSql" in optsOrUpdates &&
|
|
64
|
+
typeof optsOrUpdates.valuesSql !== "string";
|
|
65
|
+
const isMap = (obj) => {
|
|
66
|
+
return obj instanceof Map;
|
|
67
|
+
};
|
|
68
|
+
let predicate;
|
|
69
|
+
let columns;
|
|
70
|
+
switch (true) {
|
|
71
|
+
case isMap(optsOrUpdates):
|
|
72
|
+
columns = Array.from(optsOrUpdates.entries());
|
|
73
|
+
predicate = options?.where;
|
|
74
|
+
break;
|
|
75
|
+
case isValues && isMap(optsOrUpdates.values):
|
|
76
|
+
columns = Array.from(optsOrUpdates.values.entries()).map(([k, v]) => [
|
|
77
|
+
k,
|
|
78
|
+
(0, util_1.toSQL)(v),
|
|
79
|
+
]);
|
|
80
|
+
predicate = optsOrUpdates.where;
|
|
81
|
+
break;
|
|
82
|
+
case isValues && !isMap(optsOrUpdates.values):
|
|
83
|
+
columns = Object.entries(optsOrUpdates.values).map(([k, v]) => [
|
|
84
|
+
k,
|
|
85
|
+
(0, util_1.toSQL)(v),
|
|
86
|
+
]);
|
|
87
|
+
predicate = optsOrUpdates.where;
|
|
88
|
+
break;
|
|
89
|
+
case isValuesSql && isMap(optsOrUpdates.valuesSql):
|
|
90
|
+
columns = Array.from(optsOrUpdates.valuesSql.entries());
|
|
91
|
+
predicate = optsOrUpdates.where;
|
|
92
|
+
break;
|
|
93
|
+
case isValuesSql && !isMap(optsOrUpdates.valuesSql):
|
|
94
|
+
columns = Object.entries(optsOrUpdates.valuesSql).map(([k, v]) => [
|
|
95
|
+
k,
|
|
96
|
+
v,
|
|
97
|
+
]);
|
|
98
|
+
predicate = optsOrUpdates.where;
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
columns = Object.entries(optsOrUpdates);
|
|
102
|
+
predicate = options?.where;
|
|
103
|
+
}
|
|
104
|
+
await this.#client.post(`${this.#tablePrefix}/update/`, {
|
|
105
|
+
predicate: predicate ?? null,
|
|
106
|
+
updates: columns,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async countRows(filter) {
|
|
110
|
+
const payload = { predicate: filter };
|
|
111
|
+
return await this.#client.post(`${this.#tablePrefix}/count_rows/`, payload);
|
|
112
|
+
}
|
|
113
|
+
async delete(predicate) {
|
|
114
|
+
const payload = { predicate };
|
|
115
|
+
await this.#client.post(`${this.#tablePrefix}/delete/`, payload);
|
|
116
|
+
}
|
|
117
|
+
async createIndex(column, options) {
|
|
118
|
+
if (options !== undefined) {
|
|
119
|
+
console.warn("options are not yet supported on the LanceDB cloud");
|
|
120
|
+
}
|
|
121
|
+
const indexType = "vector";
|
|
122
|
+
const metric = "L2";
|
|
123
|
+
const data = {
|
|
124
|
+
column,
|
|
125
|
+
// biome-ignore lint/style/useNamingConvention: external API
|
|
126
|
+
index_type: indexType,
|
|
127
|
+
// biome-ignore lint/style/useNamingConvention: external API
|
|
128
|
+
metric_type: metric,
|
|
129
|
+
};
|
|
130
|
+
await this.#client.post(`${this.#tablePrefix}/create_index`, data);
|
|
131
|
+
}
|
|
132
|
+
query() {
|
|
133
|
+
throw new Error("query() is not yet supported on the LanceDB cloud");
|
|
134
|
+
}
|
|
135
|
+
search(_query) {
|
|
136
|
+
throw new Error("search() is not yet supported on the LanceDB cloud");
|
|
137
|
+
}
|
|
138
|
+
vectorSearch(_vector) {
|
|
139
|
+
throw new Error("vectorSearch() is not yet supported on the LanceDB cloud");
|
|
140
|
+
}
|
|
141
|
+
addColumns(_newColumnTransforms) {
|
|
142
|
+
throw new Error("addColumns() is not yet supported on the LanceDB cloud");
|
|
143
|
+
}
|
|
144
|
+
alterColumns(_columnAlterations) {
|
|
145
|
+
throw new Error("alterColumns() is not yet supported on the LanceDB cloud");
|
|
146
|
+
}
|
|
147
|
+
dropColumns(_columnNames) {
|
|
148
|
+
throw new Error("dropColumns() is not yet supported on the LanceDB cloud");
|
|
149
|
+
}
|
|
150
|
+
async version() {
|
|
151
|
+
const resp = await this.#client.post(`${this.#tablePrefix}/describe/`);
|
|
152
|
+
return resp.version;
|
|
153
|
+
}
|
|
154
|
+
checkout(_version) {
|
|
155
|
+
throw new Error("checkout() is not yet supported on the LanceDB cloud");
|
|
156
|
+
}
|
|
157
|
+
checkoutLatest() {
|
|
158
|
+
throw new Error("checkoutLatest() is not yet supported on the LanceDB cloud");
|
|
159
|
+
}
|
|
160
|
+
restore() {
|
|
161
|
+
throw new Error("restore() is not yet supported on the LanceDB cloud");
|
|
162
|
+
}
|
|
163
|
+
optimize(_options) {
|
|
164
|
+
throw new Error("optimize() is not yet supported on the LanceDB cloud");
|
|
165
|
+
}
|
|
166
|
+
async listIndices() {
|
|
167
|
+
return await this.#client.post(`${this.#tablePrefix}/index/list/`);
|
|
168
|
+
}
|
|
169
|
+
toArrow() {
|
|
170
|
+
throw new Error("toArrow() is not yet supported on the LanceDB cloud");
|
|
171
|
+
}
|
|
172
|
+
mergeInsert(_on) {
|
|
173
|
+
throw new Error("mergeInsert() is not yet supported on the LanceDB cloud");
|
|
174
|
+
}
|
|
175
|
+
async indexStats(_name) {
|
|
176
|
+
throw new Error("indexStats() is not yet supported on the LanceDB cloud");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.RemoteTable = RemoteTable;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TKeys } from "apache-arrow/type";
|
|
2
|
-
import { DataType, Date_, Decimal, DenseUnion, Dictionary, Duration, Field, FixedSizeBinary, FixedSizeList, Float, Int, Interval, List, Map_, Schema, SparseUnion, Struct, Time, Timestamp, TimestampMicrosecond, TimestampMillisecond, TimestampNanosecond, TimestampSecond, Type, Union } from "./arrow";
|
|
2
|
+
import { DataType, Date_, Decimal, DenseUnion, Dictionary, Duration, Field, FixedSizeBinary, FixedSizeList, Float, Int, Interval, List, Map_, Schema, SchemaLike, SparseUnion, Struct, Table, TableLike, Time, Timestamp, TimestampMicrosecond, TimestampMillisecond, TimestampNanosecond, TimestampSecond, Type, Union } from "./arrow";
|
|
3
3
|
export declare function sanitizeMetadata(metadataLike?: unknown): Map<string, string> | undefined;
|
|
4
4
|
export declare function sanitizeInt(typeLike: object): Int<Type.Int | Type.Int8 | Type.Int16 | Type.Int32 | Type.Int64 | Type.Uint8 | Type.Uint16 | Type.Uint32 | Type.Uint64>;
|
|
5
5
|
export declare function sanitizeFloat(typeLike: object): Float<Type.Float | Type.Float16 | Type.Float32 | Type.Float64>;
|
|
@@ -27,4 +27,5 @@ export declare function sanitizeField(fieldLike: unknown): Field;
|
|
|
27
27
|
* instance because they might be using a different instance of apache-arrow
|
|
28
28
|
* than lancedb is using.
|
|
29
29
|
*/
|
|
30
|
-
export declare function sanitizeSchema(schemaLike:
|
|
30
|
+
export declare function sanitizeSchema(schemaLike: SchemaLike): Schema;
|
|
31
|
+
export declare function sanitizeTable(tableLike: TableLike): Table;
|
|
@@ -13,7 +13,15 @@
|
|
|
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.sanitizeSchema = exports.sanitizeField = exports.sanitizeType = exports.sanitizeDictionary = exports.sanitizeDuration = exports.sanitizeMap = exports.sanitizeFixedSizeList = exports.sanitizeFixedSizeBinary = exports.sanitizeTypedUnion = exports.sanitizeUnion = exports.sanitizeStruct = exports.sanitizeList = exports.sanitizeInterval = exports.sanitizeTypedTimestamp = exports.sanitizeTimestamp = exports.sanitizeTime = exports.sanitizeDate = exports.sanitizeDecimal = exports.sanitizeFloat = exports.sanitizeInt = exports.sanitizeMetadata = void 0;
|
|
16
|
+
exports.sanitizeTable = exports.sanitizeSchema = exports.sanitizeField = exports.sanitizeType = exports.sanitizeDictionary = exports.sanitizeDuration = exports.sanitizeMap = exports.sanitizeFixedSizeList = exports.sanitizeFixedSizeBinary = exports.sanitizeTypedUnion = exports.sanitizeUnion = exports.sanitizeStruct = exports.sanitizeList = exports.sanitizeInterval = exports.sanitizeTypedTimestamp = exports.sanitizeTimestamp = exports.sanitizeTime = exports.sanitizeDate = exports.sanitizeDecimal = exports.sanitizeFloat = exports.sanitizeInt = exports.sanitizeMetadata = void 0;
|
|
17
|
+
// The utilities in this file help sanitize data from the user's arrow
|
|
18
|
+
// library into the types expected by vectordb's arrow library. Node
|
|
19
|
+
// generally allows for mulitple versions of the same library (and sometimes
|
|
20
|
+
// even multiple copies of the same version) to be installed at the same
|
|
21
|
+
// time. However, arrow-js uses instanceof which expected that the input
|
|
22
|
+
// comes from the exact same library instance. This is not always the case
|
|
23
|
+
// and so we must sanitize the input to ensure that it is compatible.
|
|
24
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
17
25
|
const arrow_1 = require("./arrow");
|
|
18
26
|
function sanitizeMetadata(metadataLike) {
|
|
19
27
|
if (metadataLike === undefined || metadataLike === null) {
|
|
@@ -380,3 +388,49 @@ function sanitizeSchema(schemaLike) {
|
|
|
380
388
|
return new arrow_1.Schema(sanitizedFields, metadata);
|
|
381
389
|
}
|
|
382
390
|
exports.sanitizeSchema = sanitizeSchema;
|
|
391
|
+
function sanitizeTable(tableLike) {
|
|
392
|
+
if (tableLike instanceof arrow_1.Table) {
|
|
393
|
+
return tableLike;
|
|
394
|
+
}
|
|
395
|
+
if (typeof tableLike !== "object" || tableLike === null) {
|
|
396
|
+
throw Error("Expected a Table but object was null/undefined");
|
|
397
|
+
}
|
|
398
|
+
if (!("schema" in tableLike)) {
|
|
399
|
+
throw Error("The table passed in does not appear to be a table (no 'schema' property)");
|
|
400
|
+
}
|
|
401
|
+
if (!("batches" in tableLike)) {
|
|
402
|
+
throw Error("The table passed in does not appear to be a table (no 'columns' property)");
|
|
403
|
+
}
|
|
404
|
+
const schema = sanitizeSchema(tableLike.schema);
|
|
405
|
+
const batches = tableLike.batches.map(sanitizeRecordBatch);
|
|
406
|
+
return new arrow_1.Table(schema, batches);
|
|
407
|
+
}
|
|
408
|
+
exports.sanitizeTable = sanitizeTable;
|
|
409
|
+
function sanitizeRecordBatch(batchLike) {
|
|
410
|
+
if (batchLike instanceof arrow_1.RecordBatch) {
|
|
411
|
+
return batchLike;
|
|
412
|
+
}
|
|
413
|
+
if (typeof batchLike !== "object" || batchLike === null) {
|
|
414
|
+
throw Error("Expected a RecordBatch but object was null/undefined");
|
|
415
|
+
}
|
|
416
|
+
if (!("schema" in batchLike)) {
|
|
417
|
+
throw Error("The record batch passed in does not appear to be a record batch (no 'schema' property)");
|
|
418
|
+
}
|
|
419
|
+
if (!("data" in batchLike)) {
|
|
420
|
+
throw Error("The record batch passed in does not appear to be a record batch (no 'data' property)");
|
|
421
|
+
}
|
|
422
|
+
const schema = sanitizeSchema(batchLike.schema);
|
|
423
|
+
const data = sanitizeData(batchLike.data);
|
|
424
|
+
return new arrow_1.RecordBatch(schema, data);
|
|
425
|
+
}
|
|
426
|
+
function sanitizeData(dataLike) {
|
|
427
|
+
if (dataLike instanceof apache_arrow_1.Data) {
|
|
428
|
+
return dataLike;
|
|
429
|
+
}
|
|
430
|
+
return new apache_arrow_1.Data(dataLike.type, dataLike.offset, dataLike.length, dataLike.nullCount, {
|
|
431
|
+
[apache_arrow_1.BufferType.OFFSET]: dataLike.valueOffsets,
|
|
432
|
+
[apache_arrow_1.BufferType.DATA]: dataLike.values,
|
|
433
|
+
[apache_arrow_1.BufferType.VALIDITY]: dataLike.nullBitmap,
|
|
434
|
+
[apache_arrow_1.BufferType.TYPE]: dataLike.typeIds,
|
|
435
|
+
});
|
|
436
|
+
}
|