@lancedb/lancedb 0.13.1-beta.0 → 0.14.0-beta.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/dist/table.d.ts DELETED
@@ -1,425 +0,0 @@
1
- import { Table as ArrowTable, Data, IntoVector, Schema, TableLike } from "./arrow";
2
- import { CreateTableOptions } from "./connection";
3
- import { IndexOptions } from "./indices";
4
- import { MergeInsertBuilder } from "./merge";
5
- import { AddColumnsSql, ColumnAlteration, IndexConfig, IndexStatistics, OptimizeStats, Table as _NativeTable } from "./native";
6
- import { Query, VectorQuery } from "./query";
7
- import { IntoSql } from "./util";
8
- export { IndexConfig } from "./native";
9
- /**
10
- * Options for adding data to a table.
11
- */
12
- export interface AddDataOptions {
13
- /**
14
- * If "append" (the default) then the new data will be added to the table
15
- *
16
- * If "overwrite" then the new data will replace the existing data in the table.
17
- */
18
- mode: "append" | "overwrite";
19
- }
20
- export interface UpdateOptions {
21
- /**
22
- * A filter that limits the scope of the update.
23
- *
24
- * This should be an SQL filter expression.
25
- *
26
- * Only rows that satisfy the expression will be updated.
27
- *
28
- * For example, this could be 'my_col == 0' to replace all instances
29
- * of 0 in a column with some other default value.
30
- */
31
- where: string;
32
- }
33
- export interface OptimizeOptions {
34
- /**
35
- * If set then all versions older than the given date
36
- * be removed. The current version will never be removed.
37
- * The default is 7 days
38
- * @example
39
- * // Delete all versions older than 1 day
40
- * const olderThan = new Date();
41
- * olderThan.setDate(olderThan.getDate() - 1));
42
- * tbl.cleanupOlderVersions(olderThan);
43
- *
44
- * // Delete all versions except the current version
45
- * tbl.cleanupOlderVersions(new Date());
46
- */
47
- cleanupOlderThan: Date;
48
- deleteUnverified: boolean;
49
- }
50
- export interface Version {
51
- version: number;
52
- timestamp: Date;
53
- metadata: Record<string, string>;
54
- }
55
- /**
56
- * A Table is a collection of Records in a LanceDB Database.
57
- *
58
- * A Table object is expected to be long lived and reused for multiple operations.
59
- * Table objects will cache a certain amount of index data in memory. This cache
60
- * will be freed when the Table is garbage collected. To eagerly free the cache you
61
- * can call the `close` method. Once the Table is closed, it cannot be used for any
62
- * further operations.
63
- *
64
- * Closing a table is optional. It not closed, it will be closed when it is garbage
65
- * collected.
66
- */
67
- export declare abstract class Table {
68
- /** Returns the name of the table */
69
- abstract get name(): string;
70
- /** Return true if the table has not been closed */
71
- abstract isOpen(): boolean;
72
- /**
73
- * Close the table, releasing any underlying resources.
74
- *
75
- * It is safe to call this method multiple times.
76
- *
77
- * Any attempt to use the table after it is closed will result in an error.
78
- */
79
- abstract close(): void;
80
- /** Return a brief description of the table */
81
- abstract display(): string;
82
- /** Get the schema of the table. */
83
- abstract schema(): Promise<Schema>;
84
- /**
85
- * Insert records into this Table.
86
- * @param {Data} data Records to be inserted into the Table
87
- */
88
- abstract add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
89
- /**
90
- * Update existing records in the Table
91
- * @param opts.values The values to update. The keys are the column names and the values
92
- * are the values to set.
93
- * @example
94
- * ```ts
95
- * table.update({where:"x = 2", values:{"vector": [10, 10]}})
96
- * ```
97
- */
98
- abstract update(opts: {
99
- values: Map<string, IntoSql> | Record<string, IntoSql>;
100
- } & Partial<UpdateOptions>): Promise<void>;
101
- /**
102
- * Update existing records in the Table
103
- * @param opts.valuesSql The values to update. The keys are the column names and the values
104
- * are the values to set. The values are SQL expressions.
105
- * @example
106
- * ```ts
107
- * table.update({where:"x = 2", valuesSql:{"x": "x + 1"}})
108
- * ```
109
- */
110
- abstract update(opts: {
111
- valuesSql: Map<string, string> | Record<string, string>;
112
- } & Partial<UpdateOptions>): Promise<void>;
113
- /**
114
- * Update existing records in the Table
115
- *
116
- * An update operation can be used to adjust existing values. Use the
117
- * returned builder to specify which columns to update. The new value
118
- * can be a literal value (e.g. replacing nulls with some default value)
119
- * or an expression applied to the old value (e.g. incrementing a value)
120
- *
121
- * An optional condition can be specified (e.g. "only update if the old
122
- * value is 0")
123
- *
124
- * Note: if your condition is something like "some_id_column == 7" and
125
- * you are updating many rows (with different ids) then you will get
126
- * better performance with a single [`merge_insert`] call instead of
127
- * repeatedly calilng this method.
128
- * @param {Map<string, string> | Record<string, string>} updates - the
129
- * columns to update
130
- *
131
- * Keys in the map should specify the name of the column to update.
132
- * Values in the map provide the new value of the column. These can
133
- * be SQL literal strings (e.g. "7" or "'foo'") or they can be expressions
134
- * based on the row being updated (e.g. "my_col + 1")
135
- * @param {Partial<UpdateOptions>} options - additional options to control
136
- * the update behavior
137
- */
138
- abstract update(updates: Map<string, string> | Record<string, string>, options?: Partial<UpdateOptions>): Promise<void>;
139
- /** Count the total number of rows in the dataset. */
140
- abstract countRows(filter?: string): Promise<number>;
141
- /** Delete the rows that satisfy the predicate. */
142
- abstract delete(predicate: string): Promise<void>;
143
- /**
144
- * Create an index to speed up queries.
145
- *
146
- * Indices can be created on vector columns or scalar columns.
147
- * Indices on vector columns will speed up vector searches.
148
- * Indices on scalar columns will speed up filtering (in both
149
- * vector and non-vector searches)
150
- *
151
- * @note We currently don't support custom named indexes,
152
- * The index name will always be `${column}_idx`
153
- * @example
154
- * // If the column has a vector (fixed size list) data type then
155
- * // an IvfPq vector index will be created.
156
- * const table = await conn.openTable("my_table");
157
- * await table.createIndex("vector");
158
- * @example
159
- * // For advanced control over vector index creation you can specify
160
- * // the index type and options.
161
- * const table = await conn.openTable("my_table");
162
- * await table.createIndex("vector", {
163
- * config: lancedb.Index.ivfPq({
164
- * numPartitions: 128,
165
- * numSubVectors: 16,
166
- * }),
167
- * });
168
- * @example
169
- * // Or create a Scalar index
170
- * await table.createIndex("my_float_col");
171
- */
172
- abstract createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
173
- /**
174
- * Create a {@link Query} Builder.
175
- *
176
- * Queries allow you to search your existing data. By default the query will
177
- * return all the data in the table in no particular order. The builder
178
- * returned by this method can be used to control the query using filtering,
179
- * vector similarity, sorting, and more.
180
- *
181
- * Note: By default, all columns are returned. For best performance, you should
182
- * only fetch the columns you need.
183
- *
184
- * When appropriate, various indices and statistics based pruning will be used to
185
- * accelerate the query.
186
- * @example
187
- * // SQL-style filtering
188
- * //
189
- * // This query will return up to 1000 rows whose value in the `id` column
190
- * // is greater than 5. LanceDb supports a broad set of filtering functions.
191
- * for await (const batch of table
192
- * .query()
193
- * .where("id > 1")
194
- * .select(["id"])
195
- * .limit(20)) {
196
- * console.log(batch);
197
- * }
198
- * @example
199
- * // Vector Similarity Search
200
- * //
201
- * // This example will find the 10 rows whose value in the "vector" column are
202
- * // closest to the query vector [1.0, 2.0, 3.0]. If an index has been created
203
- * // on the "vector" column then this will perform an ANN search.
204
- * //
205
- * // The `refineFactor` and `nprobes` methods are used to control the recall /
206
- * // latency tradeoff of the search.
207
- * for await (const batch of table
208
- * .query()
209
- * .where("id > 1")
210
- * .select(["id"])
211
- * .limit(20)) {
212
- * console.log(batch);
213
- * }
214
- * @example
215
- * // Scan the full dataset
216
- * //
217
- * // This query will return everything in the table in no particular order.
218
- * for await (const batch of table.query()) {
219
- * console.log(batch);
220
- * }
221
- * @returns {Query} A builder that can be used to parameterize the query
222
- */
223
- abstract query(): Query;
224
- /**
225
- * Create a search query to find the nearest neighbors
226
- * of the given query
227
- * @param {string | IntoVector} query - the query, a vector or string
228
- * @param {string} queryType - the type of the query, "vector", "fts", or "auto"
229
- * @param {string | string[]} ftsColumns - the columns to search in for full text search
230
- * for now, only one column can be searched at a time.
231
- *
232
- * when "auto" is used, if the query is a string and an embedding function is defined, it will be treated as a vector query
233
- * if the query is a string and no embedding function is defined, it will be treated as a full text search query
234
- */
235
- abstract search(query: string | IntoVector, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
236
- /**
237
- * Search the table with a given query vector.
238
- *
239
- * This is a convenience method for preparing a vector query and
240
- * is the same thing as calling `nearestTo` on the builder returned
241
- * by `query`. @see {@link Query#nearestTo} for more details.
242
- */
243
- abstract vectorSearch(vector: IntoVector): VectorQuery;
244
- /**
245
- * Add new columns with defined values.
246
- * @param {AddColumnsSql[]} newColumnTransforms pairs of column names and
247
- * the SQL expression to use to calculate the value of the new column. These
248
- * expressions will be evaluated for each row in the table, and can
249
- * reference existing columns in the table.
250
- */
251
- abstract addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
252
- /**
253
- * Alter the name or nullability of columns.
254
- * @param {ColumnAlteration[]} columnAlterations One or more alterations to
255
- * apply to columns.
256
- */
257
- abstract alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
258
- /**
259
- * Drop one or more columns from the dataset
260
- *
261
- * This is a metadata-only operation and does not remove the data from the
262
- * underlying storage. In order to remove the data, you must subsequently
263
- * call ``compact_files`` to rewrite the data without the removed columns and
264
- * then call ``cleanup_files`` to remove the old files.
265
- * @param {string[]} columnNames The names of the columns to drop. These can
266
- * be nested column references (e.g. "a.b.c") or top-level column names
267
- * (e.g. "a").
268
- */
269
- abstract dropColumns(columnNames: string[]): Promise<void>;
270
- /** Retrieve the version of the table */
271
- abstract version(): Promise<number>;
272
- /**
273
- * Checks out a specific version of the table _This is an in-place operation._
274
- *
275
- * This allows viewing previous versions of the table. If you wish to
276
- * keep writing to the dataset starting from an old version, then use
277
- * the `restore` function.
278
- *
279
- * Calling this method will set the table into time-travel mode. If you
280
- * wish to return to standard mode, call `checkoutLatest`.
281
- * @param {number} version The version to checkout
282
- * @example
283
- * ```typescript
284
- * import * as lancedb from "@lancedb/lancedb"
285
- * const db = await lancedb.connect("./.lancedb");
286
- * const table = await db.createTable("my_table", [
287
- * { vector: [1.1, 0.9], type: "vector" },
288
- * ]);
289
- *
290
- * console.log(await table.version()); // 1
291
- * console.log(table.display());
292
- * await table.add([{ vector: [0.5, 0.2], type: "vector" }]);
293
- * await table.checkout(1);
294
- * console.log(await table.version()); // 2
295
- * ```
296
- */
297
- abstract checkout(version: number): Promise<void>;
298
- /**
299
- * Checkout the latest version of the table. _This is an in-place operation._
300
- *
301
- * The table will be set back into standard mode, and will track the latest
302
- * version of the table.
303
- */
304
- abstract checkoutLatest(): Promise<void>;
305
- /**
306
- * List all the versions of the table
307
- */
308
- abstract listVersions(): Promise<Version[]>;
309
- /**
310
- * Restore the table to the currently checked out version
311
- *
312
- * This operation will fail if checkout has not been called previously
313
- *
314
- * This operation will overwrite the latest version of the table with a
315
- * previous version. Any changes made since the checked out version will
316
- * no longer be visible.
317
- *
318
- * Once the operation concludes the table will no longer be in a checked
319
- * out state and the read_consistency_interval, if any, will apply.
320
- */
321
- abstract restore(): Promise<void>;
322
- /**
323
- * Optimize the on-disk data and indices for better performance.
324
- *
325
- * Modeled after ``VACUUM`` in PostgreSQL.
326
- *
327
- * Optimization covers three operations:
328
- *
329
- * - Compaction: Merges small files into larger ones
330
- * - Prune: Removes old versions of the dataset
331
- * - Index: Optimizes the indices, adding new data to existing indices
332
- *
333
- *
334
- * Experimental API
335
- * ----------------
336
- *
337
- * The optimization process is undergoing active development and may change.
338
- * Our goal with these changes is to improve the performance of optimization and
339
- * reduce the complexity.
340
- *
341
- * That being said, it is essential today to run optimize if you want the best
342
- * performance. It should be stable and safe to use in production, but it our
343
- * hope that the API may be simplified (or not even need to be called) in the
344
- * future.
345
- *
346
- * The frequency an application shoudl call optimize is based on the frequency of
347
- * data modifications. If data is frequently added, deleted, or updated then
348
- * optimize should be run frequently. A good rule of thumb is to run optimize if
349
- * you have added or modified 100,000 or more records or run more than 20 data
350
- * modification operations.
351
- */
352
- abstract optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
353
- /** List all indices that have been created with {@link Table.createIndex} */
354
- abstract listIndices(): Promise<IndexConfig[]>;
355
- /** Return the table as an arrow table */
356
- abstract toArrow(): Promise<ArrowTable>;
357
- abstract mergeInsert(on: string | string[]): MergeInsertBuilder;
358
- /** List all the stats of a specified index
359
- *
360
- * @param {string} name The name of the index.
361
- * @returns {IndexStatistics | undefined} The stats of the index. If the index does not exist, it will return undefined
362
- */
363
- abstract indexStats(name: string): Promise<IndexStatistics | undefined>;
364
- static parseTableData(data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>, streaming?: boolean): Promise<{
365
- buf: Buffer;
366
- mode: string;
367
- }>;
368
- }
369
- export declare class LocalTable extends Table {
370
- private readonly inner;
371
- constructor(inner: _NativeTable);
372
- get name(): string;
373
- isOpen(): boolean;
374
- close(): void;
375
- display(): string;
376
- private getEmbeddingFunctions;
377
- /** Get the schema of the table. */
378
- schema(): Promise<Schema>;
379
- add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
380
- update(optsOrUpdates: (Map<string, string> | Record<string, string>) | ({
381
- values: Map<string, IntoSql> | Record<string, IntoSql>;
382
- } & Partial<UpdateOptions>) | ({
383
- valuesSql: Map<string, string> | Record<string, string>;
384
- } & Partial<UpdateOptions>), options?: Partial<UpdateOptions>): Promise<void>;
385
- countRows(filter?: string): Promise<number>;
386
- delete(predicate: string): Promise<void>;
387
- createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
388
- query(): Query;
389
- search(query: string | IntoVector, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
390
- vectorSearch(vector: IntoVector): VectorQuery;
391
- addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
392
- alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
393
- dropColumns(columnNames: string[]): Promise<void>;
394
- version(): Promise<number>;
395
- checkout(version: number): Promise<void>;
396
- checkoutLatest(): Promise<void>;
397
- listVersions(): Promise<Version[]>;
398
- restore(): Promise<void>;
399
- optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
400
- listIndices(): Promise<IndexConfig[]>;
401
- toArrow(): Promise<ArrowTable>;
402
- indexStats(name: string): Promise<IndexStatistics | undefined>;
403
- mergeInsert(on: string | string[]): MergeInsertBuilder;
404
- /**
405
- * Check if the table uses the new manifest path scheme.
406
- *
407
- * This function will return true if the table uses the V2 manifest
408
- * path scheme.
409
- */
410
- usesV2ManifestPaths(): Promise<boolean>;
411
- /**
412
- * Migrate the table to use the new manifest path scheme.
413
- *
414
- * This function will rename all V1 manifests to V2 manifest paths.
415
- * These paths provide more efficient opening of datasets with many versions
416
- * on object stores.
417
- *
418
- * This function is idempotent, and can be run multiple times without
419
- * changing the state of the object store.
420
- *
421
- * However, it should not be run while other concurrent operations are happening.
422
- * And it should also run until completion before resuming other operations.
423
- */
424
- migrateManifestPathsV2(): Promise<void>;
425
- }
package/dist/table.js DELETED
@@ -1,276 +0,0 @@
1
- "use strict";
2
- // Copyright 2024 Lance 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.LocalTable = exports.Table = void 0;
17
- const arrow_1 = require("./arrow");
18
- const registry_1 = require("./embedding/registry");
19
- const merge_1 = require("./merge");
20
- const query_1 = require("./query");
21
- const sanitize_1 = require("./sanitize");
22
- const util_1 = require("./util");
23
- /**
24
- * A Table is a collection of Records in a LanceDB Database.
25
- *
26
- * A Table object is expected to be long lived and reused for multiple operations.
27
- * Table objects will cache a certain amount of index data in memory. This cache
28
- * will be freed when the Table is garbage collected. To eagerly free the cache you
29
- * can call the `close` method. Once the Table is closed, it cannot be used for any
30
- * further operations.
31
- *
32
- * Closing a table is optional. It not closed, it will be closed when it is garbage
33
- * collected.
34
- */
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 {
64
- inner;
65
- constructor(inner) {
66
- super();
67
- this.inner = inner;
68
- }
69
- get name() {
70
- return this.inner.name;
71
- }
72
- isOpen() {
73
- return this.inner.isOpen();
74
- }
75
- close() {
76
- this.inner.close();
77
- }
78
- display() {
79
- return this.inner.display();
80
- }
81
- async getEmbeddingFunctions() {
82
- const schema = await this.schema();
83
- const registry = (0, registry_1.getRegistry)();
84
- return registry.parseFunctions(schema.metadata);
85
- }
86
- /** Get the schema of the table. */
87
- async schema() {
88
- const schemaBuf = await this.inner.schema();
89
- const tbl = (0, arrow_1.tableFromIPC)(schemaBuf);
90
- return tbl.schema;
91
- }
92
- async add(data, options) {
93
- const mode = options?.mode ?? "append";
94
- const schema = await this.schema();
95
- const registry = (0, registry_1.getRegistry)();
96
- const functions = await registry.parseFunctions(schema.metadata);
97
- const buffer = await (0, arrow_1.fromDataToBuffer)(data, functions.values().next().value, schema);
98
- await this.inner.add(buffer, mode);
99
- }
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;
108
- let columns;
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;
142
- }
143
- await this.inner.update(predicate, columns);
144
- }
145
- async countRows(filter) {
146
- return await this.inner.countRows(filter);
147
- }
148
- async delete(predicate) {
149
- await this.inner.delete(predicate);
150
- }
151
- async createIndex(column, options) {
152
- // Bit of a hack to get around the fact that TS has no package-scope.
153
- // biome-ignore lint/suspicious/noExplicitAny: skip
154
- const nativeIndex = options?.config?.inner;
155
- await this.inner.createIndex(nativeIndex, column, options?.replace);
156
- }
157
- query() {
158
- return new query_1.Query(this.inner);
159
- }
160
- search(query, queryType = "auto", ftsColumns) {
161
- if (typeof query !== "string") {
162
- if (queryType === "fts") {
163
- throw new Error("Cannot perform full text search on a vector query");
164
- }
165
- return this.vectorSearch(query);
166
- }
167
- // If the query is a string, we need to determine if it is a vector query or a full text search query
168
- if (queryType === "fts") {
169
- return this.query().fullTextSearch(query, {
170
- columns: ftsColumns,
171
- });
172
- }
173
- // The query type is auto or vector
174
- // fall back to full text search if no embedding functions are defined and the query is a string
175
- if (queryType === "auto" && (0, registry_1.getRegistry)().length() === 0) {
176
- return this.query().fullTextSearch(query, {
177
- columns: ftsColumns,
178
- });
179
- }
180
- const queryPromise = this.getEmbeddingFunctions().then(async (functions) => {
181
- // TODO: Support multiple embedding functions
182
- const embeddingFunc = functions
183
- .values()
184
- .next().value;
185
- if (!embeddingFunc) {
186
- return Promise.reject(new Error("No embedding functions are defined in the table"));
187
- }
188
- return await embeddingFunc.function.computeQueryEmbeddings(query);
189
- });
190
- return this.query().nearestTo(queryPromise);
191
- }
192
- vectorSearch(vector) {
193
- return this.query().nearestTo(vector);
194
- }
195
- // TODO: Support BatchUDF
196
- async addColumns(newColumnTransforms) {
197
- await this.inner.addColumns(newColumnTransforms);
198
- }
199
- async alterColumns(columnAlterations) {
200
- await this.inner.alterColumns(columnAlterations);
201
- }
202
- async dropColumns(columnNames) {
203
- await this.inner.dropColumns(columnNames);
204
- }
205
- async version() {
206
- return await this.inner.version();
207
- }
208
- async checkout(version) {
209
- await this.inner.checkout(version);
210
- }
211
- async checkoutLatest() {
212
- await this.inner.checkoutLatest();
213
- }
214
- async listVersions() {
215
- return (await this.inner.listVersions()).map((version) => ({
216
- version: version.version,
217
- timestamp: new Date(version.timestamp / 1000),
218
- metadata: version.metadata,
219
- }));
220
- }
221
- async restore() {
222
- await this.inner.restore();
223
- }
224
- async optimize(options) {
225
- let cleanupOlderThanMs;
226
- if (options?.cleanupOlderThan !== undefined &&
227
- options?.cleanupOlderThan !== null) {
228
- cleanupOlderThanMs =
229
- new Date().getTime() - options.cleanupOlderThan.getTime();
230
- }
231
- return await this.inner.optimize(cleanupOlderThanMs, options?.deleteUnverified);
232
- }
233
- async listIndices() {
234
- return await this.inner.listIndices();
235
- }
236
- async toArrow() {
237
- return await this.query().toArrow();
238
- }
239
- async indexStats(name) {
240
- const stats = await this.inner.indexStats(name);
241
- if (stats === null) {
242
- return undefined;
243
- }
244
- return stats;
245
- }
246
- mergeInsert(on) {
247
- on = Array.isArray(on) ? on : [on];
248
- return new merge_1.MergeInsertBuilder(this.inner.mergeInsert(on));
249
- }
250
- /**
251
- * Check if the table uses the new manifest path scheme.
252
- *
253
- * This function will return true if the table uses the V2 manifest
254
- * path scheme.
255
- */
256
- async usesV2ManifestPaths() {
257
- return await this.inner.usesV2ManifestPaths();
258
- }
259
- /**
260
- * Migrate the table to use the new manifest path scheme.
261
- *
262
- * This function will rename all V1 manifests to V2 manifest paths.
263
- * These paths provide more efficient opening of datasets with many versions
264
- * on object stores.
265
- *
266
- * This function is idempotent, and can be run multiple times without
267
- * changing the state of the object store.
268
- *
269
- * However, it should not be run while other concurrent operations are happening.
270
- * And it should also run until completion before resuming other operations.
271
- */
272
- async migrateManifestPathsV2() {
273
- await this.inner.migrateManifestPathsV2();
274
- }
275
- }
276
- exports.LocalTable = LocalTable;