@dengxifeng/lancedb 0.26.2
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/AGENTS.md +13 -0
- package/CONTRIBUTING.md +76 -0
- package/README.md +37 -0
- package/dist/arrow.d.ts +279 -0
- package/dist/arrow.js +1316 -0
- package/dist/connection.d.ts +259 -0
- package/dist/connection.js +224 -0
- package/dist/embedding/embedding_function.d.ts +103 -0
- package/dist/embedding/embedding_function.js +192 -0
- package/dist/embedding/index.d.ts +27 -0
- package/dist/embedding/index.js +101 -0
- package/dist/embedding/openai.d.ts +16 -0
- package/dist/embedding/openai.js +93 -0
- package/dist/embedding/registry.d.ts +74 -0
- package/dist/embedding/registry.js +165 -0
- package/dist/embedding/transformers.d.ts +36 -0
- package/dist/embedding/transformers.js +122 -0
- package/dist/header.d.ts +162 -0
- package/dist/header.js +217 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +106 -0
- package/dist/indices.d.ts +692 -0
- package/dist/indices.js +156 -0
- package/dist/merge.d.ts +80 -0
- package/dist/merge.js +92 -0
- package/dist/native.d.ts +585 -0
- package/dist/native.js +339 -0
- package/dist/permutation.d.ts +143 -0
- package/dist/permutation.js +184 -0
- package/dist/query.d.ts +581 -0
- package/dist/query.js +853 -0
- package/dist/rerankers/index.d.ts +5 -0
- package/dist/rerankers/index.js +19 -0
- package/dist/rerankers/rrf.d.ts +14 -0
- package/dist/rerankers/rrf.js +28 -0
- package/dist/sanitize.d.ts +32 -0
- package/dist/sanitize.js +473 -0
- package/dist/table.d.ts +581 -0
- package/dist/table.js +321 -0
- package/dist/util.d.ts +14 -0
- package/dist/util.js +77 -0
- package/license_header.txt +2 -0
- package/package.json +122 -0
package/dist/table.d.ts
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { Table as ArrowTable, Data, DataType, IntoVector, MultiVector, Schema } from "./arrow";
|
|
2
|
+
import { IndexOptions } from "./indices";
|
|
3
|
+
import { MergeInsertBuilder } from "./merge";
|
|
4
|
+
import { AddColumnsResult, AddColumnsSql, AddResult, AlterColumnsResult, DeleteResult, DropColumnsResult, IndexConfig, IndexStatistics, OptimizeStats, TableStatistics, Tags, UpdateResult, Table as _NativeTable } from "./native";
|
|
5
|
+
import { FullTextQuery, Query, TakeQuery, VectorQuery } from "./query";
|
|
6
|
+
import { IntoSql } from "./util";
|
|
7
|
+
export { IndexConfig } from "./native";
|
|
8
|
+
/**
|
|
9
|
+
* Options for adding data to a table.
|
|
10
|
+
*/
|
|
11
|
+
export interface AddDataOptions {
|
|
12
|
+
/**
|
|
13
|
+
* If "append" (the default) then the new data will be added to the table
|
|
14
|
+
*
|
|
15
|
+
* If "overwrite" then the new data will replace the existing data in the table.
|
|
16
|
+
*/
|
|
17
|
+
mode: "append" | "overwrite";
|
|
18
|
+
}
|
|
19
|
+
export interface UpdateOptions {
|
|
20
|
+
/**
|
|
21
|
+
* A filter that limits the scope of the update.
|
|
22
|
+
*
|
|
23
|
+
* This should be an SQL filter expression.
|
|
24
|
+
*
|
|
25
|
+
* Only rows that satisfy the expression will be updated.
|
|
26
|
+
*
|
|
27
|
+
* For example, this could be 'my_col == 0' to replace all instances
|
|
28
|
+
* of 0 in a column with some other default value.
|
|
29
|
+
*/
|
|
30
|
+
where: string;
|
|
31
|
+
}
|
|
32
|
+
export interface OptimizeOptions {
|
|
33
|
+
/**
|
|
34
|
+
* If set then all versions older than the given date
|
|
35
|
+
* be removed. The current version will never be removed.
|
|
36
|
+
* The default is 7 days
|
|
37
|
+
* @example
|
|
38
|
+
* // Delete all versions older than 1 day
|
|
39
|
+
* const olderThan = new Date();
|
|
40
|
+
* olderThan.setDate(olderThan.getDate() - 1));
|
|
41
|
+
* tbl.optimize({cleanupOlderThan: olderThan});
|
|
42
|
+
*
|
|
43
|
+
* // Delete all versions except the current version
|
|
44
|
+
* tbl.optimize({cleanupOlderThan: new Date()});
|
|
45
|
+
*/
|
|
46
|
+
cleanupOlderThan: Date;
|
|
47
|
+
deleteUnverified: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface Version {
|
|
50
|
+
version: number;
|
|
51
|
+
timestamp: Date;
|
|
52
|
+
metadata: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A Table is a collection of Records in a LanceDB Database.
|
|
56
|
+
*
|
|
57
|
+
* A Table object is expected to be long lived and reused for multiple operations.
|
|
58
|
+
* Table objects will cache a certain amount of index data in memory. This cache
|
|
59
|
+
* will be freed when the Table is garbage collected. To eagerly free the cache you
|
|
60
|
+
* can call the `close` method. Once the Table is closed, it cannot be used for any
|
|
61
|
+
* further operations.
|
|
62
|
+
*
|
|
63
|
+
* Tables are created using the methods {@link Connection#createTable}
|
|
64
|
+
* and {@link Connection#createEmptyTable}. Existing tables are opened
|
|
65
|
+
* using {@link Connection#openTable}.
|
|
66
|
+
*
|
|
67
|
+
* Closing a table is optional. It not closed, it will be closed when it is garbage
|
|
68
|
+
* collected.
|
|
69
|
+
*
|
|
70
|
+
* @hideconstructor
|
|
71
|
+
*/
|
|
72
|
+
export declare abstract class Table {
|
|
73
|
+
/** Returns the name of the table */
|
|
74
|
+
abstract get name(): string;
|
|
75
|
+
/** Return true if the table has not been closed */
|
|
76
|
+
abstract isOpen(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Close the table, releasing any underlying resources.
|
|
79
|
+
*
|
|
80
|
+
* It is safe to call this method multiple times.
|
|
81
|
+
*
|
|
82
|
+
* Any attempt to use the table after it is closed will result in an error.
|
|
83
|
+
*/
|
|
84
|
+
abstract close(): void;
|
|
85
|
+
/** Return a brief description of the table */
|
|
86
|
+
abstract display(): string;
|
|
87
|
+
/** Get the schema of the table. */
|
|
88
|
+
abstract schema(): Promise<Schema>;
|
|
89
|
+
/**
|
|
90
|
+
* Insert records into this Table.
|
|
91
|
+
* @param {Data} data Records to be inserted into the Table
|
|
92
|
+
* @returns {Promise<AddResult>} A promise that resolves to an object
|
|
93
|
+
* containing the new version number of the table
|
|
94
|
+
*/
|
|
95
|
+
abstract add(data: Data, options?: Partial<AddDataOptions>): Promise<AddResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Update existing records in the Table
|
|
98
|
+
* @param opts.values The values to update. The keys are the column names and the values
|
|
99
|
+
* are the values to set.
|
|
100
|
+
* @returns {Promise<UpdateResult>} A promise that resolves to an object containing
|
|
101
|
+
* the number of rows updated and the new version number
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* table.update({where:"x = 2", values:{"vector": [10, 10]}})
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
abstract update(opts: {
|
|
108
|
+
values: Map<string, IntoSql> | Record<string, IntoSql>;
|
|
109
|
+
} & Partial<UpdateOptions>): Promise<UpdateResult>;
|
|
110
|
+
/**
|
|
111
|
+
* Update existing records in the Table
|
|
112
|
+
* @param opts.valuesSql The values to update. The keys are the column names and the values
|
|
113
|
+
* are the values to set. The values are SQL expressions.
|
|
114
|
+
* @returns {Promise<UpdateResult>} A promise that resolves to an object containing
|
|
115
|
+
* the number of rows updated and the new version number
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* table.update({where:"x = 2", valuesSql:{"x": "x + 1"}})
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
abstract update(opts: {
|
|
122
|
+
valuesSql: Map<string, string> | Record<string, string>;
|
|
123
|
+
} & Partial<UpdateOptions>): Promise<UpdateResult>;
|
|
124
|
+
/**
|
|
125
|
+
* Update existing records in the Table
|
|
126
|
+
*
|
|
127
|
+
* An update operation can be used to adjust existing values. Use the
|
|
128
|
+
* returned builder to specify which columns to update. The new value
|
|
129
|
+
* can be a literal value (e.g. replacing nulls with some default value)
|
|
130
|
+
* or an expression applied to the old value (e.g. incrementing a value)
|
|
131
|
+
*
|
|
132
|
+
* An optional condition can be specified (e.g. "only update if the old
|
|
133
|
+
* value is 0")
|
|
134
|
+
*
|
|
135
|
+
* Note: if your condition is something like "some_id_column == 7" and
|
|
136
|
+
* you are updating many rows (with different ids) then you will get
|
|
137
|
+
* better performance with a single [`merge_insert`] call instead of
|
|
138
|
+
* repeatedly calilng this method.
|
|
139
|
+
* @param {Map<string, string> | Record<string, string>} updates - the
|
|
140
|
+
* columns to update
|
|
141
|
+
* @returns {Promise<UpdateResult>} A promise that resolves to an object
|
|
142
|
+
* containing the number of rows updated and the new version number
|
|
143
|
+
*
|
|
144
|
+
* Keys in the map should specify the name of the column to update.
|
|
145
|
+
* Values in the map provide the new value of the column. These can
|
|
146
|
+
* be SQL literal strings (e.g. "7" or "'foo'") or they can be expressions
|
|
147
|
+
* based on the row being updated (e.g. "my_col + 1")
|
|
148
|
+
* @param {Partial<UpdateOptions>} options - additional options to control
|
|
149
|
+
* the update behavior
|
|
150
|
+
*/
|
|
151
|
+
abstract update(updates: Map<string, string> | Record<string, string>, options?: Partial<UpdateOptions>): Promise<UpdateResult>;
|
|
152
|
+
/** Count the total number of rows in the dataset. */
|
|
153
|
+
abstract countRows(filter?: string): Promise<number>;
|
|
154
|
+
/**
|
|
155
|
+
* Delete the rows that satisfy the predicate.
|
|
156
|
+
* @returns {Promise<DeleteResult>} A promise that resolves to an object
|
|
157
|
+
* containing the new version number of the table
|
|
158
|
+
*/
|
|
159
|
+
abstract delete(predicate: string): Promise<DeleteResult>;
|
|
160
|
+
/**
|
|
161
|
+
* Create an index to speed up queries.
|
|
162
|
+
*
|
|
163
|
+
* Indices can be created on vector columns or scalar columns.
|
|
164
|
+
* Indices on vector columns will speed up vector searches.
|
|
165
|
+
* Indices on scalar columns will speed up filtering (in both
|
|
166
|
+
* vector and non-vector searches)
|
|
167
|
+
*
|
|
168
|
+
* We currently don't support custom named indexes.
|
|
169
|
+
* The index name will always be `${column}_idx`.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // If the column has a vector (fixed size list) data type then
|
|
173
|
+
* // an IvfPq vector index will be created.
|
|
174
|
+
* const table = await conn.openTable("my_table");
|
|
175
|
+
* await table.createIndex("vector");
|
|
176
|
+
* @example
|
|
177
|
+
* // For advanced control over vector index creation you can specify
|
|
178
|
+
* // the index type and options.
|
|
179
|
+
* const table = await conn.openTable("my_table");
|
|
180
|
+
* await table.createIndex("vector", {
|
|
181
|
+
* config: lancedb.Index.ivfPq({
|
|
182
|
+
* numPartitions: 128,
|
|
183
|
+
* numSubVectors: 16,
|
|
184
|
+
* }),
|
|
185
|
+
* });
|
|
186
|
+
* @example
|
|
187
|
+
* // Or create a Scalar index
|
|
188
|
+
* await table.createIndex("my_float_col");
|
|
189
|
+
*/
|
|
190
|
+
abstract createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Drop an index from the table.
|
|
193
|
+
*
|
|
194
|
+
* @param name The name of the index.
|
|
195
|
+
*
|
|
196
|
+
* This does not delete the index from disk, it just removes it from the table.
|
|
197
|
+
* To delete the index, run {@link Table#optimize} after dropping the index.
|
|
198
|
+
*
|
|
199
|
+
* Use {@link Table.listIndices} to find the names of the indices.
|
|
200
|
+
*/
|
|
201
|
+
abstract dropIndex(name: string): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Prewarm an index in the table.
|
|
204
|
+
*
|
|
205
|
+
* @param name The name of the index.
|
|
206
|
+
*
|
|
207
|
+
* This will load the index into memory. This may reduce the cold-start time for
|
|
208
|
+
* future queries. If the index does not fit in the cache then this call may be
|
|
209
|
+
* wasteful.
|
|
210
|
+
*/
|
|
211
|
+
abstract prewarmIndex(name: string): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Waits for asynchronous indexing to complete on the table.
|
|
214
|
+
*
|
|
215
|
+
* @param indexNames The name of the indices to wait for
|
|
216
|
+
* @param timeoutSeconds The number of seconds to wait before timing out
|
|
217
|
+
*
|
|
218
|
+
* This will raise an error if the indices are not created and fully indexed within the timeout.
|
|
219
|
+
*/
|
|
220
|
+
abstract waitForIndex(indexNames: string[], timeoutSeconds: number): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Create a {@link Query} Builder.
|
|
223
|
+
*
|
|
224
|
+
* Queries allow you to search your existing data. By default the query will
|
|
225
|
+
* return all the data in the table in no particular order. The builder
|
|
226
|
+
* returned by this method can be used to control the query using filtering,
|
|
227
|
+
* vector similarity, sorting, and more.
|
|
228
|
+
*
|
|
229
|
+
* Note: By default, all columns are returned. For best performance, you should
|
|
230
|
+
* only fetch the columns you need.
|
|
231
|
+
*
|
|
232
|
+
* When appropriate, various indices and statistics based pruning will be used to
|
|
233
|
+
* accelerate the query.
|
|
234
|
+
* @example
|
|
235
|
+
* // SQL-style filtering
|
|
236
|
+
* //
|
|
237
|
+
* // This query will return up to 1000 rows whose value in the `id` column
|
|
238
|
+
* // is greater than 5. LanceDb supports a broad set of filtering functions.
|
|
239
|
+
* for await (const batch of table
|
|
240
|
+
* .query()
|
|
241
|
+
* .where("id > 1")
|
|
242
|
+
* .select(["id"])
|
|
243
|
+
* .limit(20)) {
|
|
244
|
+
* console.log(batch);
|
|
245
|
+
* }
|
|
246
|
+
* @example
|
|
247
|
+
* // Vector Similarity Search
|
|
248
|
+
* //
|
|
249
|
+
* // This example will find the 10 rows whose value in the "vector" column are
|
|
250
|
+
* // closest to the query vector [1.0, 2.0, 3.0]. If an index has been created
|
|
251
|
+
* // on the "vector" column then this will perform an ANN search.
|
|
252
|
+
* //
|
|
253
|
+
* // The `refineFactor` and `nprobes` methods are used to control the recall /
|
|
254
|
+
* // latency tradeoff of the search.
|
|
255
|
+
* for await (const batch of table
|
|
256
|
+
* .query()
|
|
257
|
+
* .where("id > 1")
|
|
258
|
+
* .select(["id"])
|
|
259
|
+
* .limit(20)) {
|
|
260
|
+
* console.log(batch);
|
|
261
|
+
* }
|
|
262
|
+
* @example
|
|
263
|
+
* // Scan the full dataset
|
|
264
|
+
* //
|
|
265
|
+
* // This query will return everything in the table in no particular order.
|
|
266
|
+
* for await (const batch of table.query()) {
|
|
267
|
+
* console.log(batch);
|
|
268
|
+
* }
|
|
269
|
+
* @returns {Query} A builder that can be used to parameterize the query
|
|
270
|
+
*/
|
|
271
|
+
abstract query(): Query;
|
|
272
|
+
/**
|
|
273
|
+
* Create a query that returns a subset of the rows in the table.
|
|
274
|
+
* @param offsets The offsets of the rows to return.
|
|
275
|
+
* @returns A builder that can be used to parameterize the query.
|
|
276
|
+
*/
|
|
277
|
+
abstract takeOffsets(offsets: number[]): TakeQuery;
|
|
278
|
+
/**
|
|
279
|
+
* Create a query that returns a subset of the rows in the table.
|
|
280
|
+
* @param rowIds The row ids of the rows to return.
|
|
281
|
+
*
|
|
282
|
+
* Row ids returned by `withRowId()` are `bigint`, so `bigint[]` is supported.
|
|
283
|
+
* For convenience / backwards compatibility, `number[]` is also accepted (for
|
|
284
|
+
* small row ids that fit in a safe integer).
|
|
285
|
+
* @returns A builder that can be used to parameterize the query.
|
|
286
|
+
*/
|
|
287
|
+
abstract takeRowIds(rowIds: readonly (bigint | number)[]): TakeQuery;
|
|
288
|
+
/**
|
|
289
|
+
* Create a search query to find the nearest neighbors
|
|
290
|
+
* of the given query
|
|
291
|
+
* @param {string | IntoVector} query - the query, a vector or string
|
|
292
|
+
* @param {string} queryType - the type of the query, "vector", "fts", or "auto"
|
|
293
|
+
* @param {string | string[]} ftsColumns - the columns to search in for full text search
|
|
294
|
+
* for now, only one column can be searched at a time.
|
|
295
|
+
*
|
|
296
|
+
* when "auto" is used, if the query is a string and an embedding function is defined, it will be treated as a vector query
|
|
297
|
+
* if the query is a string and no embedding function is defined, it will be treated as a full text search query
|
|
298
|
+
*/
|
|
299
|
+
abstract search(query: string | IntoVector | MultiVector | FullTextQuery, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
|
|
300
|
+
/**
|
|
301
|
+
* Search the table with a given query vector.
|
|
302
|
+
*
|
|
303
|
+
* This is a convenience method for preparing a vector query and
|
|
304
|
+
* is the same thing as calling `nearestTo` on the builder returned
|
|
305
|
+
* by `query`. @see {@link Query#nearestTo} for more details.
|
|
306
|
+
*/
|
|
307
|
+
abstract vectorSearch(vector: IntoVector | MultiVector): VectorQuery;
|
|
308
|
+
/**
|
|
309
|
+
* Add new columns with defined values.
|
|
310
|
+
* @param {AddColumnsSql[]} newColumnTransforms pairs of column names and
|
|
311
|
+
* the SQL expression to use to calculate the value of the new column. These
|
|
312
|
+
* expressions will be evaluated for each row in the table, and can
|
|
313
|
+
* reference existing columns in the table.
|
|
314
|
+
* @returns {Promise<AddColumnsResult>} A promise that resolves to an object
|
|
315
|
+
* containing the new version number of the table after adding the columns.
|
|
316
|
+
*/
|
|
317
|
+
abstract addColumns(newColumnTransforms: AddColumnsSql[]): Promise<AddColumnsResult>;
|
|
318
|
+
/**
|
|
319
|
+
* Alter the name or nullability of columns.
|
|
320
|
+
* @param {ColumnAlteration[]} columnAlterations One or more alterations to
|
|
321
|
+
* apply to columns.
|
|
322
|
+
* @returns {Promise<AlterColumnsResult>} A promise that resolves to an object
|
|
323
|
+
* containing the new version number of the table after altering the columns.
|
|
324
|
+
*/
|
|
325
|
+
abstract alterColumns(columnAlterations: ColumnAlteration[]): Promise<AlterColumnsResult>;
|
|
326
|
+
/**
|
|
327
|
+
* Drop one or more columns from the dataset
|
|
328
|
+
*
|
|
329
|
+
* This is a metadata-only operation and does not remove the data from the
|
|
330
|
+
* underlying storage. In order to remove the data, you must subsequently
|
|
331
|
+
* call ``compact_files`` to rewrite the data without the removed columns and
|
|
332
|
+
* then call ``cleanup_files`` to remove the old files.
|
|
333
|
+
* @param {string[]} columnNames The names of the columns to drop. These can
|
|
334
|
+
* be nested column references (e.g. "a.b.c") or top-level column names
|
|
335
|
+
* (e.g. "a").
|
|
336
|
+
* @returns {Promise<DropColumnsResult>} A promise that resolves to an object
|
|
337
|
+
* containing the new version number of the table after dropping the columns.
|
|
338
|
+
*/
|
|
339
|
+
abstract dropColumns(columnNames: string[]): Promise<DropColumnsResult>;
|
|
340
|
+
/** Retrieve the version of the table */
|
|
341
|
+
abstract version(): Promise<number>;
|
|
342
|
+
/**
|
|
343
|
+
* Checks out a specific version of the table _This is an in-place operation._
|
|
344
|
+
*
|
|
345
|
+
* This allows viewing previous versions of the table. If you wish to
|
|
346
|
+
* keep writing to the dataset starting from an old version, then use
|
|
347
|
+
* the `restore` function.
|
|
348
|
+
*
|
|
349
|
+
* Calling this method will set the table into time-travel mode. If you
|
|
350
|
+
* wish to return to standard mode, call `checkoutLatest`.
|
|
351
|
+
* @param {number | string} version The version to checkout, could be version number or tag
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* import * as lancedb from "@lancedb/lancedb"
|
|
355
|
+
* const db = await lancedb.connect("./.lancedb");
|
|
356
|
+
* const table = await db.createTable("my_table", [
|
|
357
|
+
* { vector: [1.1, 0.9], type: "vector" },
|
|
358
|
+
* ]);
|
|
359
|
+
*
|
|
360
|
+
* console.log(await table.version()); // 1
|
|
361
|
+
* console.log(table.display());
|
|
362
|
+
* await table.add([{ vector: [0.5, 0.2], type: "vector" }]);
|
|
363
|
+
* await table.checkout(1);
|
|
364
|
+
* console.log(await table.version()); // 2
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
abstract checkout(version: number | string): Promise<void>;
|
|
368
|
+
/**
|
|
369
|
+
* Checkout the latest version of the table. _This is an in-place operation._
|
|
370
|
+
*
|
|
371
|
+
* The table will be set back into standard mode, and will track the latest
|
|
372
|
+
* version of the table.
|
|
373
|
+
*/
|
|
374
|
+
abstract checkoutLatest(): Promise<void>;
|
|
375
|
+
/**
|
|
376
|
+
* List all the versions of the table
|
|
377
|
+
*/
|
|
378
|
+
abstract listVersions(): Promise<Version[]>;
|
|
379
|
+
/**
|
|
380
|
+
* Get a tags manager for this table.
|
|
381
|
+
*
|
|
382
|
+
* Tags allow you to label specific versions of a table with a human-readable name.
|
|
383
|
+
* The returned tags manager can be used to list, create, update, or delete tags.
|
|
384
|
+
*
|
|
385
|
+
* @returns {Tags} A tags manager for this table
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const tagsManager = await table.tags();
|
|
389
|
+
* await tagsManager.create("v1", 1);
|
|
390
|
+
* const tags = await tagsManager.list();
|
|
391
|
+
* console.log(tags); // { "v1": { version: 1, manifestSize: ... } }
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
abstract tags(): Promise<Tags>;
|
|
395
|
+
/**
|
|
396
|
+
* Restore the table to the currently checked out version
|
|
397
|
+
*
|
|
398
|
+
* This operation will fail if checkout has not been called previously
|
|
399
|
+
*
|
|
400
|
+
* This operation will overwrite the latest version of the table with a
|
|
401
|
+
* previous version. Any changes made since the checked out version will
|
|
402
|
+
* no longer be visible.
|
|
403
|
+
*
|
|
404
|
+
* Once the operation concludes the table will no longer be in a checked
|
|
405
|
+
* out state and the read_consistency_interval, if any, will apply.
|
|
406
|
+
*/
|
|
407
|
+
abstract restore(): Promise<void>;
|
|
408
|
+
/**
|
|
409
|
+
* Optimize the on-disk data and indices for better performance.
|
|
410
|
+
*
|
|
411
|
+
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
412
|
+
*
|
|
413
|
+
* Optimization covers three operations:
|
|
414
|
+
*
|
|
415
|
+
* - Compaction: Merges small files into larger ones
|
|
416
|
+
* - Prune: Removes old versions of the dataset
|
|
417
|
+
* - Index: Optimizes the indices, adding new data to existing indices
|
|
418
|
+
*
|
|
419
|
+
*
|
|
420
|
+
* Experimental API
|
|
421
|
+
* ----------------
|
|
422
|
+
*
|
|
423
|
+
* The optimization process is undergoing active development and may change.
|
|
424
|
+
* Our goal with these changes is to improve the performance of optimization and
|
|
425
|
+
* reduce the complexity.
|
|
426
|
+
*
|
|
427
|
+
* That being said, it is essential today to run optimize if you want the best
|
|
428
|
+
* performance. It should be stable and safe to use in production, but it our
|
|
429
|
+
* hope that the API may be simplified (or not even need to be called) in the
|
|
430
|
+
* future.
|
|
431
|
+
*
|
|
432
|
+
* The frequency an application shoudl call optimize is based on the frequency of
|
|
433
|
+
* data modifications. If data is frequently added, deleted, or updated then
|
|
434
|
+
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
435
|
+
* you have added or modified 100,000 or more records or run more than 20 data
|
|
436
|
+
* modification operations.
|
|
437
|
+
*/
|
|
438
|
+
abstract optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
|
|
439
|
+
/** List all indices that have been created with {@link Table.createIndex} */
|
|
440
|
+
abstract listIndices(): Promise<IndexConfig[]>;
|
|
441
|
+
/** Return the table as an arrow table */
|
|
442
|
+
abstract toArrow(): Promise<ArrowTable>;
|
|
443
|
+
abstract mergeInsert(on: string | string[]): MergeInsertBuilder;
|
|
444
|
+
/** List all the stats of a specified index
|
|
445
|
+
*
|
|
446
|
+
* @param {string} name The name of the index.
|
|
447
|
+
* @returns {IndexStatistics | undefined} The stats of the index. If the index does not exist, it will return undefined
|
|
448
|
+
*
|
|
449
|
+
* Use {@link Table.listIndices} to find the names of the indices.
|
|
450
|
+
*/
|
|
451
|
+
abstract indexStats(name: string): Promise<IndexStatistics | undefined>;
|
|
452
|
+
/** Returns table and fragment statistics
|
|
453
|
+
*
|
|
454
|
+
* @returns {TableStatistics} The table and fragment statistics
|
|
455
|
+
*
|
|
456
|
+
*/
|
|
457
|
+
abstract stats(): Promise<TableStatistics>;
|
|
458
|
+
/**
|
|
459
|
+
* Get the initial storage options that were passed in when opening this table.
|
|
460
|
+
*
|
|
461
|
+
* For dynamically refreshed options (e.g., credential vending), use
|
|
462
|
+
* {@link Table.latestStorageOptions}.
|
|
463
|
+
*
|
|
464
|
+
* Warning: This is an internal API and the return value is subject to change.
|
|
465
|
+
*
|
|
466
|
+
* @returns The storage options, or undefined if no storage options were configured.
|
|
467
|
+
*/
|
|
468
|
+
abstract initialStorageOptions(): Promise<Record<string, string> | null | undefined>;
|
|
469
|
+
/**
|
|
470
|
+
* Get the latest storage options, refreshing from provider if configured.
|
|
471
|
+
*
|
|
472
|
+
* This method is useful for credential vending scenarios where storage options
|
|
473
|
+
* may be refreshed dynamically. If no dynamic provider is configured, this
|
|
474
|
+
* returns the initial static options.
|
|
475
|
+
*
|
|
476
|
+
* Warning: This is an internal API and the return value is subject to change.
|
|
477
|
+
*
|
|
478
|
+
* @returns The storage options, or undefined if no storage options were configured.
|
|
479
|
+
*/
|
|
480
|
+
abstract latestStorageOptions(): Promise<Record<string, string> | null | undefined>;
|
|
481
|
+
}
|
|
482
|
+
export declare class LocalTable extends Table {
|
|
483
|
+
private readonly inner;
|
|
484
|
+
constructor(inner: _NativeTable);
|
|
485
|
+
get name(): string;
|
|
486
|
+
isOpen(): boolean;
|
|
487
|
+
close(): void;
|
|
488
|
+
display(): string;
|
|
489
|
+
private getEmbeddingFunctions;
|
|
490
|
+
/** Get the schema of the table. */
|
|
491
|
+
schema(): Promise<Schema>;
|
|
492
|
+
add(data: Data, options?: Partial<AddDataOptions>): Promise<AddResult>;
|
|
493
|
+
update(optsOrUpdates: (Map<string, string> | Record<string, string>) | ({
|
|
494
|
+
values: Map<string, IntoSql> | Record<string, IntoSql>;
|
|
495
|
+
} & Partial<UpdateOptions>) | ({
|
|
496
|
+
valuesSql: Map<string, string> | Record<string, string>;
|
|
497
|
+
} & Partial<UpdateOptions>), options?: Partial<UpdateOptions>): Promise<UpdateResult>;
|
|
498
|
+
countRows(filter?: string): Promise<number>;
|
|
499
|
+
delete(predicate: string): Promise<DeleteResult>;
|
|
500
|
+
createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
|
|
501
|
+
dropIndex(name: string): Promise<void>;
|
|
502
|
+
prewarmIndex(name: string): Promise<void>;
|
|
503
|
+
waitForIndex(indexNames: string[], timeoutSeconds: number): Promise<void>;
|
|
504
|
+
takeOffsets(offsets: number[]): TakeQuery;
|
|
505
|
+
takeRowIds(rowIds: readonly (bigint | number)[]): TakeQuery;
|
|
506
|
+
query(): Query;
|
|
507
|
+
search(query: string | IntoVector | MultiVector | FullTextQuery, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
|
|
508
|
+
vectorSearch(vector: IntoVector | MultiVector): VectorQuery;
|
|
509
|
+
addColumns(newColumnTransforms: AddColumnsSql[]): Promise<AddColumnsResult>;
|
|
510
|
+
alterColumns(columnAlterations: ColumnAlteration[]): Promise<AlterColumnsResult>;
|
|
511
|
+
dropColumns(columnNames: string[]): Promise<DropColumnsResult>;
|
|
512
|
+
version(): Promise<number>;
|
|
513
|
+
checkout(version: number | string): Promise<void>;
|
|
514
|
+
checkoutLatest(): Promise<void>;
|
|
515
|
+
listVersions(): Promise<Version[]>;
|
|
516
|
+
restore(): Promise<void>;
|
|
517
|
+
tags(): Promise<Tags>;
|
|
518
|
+
optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
|
|
519
|
+
listIndices(): Promise<IndexConfig[]>;
|
|
520
|
+
toArrow(): Promise<ArrowTable>;
|
|
521
|
+
indexStats(name: string): Promise<IndexStatistics | undefined>;
|
|
522
|
+
stats(): Promise<TableStatistics>;
|
|
523
|
+
initialStorageOptions(): Promise<Record<string, string> | null | undefined>;
|
|
524
|
+
latestStorageOptions(): Promise<Record<string, string> | null | undefined>;
|
|
525
|
+
mergeInsert(on: string | string[]): MergeInsertBuilder;
|
|
526
|
+
/**
|
|
527
|
+
* Check if the table uses the new manifest path scheme.
|
|
528
|
+
*
|
|
529
|
+
* This function will return true if the table uses the V2 manifest
|
|
530
|
+
* path scheme.
|
|
531
|
+
*/
|
|
532
|
+
usesV2ManifestPaths(): Promise<boolean>;
|
|
533
|
+
/**
|
|
534
|
+
* Migrate the table to use the new manifest path scheme.
|
|
535
|
+
*
|
|
536
|
+
* This function will rename all V1 manifests to V2 manifest paths.
|
|
537
|
+
* These paths provide more efficient opening of datasets with many versions
|
|
538
|
+
* on object stores.
|
|
539
|
+
*
|
|
540
|
+
* This function is idempotent, and can be run multiple times without
|
|
541
|
+
* changing the state of the object store.
|
|
542
|
+
*
|
|
543
|
+
* However, it should not be run while other concurrent operations are happening.
|
|
544
|
+
* And it should also run until completion before resuming other operations.
|
|
545
|
+
*/
|
|
546
|
+
migrateManifestPathsV2(): Promise<void>;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* A definition of a column alteration. The alteration changes the column at
|
|
550
|
+
* `path` to have the new name `name`, to be nullable if `nullable` is true,
|
|
551
|
+
* and to have the data type `data_type`. At least one of `rename` or `nullable`
|
|
552
|
+
* must be provided.
|
|
553
|
+
*/
|
|
554
|
+
export interface ColumnAlteration {
|
|
555
|
+
/**
|
|
556
|
+
* The path to the column to alter. This is a dot-separated path to the column.
|
|
557
|
+
* If it is a top-level column then it is just the name of the column. If it is
|
|
558
|
+
* a nested column then it is the path to the column, e.g. "a.b.c" for a column
|
|
559
|
+
* `c` nested inside a column `b` nested inside a column `a`.
|
|
560
|
+
*/
|
|
561
|
+
path: string;
|
|
562
|
+
/**
|
|
563
|
+
* The new name of the column. If not provided then the name will not be changed.
|
|
564
|
+
* This must be distinct from the names of all other columns in the table.
|
|
565
|
+
*/
|
|
566
|
+
rename?: string;
|
|
567
|
+
/**
|
|
568
|
+
* A new data type for the column. If not provided then the data type will not be changed.
|
|
569
|
+
* Changing data types is limited to casting to the same general type. For example, these
|
|
570
|
+
* changes are valid:
|
|
571
|
+
* * `int32` -> `int64` (integers)
|
|
572
|
+
* * `double` -> `float` (floats)
|
|
573
|
+
* * `string` -> `large_string` (strings)
|
|
574
|
+
* But these changes are not:
|
|
575
|
+
* * `int32` -> `double` (mix integers and floats)
|
|
576
|
+
* * `string` -> `int32` (mix strings and integers)
|
|
577
|
+
*/
|
|
578
|
+
dataType?: string | DataType;
|
|
579
|
+
/** Set the new nullability. Note that a nullable column cannot be made non-nullable. */
|
|
580
|
+
nullable?: boolean;
|
|
581
|
+
}
|