@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
|
@@ -13,10 +13,13 @@
|
|
|
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.Table = void 0;
|
|
16
|
+
exports.LocalTable = exports.Table = void 0;
|
|
17
17
|
const arrow_1 = require("./arrow");
|
|
18
18
|
const registry_1 = require("./embedding/registry");
|
|
19
|
+
const merge_1 = require("./merge");
|
|
19
20
|
const query_1 = require("./query");
|
|
21
|
+
const sanitize_1 = require("./sanitize");
|
|
22
|
+
const util_1 = require("./util");
|
|
20
23
|
/**
|
|
21
24
|
* A Table is a collection of Records in a LanceDB Database.
|
|
22
25
|
*
|
|
@@ -30,30 +33,52 @@ const query_1 = require("./query");
|
|
|
30
33
|
* collected.
|
|
31
34
|
*/
|
|
32
35
|
class Table {
|
|
36
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
37
|
+
return this.display();
|
|
38
|
+
}
|
|
39
|
+
static async parseTableData(data, options, streaming = false) {
|
|
40
|
+
let mode = options?.mode ?? "create";
|
|
41
|
+
const existOk = options?.existOk ?? false;
|
|
42
|
+
if (mode === "create" && existOk) {
|
|
43
|
+
mode = "exist_ok";
|
|
44
|
+
}
|
|
45
|
+
let table;
|
|
46
|
+
if ((0, arrow_1.isArrowTable)(data)) {
|
|
47
|
+
table = (0, sanitize_1.sanitizeTable)(data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
table = (0, arrow_1.makeArrowTable)(data, options);
|
|
51
|
+
}
|
|
52
|
+
if (streaming) {
|
|
53
|
+
const buf = await (0, arrow_1.fromTableToStreamBuffer)(table, options?.embeddingFunction, options?.schema);
|
|
54
|
+
return { buf, mode };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const buf = await (0, arrow_1.fromTableToBuffer)(table, options?.embeddingFunction, options?.schema);
|
|
58
|
+
return { buf, mode };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Table = Table;
|
|
63
|
+
class LocalTable extends Table {
|
|
33
64
|
inner;
|
|
34
|
-
/** Construct a Table. Internal use only. */
|
|
35
65
|
constructor(inner) {
|
|
66
|
+
super();
|
|
36
67
|
this.inner = inner;
|
|
37
68
|
}
|
|
38
|
-
|
|
69
|
+
get name() {
|
|
70
|
+
return this.inner.name;
|
|
71
|
+
}
|
|
39
72
|
isOpen() {
|
|
40
73
|
return this.inner.isOpen();
|
|
41
74
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Close the table, releasing any underlying resources.
|
|
44
|
-
*
|
|
45
|
-
* It is safe to call this method multiple times.
|
|
46
|
-
*
|
|
47
|
-
* Any attempt to use the table after it is closed will result in an error.
|
|
48
|
-
*/
|
|
49
75
|
close() {
|
|
50
76
|
this.inner.close();
|
|
51
77
|
}
|
|
52
|
-
/** Return a brief description of the table */
|
|
53
78
|
display() {
|
|
54
79
|
return this.inner.display();
|
|
55
80
|
}
|
|
56
|
-
async
|
|
81
|
+
async getEmbeddingFunctions() {
|
|
57
82
|
const schema = await this.schema();
|
|
58
83
|
const registry = (0, registry_1.getRegistry)();
|
|
59
84
|
return registry.parseFunctions(schema.metadata);
|
|
@@ -64,10 +89,6 @@ class Table {
|
|
|
64
89
|
const tbl = (0, arrow_1.tableFromIPC)(schemaBuf);
|
|
65
90
|
return tbl.schema;
|
|
66
91
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Insert records into this Table.
|
|
69
|
-
* @param {Data} data Records to be inserted into the Table
|
|
70
|
-
*/
|
|
71
92
|
async add(data, options) {
|
|
72
93
|
const mode = options?.mode ?? "append";
|
|
73
94
|
const schema = await this.schema();
|
|
@@ -76,132 +97,63 @@ class Table {
|
|
|
76
97
|
const buffer = await (0, arrow_1.fromDataToBuffer)(data, functions.values().next().value, schema);
|
|
77
98
|
await this.inner.add(buffer, mode);
|
|
78
99
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* An optional condition can be specified (e.g. "only update if the old
|
|
88
|
-
* value is 0")
|
|
89
|
-
*
|
|
90
|
-
* Note: if your condition is something like "some_id_column == 7" and
|
|
91
|
-
* you are updating many rows (with different ids) then you will get
|
|
92
|
-
* better performance with a single [`merge_insert`] call instead of
|
|
93
|
-
* repeatedly calilng this method.
|
|
94
|
-
* @param {Map<string, string> | Record<string, string>} updates - the
|
|
95
|
-
* columns to update
|
|
96
|
-
*
|
|
97
|
-
* Keys in the map should specify the name of the column to update.
|
|
98
|
-
* Values in the map provide the new value of the column. These can
|
|
99
|
-
* be SQL literal strings (e.g. "7" or "'foo'") or they can be expressions
|
|
100
|
-
* based on the row being updated (e.g. "my_col + 1")
|
|
101
|
-
* @param {Partial<UpdateOptions>} options - additional options to control
|
|
102
|
-
* the update behavior
|
|
103
|
-
*/
|
|
104
|
-
async update(updates, options) {
|
|
105
|
-
const onlyIf = options?.where;
|
|
100
|
+
async update(optsOrUpdates, options) {
|
|
101
|
+
const isValues = "values" in optsOrUpdates && typeof optsOrUpdates.values !== "string";
|
|
102
|
+
const isValuesSql = "valuesSql" in optsOrUpdates &&
|
|
103
|
+
typeof optsOrUpdates.valuesSql !== "string";
|
|
104
|
+
const isMap = (obj) => {
|
|
105
|
+
return obj instanceof Map;
|
|
106
|
+
};
|
|
107
|
+
let predicate;
|
|
106
108
|
let columns;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
switch (true) {
|
|
110
|
+
case isMap(optsOrUpdates):
|
|
111
|
+
columns = Array.from(optsOrUpdates.entries());
|
|
112
|
+
predicate = options?.where;
|
|
113
|
+
break;
|
|
114
|
+
case isValues && isMap(optsOrUpdates.values):
|
|
115
|
+
columns = Array.from(optsOrUpdates.values.entries()).map(([k, v]) => [
|
|
116
|
+
k,
|
|
117
|
+
(0, util_1.toSQL)(v),
|
|
118
|
+
]);
|
|
119
|
+
predicate = optsOrUpdates.where;
|
|
120
|
+
break;
|
|
121
|
+
case isValues && !isMap(optsOrUpdates.values):
|
|
122
|
+
columns = Object.entries(optsOrUpdates.values).map(([k, v]) => [
|
|
123
|
+
k,
|
|
124
|
+
(0, util_1.toSQL)(v),
|
|
125
|
+
]);
|
|
126
|
+
predicate = optsOrUpdates.where;
|
|
127
|
+
break;
|
|
128
|
+
case isValuesSql && isMap(optsOrUpdates.valuesSql):
|
|
129
|
+
columns = Array.from(optsOrUpdates.valuesSql.entries());
|
|
130
|
+
predicate = optsOrUpdates.where;
|
|
131
|
+
break;
|
|
132
|
+
case isValuesSql && !isMap(optsOrUpdates.valuesSql):
|
|
133
|
+
columns = Object.entries(optsOrUpdates.valuesSql).map(([k, v]) => [
|
|
134
|
+
k,
|
|
135
|
+
v,
|
|
136
|
+
]);
|
|
137
|
+
predicate = optsOrUpdates.where;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
columns = Object.entries(optsOrUpdates);
|
|
141
|
+
predicate = options?.where;
|
|
112
142
|
}
|
|
113
|
-
await this.inner.update(
|
|
143
|
+
await this.inner.update(predicate, columns);
|
|
114
144
|
}
|
|
115
|
-
/** Count the total number of rows in the dataset. */
|
|
116
145
|
async countRows(filter) {
|
|
117
146
|
return await this.inner.countRows(filter);
|
|
118
147
|
}
|
|
119
|
-
/** Delete the rows that satisfy the predicate. */
|
|
120
148
|
async delete(predicate) {
|
|
121
149
|
await this.inner.delete(predicate);
|
|
122
150
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Create an index to speed up queries.
|
|
125
|
-
*
|
|
126
|
-
* Indices can be created on vector columns or scalar columns.
|
|
127
|
-
* Indices on vector columns will speed up vector searches.
|
|
128
|
-
* Indices on scalar columns will speed up filtering (in both
|
|
129
|
-
* vector and non-vector searches)
|
|
130
|
-
* @example
|
|
131
|
-
* // If the column has a vector (fixed size list) data type then
|
|
132
|
-
* // an IvfPq vector index will be created.
|
|
133
|
-
* const table = await conn.openTable("my_table");
|
|
134
|
-
* await table.createIndex("vector");
|
|
135
|
-
* @example
|
|
136
|
-
* // For advanced control over vector index creation you can specify
|
|
137
|
-
* // the index type and options.
|
|
138
|
-
* const table = await conn.openTable("my_table");
|
|
139
|
-
* await table.createIndex("vector", {
|
|
140
|
-
* config: lancedb.Index.ivfPq({
|
|
141
|
-
* numPartitions: 128,
|
|
142
|
-
* numSubVectors: 16,
|
|
143
|
-
* }),
|
|
144
|
-
* });
|
|
145
|
-
* @example
|
|
146
|
-
* // Or create a Scalar index
|
|
147
|
-
* await table.createIndex("my_float_col");
|
|
148
|
-
*/
|
|
149
151
|
async createIndex(column, options) {
|
|
150
152
|
// Bit of a hack to get around the fact that TS has no package-scope.
|
|
151
153
|
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
152
154
|
const nativeIndex = options?.config?.inner;
|
|
153
155
|
await this.inner.createIndex(nativeIndex, column, options?.replace);
|
|
154
156
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Create a {@link Query} Builder.
|
|
157
|
-
*
|
|
158
|
-
* Queries allow you to search your existing data. By default the query will
|
|
159
|
-
* return all the data in the table in no particular order. The builder
|
|
160
|
-
* returned by this method can be used to control the query using filtering,
|
|
161
|
-
* vector similarity, sorting, and more.
|
|
162
|
-
*
|
|
163
|
-
* Note: By default, all columns are returned. For best performance, you should
|
|
164
|
-
* only fetch the columns you need.
|
|
165
|
-
*
|
|
166
|
-
* When appropriate, various indices and statistics based pruning will be used to
|
|
167
|
-
* accelerate the query.
|
|
168
|
-
* @example
|
|
169
|
-
* // SQL-style filtering
|
|
170
|
-
* //
|
|
171
|
-
* // This query will return up to 1000 rows whose value in the `id` column
|
|
172
|
-
* // is greater than 5. LanceDb supports a broad set of filtering functions.
|
|
173
|
-
* for await (const batch of table
|
|
174
|
-
* .query()
|
|
175
|
-
* .where("id > 1")
|
|
176
|
-
* .select(["id"])
|
|
177
|
-
* .limit(20)) {
|
|
178
|
-
* console.log(batch);
|
|
179
|
-
* }
|
|
180
|
-
* @example
|
|
181
|
-
* // Vector Similarity Search
|
|
182
|
-
* //
|
|
183
|
-
* // This example will find the 10 rows whose value in the "vector" column are
|
|
184
|
-
* // closest to the query vector [1.0, 2.0, 3.0]. If an index has been created
|
|
185
|
-
* // on the "vector" column then this will perform an ANN search.
|
|
186
|
-
* //
|
|
187
|
-
* // The `refineFactor` and `nprobes` methods are used to control the recall /
|
|
188
|
-
* // latency tradeoff of the search.
|
|
189
|
-
* for await (const batch of table
|
|
190
|
-
* .query()
|
|
191
|
-
* .where("id > 1")
|
|
192
|
-
* .select(["id"])
|
|
193
|
-
* .limit(20)) {
|
|
194
|
-
* console.log(batch);
|
|
195
|
-
* }
|
|
196
|
-
* @example
|
|
197
|
-
* // Scan the full dataset
|
|
198
|
-
* //
|
|
199
|
-
* // This query will return everything in the table in no particular order.
|
|
200
|
-
* for await (const batch of table.query()) {
|
|
201
|
-
* console.log(batch);
|
|
202
|
-
* }
|
|
203
|
-
* @returns {Query} A builder that can be used to parameterize the query
|
|
204
|
-
*/
|
|
205
157
|
query() {
|
|
206
158
|
return new query_1.Query(this.inner);
|
|
207
159
|
}
|
|
@@ -210,7 +162,7 @@ class Table {
|
|
|
210
162
|
return this.vectorSearch(query);
|
|
211
163
|
}
|
|
212
164
|
else {
|
|
213
|
-
|
|
165
|
+
const queryPromise = this.getEmbeddingFunctions().then(async (functions) => {
|
|
214
166
|
// TODO: Support multiple embedding functions
|
|
215
167
|
const embeddingFunc = functions
|
|
216
168
|
.values()
|
|
@@ -218,140 +170,36 @@ class Table {
|
|
|
218
170
|
if (!embeddingFunc) {
|
|
219
171
|
return Promise.reject(new Error("No embedding functions are defined in the table"));
|
|
220
172
|
}
|
|
221
|
-
|
|
222
|
-
return this.query().nearestTo(embeddings);
|
|
173
|
+
return await embeddingFunc.function.computeQueryEmbeddings(query);
|
|
223
174
|
});
|
|
175
|
+
return this.query().nearestTo(queryPromise);
|
|
224
176
|
}
|
|
225
177
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Search the table with a given query vector.
|
|
228
|
-
*
|
|
229
|
-
* This is a convenience method for preparing a vector query and
|
|
230
|
-
* is the same thing as calling `nearestTo` on the builder returned
|
|
231
|
-
* by `query`. @see {@link Query#nearestTo} for more details.
|
|
232
|
-
*/
|
|
233
178
|
vectorSearch(vector) {
|
|
234
179
|
return this.query().nearestTo(vector);
|
|
235
180
|
}
|
|
236
181
|
// TODO: Support BatchUDF
|
|
237
|
-
/**
|
|
238
|
-
* Add new columns with defined values.
|
|
239
|
-
* @param {AddColumnsSql[]} newColumnTransforms pairs of column names and
|
|
240
|
-
* the SQL expression to use to calculate the value of the new column. These
|
|
241
|
-
* expressions will be evaluated for each row in the table, and can
|
|
242
|
-
* reference existing columns in the table.
|
|
243
|
-
*/
|
|
244
182
|
async addColumns(newColumnTransforms) {
|
|
245
183
|
await this.inner.addColumns(newColumnTransforms);
|
|
246
184
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Alter the name or nullability of columns.
|
|
249
|
-
* @param {ColumnAlteration[]} columnAlterations One or more alterations to
|
|
250
|
-
* apply to columns.
|
|
251
|
-
*/
|
|
252
185
|
async alterColumns(columnAlterations) {
|
|
253
186
|
await this.inner.alterColumns(columnAlterations);
|
|
254
187
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Drop one or more columns from the dataset
|
|
257
|
-
*
|
|
258
|
-
* This is a metadata-only operation and does not remove the data from the
|
|
259
|
-
* underlying storage. In order to remove the data, you must subsequently
|
|
260
|
-
* call ``compact_files`` to rewrite the data without the removed columns and
|
|
261
|
-
* then call ``cleanup_files`` to remove the old files.
|
|
262
|
-
* @param {string[]} columnNames The names of the columns to drop. These can
|
|
263
|
-
* be nested column references (e.g. "a.b.c") or top-level column names
|
|
264
|
-
* (e.g. "a").
|
|
265
|
-
*/
|
|
266
188
|
async dropColumns(columnNames) {
|
|
267
189
|
await this.inner.dropColumns(columnNames);
|
|
268
190
|
}
|
|
269
|
-
/** Retrieve the version of the table */
|
|
270
191
|
async version() {
|
|
271
192
|
return await this.inner.version();
|
|
272
193
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Checks out a specific version of the table _This is an in-place operation._
|
|
275
|
-
*
|
|
276
|
-
* This allows viewing previous versions of the table. If you wish to
|
|
277
|
-
* keep writing to the dataset starting from an old version, then use
|
|
278
|
-
* the `restore` function.
|
|
279
|
-
*
|
|
280
|
-
* Calling this method will set the table into time-travel mode. If you
|
|
281
|
-
* wish to return to standard mode, call `checkoutLatest`.
|
|
282
|
-
* @param {number} version The version to checkout
|
|
283
|
-
* @example
|
|
284
|
-
* ```typescript
|
|
285
|
-
* import * as lancedb from "@lancedb/lancedb"
|
|
286
|
-
* const db = await lancedb.connect("./.lancedb");
|
|
287
|
-
* const table = await db.createTable("my_table", [
|
|
288
|
-
* { vector: [1.1, 0.9], type: "vector" },
|
|
289
|
-
* ]);
|
|
290
|
-
*
|
|
291
|
-
* console.log(await table.version()); // 1
|
|
292
|
-
* console.log(table.display());
|
|
293
|
-
* await table.add([{ vector: [0.5, 0.2], type: "vector" }]);
|
|
294
|
-
* await table.checkout(1);
|
|
295
|
-
* console.log(await table.version()); // 2
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
194
|
async checkout(version) {
|
|
299
195
|
await this.inner.checkout(version);
|
|
300
196
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Checkout the latest version of the table. _This is an in-place operation._
|
|
303
|
-
*
|
|
304
|
-
* The table will be set back into standard mode, and will track the latest
|
|
305
|
-
* version of the table.
|
|
306
|
-
*/
|
|
307
197
|
async checkoutLatest() {
|
|
308
198
|
await this.inner.checkoutLatest();
|
|
309
199
|
}
|
|
310
|
-
/**
|
|
311
|
-
* Restore the table to the currently checked out version
|
|
312
|
-
*
|
|
313
|
-
* This operation will fail if checkout has not been called previously
|
|
314
|
-
*
|
|
315
|
-
* This operation will overwrite the latest version of the table with a
|
|
316
|
-
* previous version. Any changes made since the checked out version will
|
|
317
|
-
* no longer be visible.
|
|
318
|
-
*
|
|
319
|
-
* Once the operation concludes the table will no longer be in a checked
|
|
320
|
-
* out state and the read_consistency_interval, if any, will apply.
|
|
321
|
-
*/
|
|
322
200
|
async restore() {
|
|
323
201
|
await this.inner.restore();
|
|
324
202
|
}
|
|
325
|
-
/**
|
|
326
|
-
* Optimize the on-disk data and indices for better performance.
|
|
327
|
-
*
|
|
328
|
-
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
329
|
-
*
|
|
330
|
-
* Optimization covers three operations:
|
|
331
|
-
*
|
|
332
|
-
* - Compaction: Merges small files into larger ones
|
|
333
|
-
* - Prune: Removes old versions of the dataset
|
|
334
|
-
* - Index: Optimizes the indices, adding new data to existing indices
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* Experimental API
|
|
338
|
-
* ----------------
|
|
339
|
-
*
|
|
340
|
-
* The optimization process is undergoing active development and may change.
|
|
341
|
-
* Our goal with these changes is to improve the performance of optimization and
|
|
342
|
-
* reduce the complexity.
|
|
343
|
-
*
|
|
344
|
-
* That being said, it is essential today to run optimize if you want the best
|
|
345
|
-
* performance. It should be stable and safe to use in production, but it our
|
|
346
|
-
* hope that the API may be simplified (or not even need to be called) in the
|
|
347
|
-
* future.
|
|
348
|
-
*
|
|
349
|
-
* The frequency an application shoudl call optimize is based on the frequency of
|
|
350
|
-
* data modifications. If data is frequently added, deleted, or updated then
|
|
351
|
-
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
352
|
-
* you have added or modified 100,000 or more records or run more than 20 data
|
|
353
|
-
* modification operations.
|
|
354
|
-
*/
|
|
355
203
|
async optimize(options) {
|
|
356
204
|
let cleanupOlderThanMs;
|
|
357
205
|
if (options?.cleanupOlderThan !== undefined &&
|
|
@@ -361,13 +209,22 @@ class Table {
|
|
|
361
209
|
}
|
|
362
210
|
return await this.inner.optimize(cleanupOlderThanMs);
|
|
363
211
|
}
|
|
364
|
-
/** List all indices that have been created with {@link Table.createIndex} */
|
|
365
212
|
async listIndices() {
|
|
366
213
|
return await this.inner.listIndices();
|
|
367
214
|
}
|
|
368
|
-
/** Return the table as an arrow table */
|
|
369
215
|
async toArrow() {
|
|
370
216
|
return await this.query().toArrow();
|
|
371
217
|
}
|
|
218
|
+
async indexStats(name) {
|
|
219
|
+
const stats = await this.inner.indexStats(name);
|
|
220
|
+
if (stats === null) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
return stats;
|
|
224
|
+
}
|
|
225
|
+
mergeInsert(on) {
|
|
226
|
+
on = Array.isArray(on) ? on : [on];
|
|
227
|
+
return new merge_1.MergeInsertBuilder(this.inner.mergeInsert(on));
|
|
228
|
+
}
|
|
372
229
|
}
|
|
373
|
-
exports.
|
|
230
|
+
exports.LocalTable = LocalTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export type IntoSql = string | number | boolean | null | Date | ArrayBufferLike | Buffer | IntoSql[];
|
|
3
|
+
export declare function toSQL(value: IntoSql): string;
|
|
4
|
+
export declare class TTLCache {
|
|
5
|
+
private readonly ttl;
|
|
6
|
+
private readonly cache;
|
|
7
|
+
/**
|
|
8
|
+
* @param ttl Time to live in milliseconds
|
|
9
|
+
*/
|
|
10
|
+
constructor(ttl: number);
|
|
11
|
+
get(key: string): any | undefined;
|
|
12
|
+
set(key: string, value: any): void;
|
|
13
|
+
delete(key: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TTLCache = exports.toSQL = void 0;
|
|
4
|
+
function toSQL(value) {
|
|
5
|
+
if (typeof value === "string") {
|
|
6
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
7
|
+
}
|
|
8
|
+
else if (typeof value === "number") {
|
|
9
|
+
return value.toString();
|
|
10
|
+
}
|
|
11
|
+
else if (typeof value === "boolean") {
|
|
12
|
+
return value ? "TRUE" : "FALSE";
|
|
13
|
+
}
|
|
14
|
+
else if (value === null) {
|
|
15
|
+
return "NULL";
|
|
16
|
+
}
|
|
17
|
+
else if (value instanceof Date) {
|
|
18
|
+
return `'${value.toISOString()}'`;
|
|
19
|
+
}
|
|
20
|
+
else if (Array.isArray(value)) {
|
|
21
|
+
return `[${value.map(toSQL).join(", ")}]`;
|
|
22
|
+
}
|
|
23
|
+
else if (Buffer.isBuffer(value)) {
|
|
24
|
+
return `X'${value.toString("hex")}'`;
|
|
25
|
+
}
|
|
26
|
+
else if (value instanceof ArrayBuffer) {
|
|
27
|
+
return `X'${Buffer.from(value).toString("hex")}'`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error(`Unsupported value type: ${typeof value} value: (${value})`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.toSQL = toSQL;
|
|
34
|
+
class TTLCache {
|
|
35
|
+
ttl;
|
|
36
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
37
|
+
cache;
|
|
38
|
+
/**
|
|
39
|
+
* @param ttl Time to live in milliseconds
|
|
40
|
+
*/
|
|
41
|
+
constructor(ttl) {
|
|
42
|
+
this.ttl = ttl;
|
|
43
|
+
this.cache = new Map();
|
|
44
|
+
}
|
|
45
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
46
|
+
get(key) {
|
|
47
|
+
const entry = this.cache.get(key);
|
|
48
|
+
if (entry === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (entry.expires < Date.now()) {
|
|
52
|
+
this.cache.delete(key);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return entry.value;
|
|
56
|
+
}
|
|
57
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
58
|
+
set(key, value) {
|
|
59
|
+
this.cache.set(key, { value, expires: Date.now() + this.ttl });
|
|
60
|
+
}
|
|
61
|
+
delete(key) {
|
|
62
|
+
this.cache.delete(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.TTLCache = TTLCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lancedb/lancedb",
|
|
3
|
-
"
|
|
3
|
+
"description": "LanceDB: A serverless, low-latency vector database for AI applications",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"database",
|
|
6
|
+
"lance",
|
|
7
|
+
"lancedb",
|
|
8
|
+
"search",
|
|
9
|
+
"vector",
|
|
10
|
+
"vector database",
|
|
11
|
+
"ann"
|
|
12
|
+
],
|
|
13
|
+
"version": "0.7.0",
|
|
4
14
|
"main": "dist/index.js",
|
|
5
15
|
"exports": {
|
|
6
16
|
".": "./dist/index.js",
|
|
@@ -24,9 +34,10 @@
|
|
|
24
34
|
"devDependencies": {
|
|
25
35
|
"@aws-sdk/client-kms": "^3.33.0",
|
|
26
36
|
"@aws-sdk/client-s3": "^3.33.0",
|
|
37
|
+
"@aws-sdk/client-dynamodb": "^3.33.0",
|
|
27
38
|
"@biomejs/biome": "^1.7.3",
|
|
28
39
|
"@jest/globals": "^29.7.0",
|
|
29
|
-
"@napi-rs/cli": "^2.18.
|
|
40
|
+
"@napi-rs/cli": "^2.18.3",
|
|
30
41
|
"@types/jest": "^29.1.2",
|
|
31
42
|
"@types/tmp": "^0.2.6",
|
|
32
43
|
"apache-arrow-old": "npm:apache-arrow@13.0.0",
|
|
@@ -38,7 +49,8 @@
|
|
|
38
49
|
"typedoc": "^0.25.7",
|
|
39
50
|
"typedoc-plugin-markdown": "^3.17.1",
|
|
40
51
|
"typescript": "^5.3.3",
|
|
41
|
-
"typescript-eslint": "^7.1.0"
|
|
52
|
+
"typescript-eslint": "^7.1.0",
|
|
53
|
+
"@types/axios": "^0.14.0"
|
|
42
54
|
},
|
|
43
55
|
"ava": {
|
|
44
56
|
"timeout": "3m"
|
|
@@ -64,7 +76,7 @@
|
|
|
64
76
|
"lint-ci": "biome ci .",
|
|
65
77
|
"docs": "typedoc --plugin typedoc-plugin-markdown --out ../docs/src/js lancedb/index.ts",
|
|
66
78
|
"lint": "biome check . && biome format .",
|
|
67
|
-
"lint-fix": "biome check --
|
|
79
|
+
"lint-fix": "biome check --write . && biome format --write .",
|
|
68
80
|
"prepublishOnly": "napi prepublish -t npm",
|
|
69
81
|
"test": "jest --verbose",
|
|
70
82
|
"integration": "S3_TEST=1 npm run test",
|
|
@@ -72,15 +84,17 @@
|
|
|
72
84
|
"version": "napi version"
|
|
73
85
|
},
|
|
74
86
|
"dependencies": {
|
|
75
|
-
"
|
|
76
|
-
"openai": "^4.29.2",
|
|
87
|
+
"axios": "^1.7.2",
|
|
77
88
|
"reflect-metadata": "^0.2.2"
|
|
78
89
|
},
|
|
79
90
|
"optionalDependencies": {
|
|
80
|
-
"@lancedb/lancedb-darwin-arm64": "0.
|
|
81
|
-
"@lancedb/lancedb-linux-arm64-gnu": "0.
|
|
82
|
-
"@lancedb/lancedb-darwin-x64": "0.
|
|
83
|
-
"@lancedb/lancedb-linux-x64-gnu": "0.
|
|
84
|
-
"@lancedb/lancedb-win32-x64-msvc": "0.
|
|
91
|
+
"@lancedb/lancedb-darwin-arm64": "0.7.0",
|
|
92
|
+
"@lancedb/lancedb-linux-arm64-gnu": "0.7.0",
|
|
93
|
+
"@lancedb/lancedb-darwin-x64": "0.7.0",
|
|
94
|
+
"@lancedb/lancedb-linux-x64-gnu": "0.7.0",
|
|
95
|
+
"@lancedb/lancedb-win32-x64-msvc": "0.7.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"apache-arrow": "^15.0.0"
|
|
85
99
|
}
|
|
86
100
|
}
|