@lancedb/lancedb 0.4.20 → 0.5.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/README.md +5 -14
- package/biome.json +136 -0
- package/dist/arrow.d.ts +2 -1
- package/dist/arrow.js +33 -2
- package/dist/connection.d.ts +1 -1
- package/dist/connection.js +1 -1
- package/dist/native.d.ts +26 -0
- package/dist/query.d.ts +1 -1
- package/dist/query.js +4 -3
- package/dist/sanitize.js +3 -3
- package/dist/table.d.ts +50 -3
- package/dist/table.js +41 -2
- package/lancedb/arrow.ts +54 -16
- package/lancedb/connection.ts +1 -1
- package/lancedb/embedding/openai.ts +1 -1
- package/lancedb/query.ts +8 -6
- package/lancedb/sanitize.ts +40 -40
- package/lancedb/table.ts +63 -3
- package/nodejs-artifacts/arrow.d.ts +2 -1
- package/nodejs-artifacts/arrow.js +33 -2
- package/nodejs-artifacts/connection.d.ts +1 -1
- package/nodejs-artifacts/connection.js +1 -1
- package/nodejs-artifacts/native.d.ts +26 -0
- package/nodejs-artifacts/query.d.ts +1 -1
- package/nodejs-artifacts/query.js +4 -3
- package/nodejs-artifacts/sanitize.js +3 -3
- package/nodejs-artifacts/table.d.ts +50 -3
- package/nodejs-artifacts/table.js +41 -2
- package/package.json +17 -20
- package/.eslintignore +0 -3
- package/eslint.config.js +0 -28
package/lancedb/query.ts
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { Table as ArrowTable, RecordBatch, tableFromIPC } from "apache-arrow";
|
|
16
|
+
import { type IvfPqOptions } from "./indices";
|
|
16
17
|
import {
|
|
17
18
|
RecordBatchIterator as NativeBatchIterator,
|
|
18
19
|
Query as NativeQuery,
|
|
19
20
|
Table as NativeTable,
|
|
20
21
|
VectorQuery as NativeVectorQuery,
|
|
21
22
|
} from "./native";
|
|
22
|
-
import { type IvfPqOptions } from "./indices";
|
|
23
23
|
export class RecordBatchIterator implements AsyncIterator<RecordBatch> {
|
|
24
24
|
private promisedInner?: Promise<NativeBatchIterator>;
|
|
25
25
|
private inner?: NativeBatchIterator;
|
|
@@ -29,7 +29,7 @@ export class RecordBatchIterator implements AsyncIterator<RecordBatch> {
|
|
|
29
29
|
this.promisedInner = promise;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
33
33
|
async next(): Promise<IteratorResult<RecordBatch<any>>> {
|
|
34
34
|
if (this.inner === undefined) {
|
|
35
35
|
this.inner = await this.promisedInner;
|
|
@@ -56,7 +56,9 @@ export class QueryBase<
|
|
|
56
56
|
QueryType,
|
|
57
57
|
> implements AsyncIterable<RecordBatch>
|
|
58
58
|
{
|
|
59
|
-
protected constructor(protected inner: NativeQueryType) {
|
|
59
|
+
protected constructor(protected inner: NativeQueryType) {
|
|
60
|
+
// intentionally empty
|
|
61
|
+
}
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
64
|
* A filter statement to be applied to this query.
|
|
@@ -150,7 +152,7 @@ export class QueryBase<
|
|
|
150
152
|
return new RecordBatchIterator(this.nativeExecute());
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
//
|
|
155
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
154
156
|
[Symbol.asyncIterator](): AsyncIterator<RecordBatch<any>> {
|
|
155
157
|
const promise = this.nativeExecute();
|
|
156
158
|
return new RecordBatchIterator(promise);
|
|
@@ -368,7 +370,7 @@ export class Query extends QueryBase<NativeQuery, Query> {
|
|
|
368
370
|
* a default `limit` of 10 will be used. @see {@link Query#limit}
|
|
369
371
|
*/
|
|
370
372
|
nearestTo(vector: unknown): VectorQuery {
|
|
371
|
-
//
|
|
373
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
372
374
|
const vectorQuery = this.inner.nearestTo(Float32Array.from(vector as any));
|
|
373
375
|
return new VectorQuery(vectorQuery);
|
|
374
376
|
}
|
package/lancedb/sanitize.ts
CHANGED
|
@@ -21,60 +21,60 @@
|
|
|
21
21
|
// and so we must sanitize the input to ensure that it is compatible.
|
|
22
22
|
|
|
23
23
|
import {
|
|
24
|
-
|
|
25
|
-
Utf8,
|
|
26
|
-
FixedSizeBinary,
|
|
27
|
-
FixedSizeList,
|
|
28
|
-
Schema,
|
|
29
|
-
List,
|
|
30
|
-
Struct,
|
|
31
|
-
Float,
|
|
24
|
+
Binary,
|
|
32
25
|
Bool,
|
|
26
|
+
DataType,
|
|
27
|
+
DateDay,
|
|
28
|
+
DateMillisecond,
|
|
29
|
+
type DateUnit,
|
|
33
30
|
Date_,
|
|
34
31
|
Decimal,
|
|
35
|
-
|
|
32
|
+
DenseUnion,
|
|
36
33
|
Dictionary,
|
|
37
|
-
Binary,
|
|
38
|
-
Float32,
|
|
39
|
-
Interval,
|
|
40
|
-
Map_,
|
|
41
34
|
Duration,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
DurationMicrosecond,
|
|
36
|
+
DurationMillisecond,
|
|
37
|
+
DurationNanosecond,
|
|
38
|
+
DurationSecond,
|
|
39
|
+
Field,
|
|
40
|
+
FixedSizeBinary,
|
|
41
|
+
FixedSizeList,
|
|
42
|
+
Float,
|
|
43
|
+
Float16,
|
|
44
|
+
Float32,
|
|
45
|
+
Float64,
|
|
47
46
|
Int,
|
|
48
|
-
type Precision,
|
|
49
|
-
type DateUnit,
|
|
50
47
|
Int8,
|
|
51
48
|
Int16,
|
|
52
49
|
Int32,
|
|
53
50
|
Int64,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
DenseUnion,
|
|
51
|
+
Interval,
|
|
52
|
+
IntervalDayTime,
|
|
53
|
+
IntervalYearMonth,
|
|
54
|
+
List,
|
|
55
|
+
Map_,
|
|
56
|
+
Null,
|
|
57
|
+
type Precision,
|
|
58
|
+
Schema,
|
|
63
59
|
SparseUnion,
|
|
64
|
-
|
|
60
|
+
Struct,
|
|
61
|
+
Time,
|
|
65
62
|
TimeMicrosecond,
|
|
66
63
|
TimeMillisecond,
|
|
64
|
+
TimeNanosecond,
|
|
67
65
|
TimeSecond,
|
|
68
|
-
|
|
66
|
+
Timestamp,
|
|
69
67
|
TimestampMicrosecond,
|
|
70
68
|
TimestampMillisecond,
|
|
69
|
+
TimestampNanosecond,
|
|
71
70
|
TimestampSecond,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
Type,
|
|
72
|
+
Uint8,
|
|
73
|
+
Uint16,
|
|
74
|
+
Uint32,
|
|
75
|
+
Uint64,
|
|
76
|
+
Union,
|
|
77
|
+
Utf8,
|
|
78
78
|
} from "apache-arrow";
|
|
79
79
|
import type { IntBitWidth, TKeys, TimeBitWidth } from "apache-arrow/type";
|
|
80
80
|
|
|
@@ -228,7 +228,7 @@ function sanitizeUnion(typeLike: object) {
|
|
|
228
228
|
|
|
229
229
|
return new Union(
|
|
230
230
|
typeLike.mode,
|
|
231
|
-
//
|
|
231
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
232
232
|
typeLike.typeIds as any,
|
|
233
233
|
typeLike.children.map((child) => sanitizeField(child)),
|
|
234
234
|
);
|
|
@@ -294,7 +294,7 @@ function sanitizeMap(typeLike: object) {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
return new Map_(
|
|
297
|
-
//
|
|
297
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
298
298
|
typeLike.children.map((field) => sanitizeField(field)) as any,
|
|
299
299
|
typeLike.keysSorted,
|
|
300
300
|
);
|
|
@@ -328,7 +328,7 @@ function sanitizeDictionary(typeLike: object) {
|
|
|
328
328
|
);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
//
|
|
331
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
332
332
|
function sanitizeType(typeLike: unknown): DataType<any> {
|
|
333
333
|
if (typeof typeLike !== "object" || typeLike === null) {
|
|
334
334
|
throw Error("Expected a Type but object was null/undefined");
|
package/lancedb/table.ts
CHANGED
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
15
|
import { Schema, tableFromIPC } from "apache-arrow";
|
|
16
|
+
import { Data, fromDataToBuffer } from "./arrow";
|
|
17
|
+
import { IndexOptions } from "./indices";
|
|
16
18
|
import {
|
|
17
19
|
AddColumnsSql,
|
|
18
20
|
ColumnAlteration,
|
|
19
21
|
IndexConfig,
|
|
22
|
+
OptimizeStats,
|
|
20
23
|
Table as _NativeTable,
|
|
21
24
|
} from "./native";
|
|
22
25
|
import { Query, VectorQuery } from "./query";
|
|
23
|
-
import { IndexOptions } from "./indices";
|
|
24
|
-
import { Data, fromDataToBuffer } from "./arrow";
|
|
25
26
|
|
|
26
27
|
export { IndexConfig } from "./native";
|
|
27
28
|
/**
|
|
@@ -50,6 +51,23 @@ export interface UpdateOptions {
|
|
|
50
51
|
where: string;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
export interface OptimizeOptions {
|
|
55
|
+
/**
|
|
56
|
+
* If set then all versions older than the given date
|
|
57
|
+
* be removed. The current version will never be removed.
|
|
58
|
+
* The default is 7 days
|
|
59
|
+
* @example
|
|
60
|
+
* // Delete all versions older than 1 day
|
|
61
|
+
* const olderThan = new Date();
|
|
62
|
+
* olderThan.setDate(olderThan.getDate() - 1));
|
|
63
|
+
* tbl.cleanupOlderVersions(olderThan);
|
|
64
|
+
*
|
|
65
|
+
* // Delete all versions except the current version
|
|
66
|
+
* tbl.cleanupOlderVersions(new Date());
|
|
67
|
+
*/
|
|
68
|
+
cleanupOlderThan: Date;
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
/**
|
|
54
72
|
* A Table is a collection of Records in a LanceDB Database.
|
|
55
73
|
*
|
|
@@ -186,7 +204,7 @@ export class Table {
|
|
|
186
204
|
*/
|
|
187
205
|
async createIndex(column: string, options?: Partial<IndexOptions>) {
|
|
188
206
|
// Bit of a hack to get around the fact that TS has no package-scope.
|
|
189
|
-
//
|
|
207
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
190
208
|
const nativeIndex = (options?.config as any)?.inner;
|
|
191
209
|
await this.inner.createIndex(nativeIndex, column, options?.replace);
|
|
192
210
|
}
|
|
@@ -352,6 +370,48 @@ export class Table {
|
|
|
352
370
|
await this.inner.restore();
|
|
353
371
|
}
|
|
354
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Optimize the on-disk data and indices for better performance.
|
|
375
|
+
*
|
|
376
|
+
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
377
|
+
*
|
|
378
|
+
* Optimization covers three operations:
|
|
379
|
+
*
|
|
380
|
+
* - Compaction: Merges small files into larger ones
|
|
381
|
+
* - Prune: Removes old versions of the dataset
|
|
382
|
+
* - Index: Optimizes the indices, adding new data to existing indices
|
|
383
|
+
*
|
|
384
|
+
*
|
|
385
|
+
* Experimental API
|
|
386
|
+
* ----------------
|
|
387
|
+
*
|
|
388
|
+
* The optimization process is undergoing active development and may change.
|
|
389
|
+
* Our goal with these changes is to improve the performance of optimization and
|
|
390
|
+
* reduce the complexity.
|
|
391
|
+
*
|
|
392
|
+
* That being said, it is essential today to run optimize if you want the best
|
|
393
|
+
* performance. It should be stable and safe to use in production, but it our
|
|
394
|
+
* hope that the API may be simplified (or not even need to be called) in the
|
|
395
|
+
* future.
|
|
396
|
+
*
|
|
397
|
+
* The frequency an application shoudl call optimize is based on the frequency of
|
|
398
|
+
* data modifications. If data is frequently added, deleted, or updated then
|
|
399
|
+
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
400
|
+
* you have added or modified 100,000 or more records or run more than 20 data
|
|
401
|
+
* modification operations.
|
|
402
|
+
*/
|
|
403
|
+
async optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats> {
|
|
404
|
+
let cleanupOlderThanMs;
|
|
405
|
+
if (
|
|
406
|
+
options?.cleanupOlderThan !== undefined &&
|
|
407
|
+
options?.cleanupOlderThan !== null
|
|
408
|
+
) {
|
|
409
|
+
cleanupOlderThanMs =
|
|
410
|
+
new Date().getTime() - options.cleanupOlderThan.getTime();
|
|
411
|
+
}
|
|
412
|
+
return await this.inner.optimize(cleanupOlderThanMs);
|
|
413
|
+
}
|
|
414
|
+
|
|
355
415
|
/** List all indices that have been created with {@link Table.createIndex} */
|
|
356
416
|
async listIndices(): Promise<IndexConfig[]> {
|
|
357
417
|
return await this.inner.listIndices();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Table as ArrowTable, type Float, Schema } from "apache-arrow";
|
|
3
3
|
import { type EmbeddingFunction } from "./embedding/embedding_function";
|
|
4
4
|
/** Data type accepted by NodeJS SDK */
|
|
5
5
|
export type Data = Record<string, unknown>[] | ArrowTable;
|
|
@@ -12,6 +12,7 @@ export declare class VectorColumnOptions {
|
|
|
12
12
|
export declare class MakeArrowTableOptions {
|
|
13
13
|
schema?: Schema;
|
|
14
14
|
vectorColumns: Record<string, VectorColumnOptions>;
|
|
15
|
+
embeddings?: EmbeddingFunction<unknown>;
|
|
15
16
|
/**
|
|
16
17
|
* If true then string columns will be encoded with dictionary encoding
|
|
17
18
|
*
|
|
@@ -60,6 +60,7 @@ class MakeArrowTableOptions {
|
|
|
60
60
|
vectorColumns = {
|
|
61
61
|
vector: new VectorColumnOptions(),
|
|
62
62
|
};
|
|
63
|
+
embeddings;
|
|
63
64
|
/**
|
|
64
65
|
* If true then string columns will be encoded with dictionary encoding
|
|
65
66
|
*
|
|
@@ -175,6 +176,7 @@ function makeArrowTable(data, options) {
|
|
|
175
176
|
const opt = new MakeArrowTableOptions(options !== undefined ? options : {});
|
|
176
177
|
if (opt.schema !== undefined && opt.schema !== null) {
|
|
177
178
|
opt.schema = (0, sanitize_1.sanitizeSchema)(opt.schema);
|
|
179
|
+
opt.schema = validateSchemaEmbeddings(opt.schema, data, opt.embeddings);
|
|
178
180
|
}
|
|
179
181
|
const columns = {};
|
|
180
182
|
// TODO: sample dataset to find missing columns
|
|
@@ -244,8 +246,9 @@ function makeArrowTable(data, options) {
|
|
|
244
246
|
// then patch the schema of the batches so we can use
|
|
245
247
|
// `new ArrowTable(schema, batches)` which does not do any schema inference
|
|
246
248
|
const firstTable = new apache_arrow_1.Table(columns);
|
|
249
|
+
const batchesFixed = firstTable.batches.map(
|
|
247
250
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
248
|
-
|
|
251
|
+
(batch) => new apache_arrow_1.RecordBatch(opt.schema, batch.data));
|
|
249
252
|
return new apache_arrow_1.Table(opt.schema, batchesFixed);
|
|
250
253
|
}
|
|
251
254
|
else {
|
|
@@ -269,7 +272,7 @@ function makeListVector(lists) {
|
|
|
269
272
|
throw Error("Cannot infer list vector from empty array or empty list");
|
|
270
273
|
}
|
|
271
274
|
const sampleList = lists[0];
|
|
272
|
-
//
|
|
275
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
273
276
|
let inferredType;
|
|
274
277
|
try {
|
|
275
278
|
const sampleVector = makeVector(sampleList);
|
|
@@ -537,3 +540,31 @@ function createEmptyTable(schema) {
|
|
|
537
540
|
return new apache_arrow_1.Table((0, sanitize_1.sanitizeSchema)(schema));
|
|
538
541
|
}
|
|
539
542
|
exports.createEmptyTable = createEmptyTable;
|
|
543
|
+
function validateSchemaEmbeddings(schema, data, embeddings) {
|
|
544
|
+
const fields = [];
|
|
545
|
+
const missingEmbeddingFields = [];
|
|
546
|
+
// First we check if the field is a `FixedSizeList`
|
|
547
|
+
// Then we check if the data contains the field
|
|
548
|
+
// if it does not, we add it to the list of missing embedding fields
|
|
549
|
+
// Finally, we check if those missing embedding fields are `this._embeddings`
|
|
550
|
+
// if they are not, we throw an error
|
|
551
|
+
for (const field of schema.fields) {
|
|
552
|
+
if (field.type instanceof apache_arrow_1.FixedSizeList) {
|
|
553
|
+
if (data.length !== 0 && data?.[0]?.[field.name] === undefined) {
|
|
554
|
+
missingEmbeddingFields.push(field);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
fields.push(field);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
fields.push(field);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (missingEmbeddingFields.length > 0 && embeddings === undefined) {
|
|
565
|
+
throw new Error(`Table has embeddings: "${missingEmbeddingFields
|
|
566
|
+
.map((f) => f.name)
|
|
567
|
+
.join(",")}", but no embedding function was provided`);
|
|
568
|
+
}
|
|
569
|
+
return new apache_arrow_1.Schema(fields, schema.metadata);
|
|
570
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Table as ArrowTable, Schema } from "apache-arrow";
|
|
1
2
|
import { ConnectionOptions, Connection as LanceDbConnection } from "./native";
|
|
2
3
|
import { Table } from "./table";
|
|
3
|
-
import { Table as ArrowTable, Schema } from "apache-arrow";
|
|
4
4
|
/**
|
|
5
5
|
* Connect to a LanceDB instance at the given URI.
|
|
6
6
|
*
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Connection = exports.connect = void 0;
|
|
17
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
17
18
|
const arrow_1 = require("./arrow");
|
|
18
19
|
const native_1 = require("./native");
|
|
19
20
|
const table_1 = require("./table");
|
|
20
|
-
const apache_arrow_1 = require("apache-arrow");
|
|
21
21
|
/**
|
|
22
22
|
* Connect to a LanceDB instance at the given URI.
|
|
23
23
|
*
|
|
@@ -15,6 +15,31 @@ export interface IndexConfig {
|
|
|
15
15
|
*/
|
|
16
16
|
columns: Array<string>
|
|
17
17
|
}
|
|
18
|
+
/** Statistics about a compaction operation. */
|
|
19
|
+
export interface CompactionStats {
|
|
20
|
+
/** The number of fragments removed */
|
|
21
|
+
fragmentsRemoved: number
|
|
22
|
+
/** The number of new, compacted fragments added */
|
|
23
|
+
fragmentsAdded: number
|
|
24
|
+
/** The number of data files removed */
|
|
25
|
+
filesRemoved: number
|
|
26
|
+
/** The number of new, compacted data files added */
|
|
27
|
+
filesAdded: number
|
|
28
|
+
}
|
|
29
|
+
/** Statistics about a cleanup operation */
|
|
30
|
+
export interface RemovalStats {
|
|
31
|
+
/** The number of bytes removed */
|
|
32
|
+
bytesRemoved: number
|
|
33
|
+
/** The number of old versions removed */
|
|
34
|
+
oldVersionsRemoved: number
|
|
35
|
+
}
|
|
36
|
+
/** Statistics about an optimize operation */
|
|
37
|
+
export interface OptimizeStats {
|
|
38
|
+
/** Statistics about the compaction operation */
|
|
39
|
+
compaction: CompactionStats
|
|
40
|
+
/** Statistics about the removal operation */
|
|
41
|
+
prune: RemovalStats
|
|
42
|
+
}
|
|
18
43
|
/**
|
|
19
44
|
* A definition of a column alteration. The alteration changes the column at
|
|
20
45
|
* `path` to have the new name `name`, to be nullable if `nullable` is true,
|
|
@@ -151,5 +176,6 @@ export class Table {
|
|
|
151
176
|
checkout(version: number): Promise<void>
|
|
152
177
|
checkoutLatest(): Promise<void>
|
|
153
178
|
restore(): Promise<void>
|
|
179
|
+
optimize(olderThanMs?: number | undefined | null): Promise<OptimizeStats>
|
|
154
180
|
listIndices(): Promise<Array<IndexConfig>>
|
|
155
181
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Table as ArrowTable, RecordBatch } from "apache-arrow";
|
|
2
2
|
import { RecordBatchIterator as NativeBatchIterator, Query as NativeQuery, Table as NativeTable, VectorQuery as NativeVectorQuery } from "./native";
|
|
3
3
|
export declare class RecordBatchIterator implements AsyncIterator<RecordBatch> {
|
|
4
4
|
private promisedInner?;
|
|
@@ -22,7 +22,7 @@ class RecordBatchIterator {
|
|
|
22
22
|
// TODO: check promise reliably so we dont need to pass two arguments.
|
|
23
23
|
this.promisedInner = promise;
|
|
24
24
|
}
|
|
25
|
-
//
|
|
25
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
26
26
|
async next() {
|
|
27
27
|
if (this.inner === undefined) {
|
|
28
28
|
this.inner = await this.promisedInner;
|
|
@@ -48,6 +48,7 @@ class QueryBase {
|
|
|
48
48
|
inner;
|
|
49
49
|
constructor(inner) {
|
|
50
50
|
this.inner = inner;
|
|
51
|
+
// intentionally empty
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* A filter statement to be applied to this query.
|
|
@@ -136,7 +137,7 @@ class QueryBase {
|
|
|
136
137
|
execute() {
|
|
137
138
|
return new RecordBatchIterator(this.nativeExecute());
|
|
138
139
|
}
|
|
139
|
-
//
|
|
140
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
140
141
|
[Symbol.asyncIterator]() {
|
|
141
142
|
const promise = this.nativeExecute();
|
|
142
143
|
return new RecordBatchIterator(promise);
|
|
@@ -338,7 +339,7 @@ class Query extends QueryBase {
|
|
|
338
339
|
* a default `limit` of 10 will be used. @see {@link Query#limit}
|
|
339
340
|
*/
|
|
340
341
|
nearestTo(vector) {
|
|
341
|
-
//
|
|
342
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
342
343
|
const vectorQuery = this.inner.nearestTo(Float32Array.from(vector));
|
|
343
344
|
return new VectorQuery(vectorQuery);
|
|
344
345
|
}
|
|
@@ -127,7 +127,7 @@ function sanitizeUnion(typeLike) {
|
|
|
127
127
|
throw Error("Expected a Union type to have an array-like `children` property");
|
|
128
128
|
}
|
|
129
129
|
return new apache_arrow_1.Union(typeLike.mode,
|
|
130
|
-
//
|
|
130
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
131
131
|
typeLike.typeIds, typeLike.children.map((child) => sanitizeField(child)));
|
|
132
132
|
}
|
|
133
133
|
function sanitizeTypedUnion(typeLike,
|
|
@@ -167,7 +167,7 @@ function sanitizeMap(typeLike) {
|
|
|
167
167
|
throw Error("Expected a Map type to have a `keysSorted` property");
|
|
168
168
|
}
|
|
169
169
|
return new apache_arrow_1.Map_(
|
|
170
|
-
//
|
|
170
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
171
171
|
typeLike.children.map((field) => sanitizeField(field)), typeLike.keysSorted);
|
|
172
172
|
}
|
|
173
173
|
function sanitizeDuration(typeLike) {
|
|
@@ -191,7 +191,7 @@ function sanitizeDictionary(typeLike) {
|
|
|
191
191
|
}
|
|
192
192
|
return new apache_arrow_1.Dictionary(sanitizeType(typeLike.dictionary), sanitizeType(typeLike.indices), typeLike.id, typeLike.isOrdered);
|
|
193
193
|
}
|
|
194
|
-
//
|
|
194
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
195
195
|
function sanitizeType(typeLike) {
|
|
196
196
|
if (typeof typeLike !== "object" || typeLike === null) {
|
|
197
197
|
throw Error("Expected a Type but object was null/undefined");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema } from "apache-arrow";
|
|
2
|
-
import { AddColumnsSql, ColumnAlteration, IndexConfig, Table as _NativeTable } from "./native";
|
|
3
|
-
import { Query, VectorQuery } from "./query";
|
|
4
|
-
import { IndexOptions } from "./indices";
|
|
5
2
|
import { Data } from "./arrow";
|
|
3
|
+
import { IndexOptions } from "./indices";
|
|
4
|
+
import { AddColumnsSql, ColumnAlteration, IndexConfig, OptimizeStats, Table as _NativeTable } from "./native";
|
|
5
|
+
import { Query, VectorQuery } from "./query";
|
|
6
6
|
export { IndexConfig } from "./native";
|
|
7
7
|
/**
|
|
8
8
|
* Options for adding data to a table.
|
|
@@ -28,6 +28,22 @@ export interface UpdateOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
where: string;
|
|
30
30
|
}
|
|
31
|
+
export interface OptimizeOptions {
|
|
32
|
+
/**
|
|
33
|
+
* If set then all versions older than the given date
|
|
34
|
+
* be removed. The current version will never be removed.
|
|
35
|
+
* The default is 7 days
|
|
36
|
+
* @example
|
|
37
|
+
* // Delete all versions older than 1 day
|
|
38
|
+
* const olderThan = new Date();
|
|
39
|
+
* olderThan.setDate(olderThan.getDate() - 1));
|
|
40
|
+
* tbl.cleanupOlderVersions(olderThan);
|
|
41
|
+
*
|
|
42
|
+
* // Delete all versions except the current version
|
|
43
|
+
* tbl.cleanupOlderVersions(new Date());
|
|
44
|
+
*/
|
|
45
|
+
cleanupOlderThan: Date;
|
|
46
|
+
}
|
|
31
47
|
/**
|
|
32
48
|
* A Table is a collection of Records in a LanceDB Database.
|
|
33
49
|
*
|
|
@@ -253,6 +269,37 @@ export declare class Table {
|
|
|
253
269
|
* out state and the read_consistency_interval, if any, will apply.
|
|
254
270
|
*/
|
|
255
271
|
restore(): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* Optimize the on-disk data and indices for better performance.
|
|
274
|
+
*
|
|
275
|
+
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
276
|
+
*
|
|
277
|
+
* Optimization covers three operations:
|
|
278
|
+
*
|
|
279
|
+
* - Compaction: Merges small files into larger ones
|
|
280
|
+
* - Prune: Removes old versions of the dataset
|
|
281
|
+
* - Index: Optimizes the indices, adding new data to existing indices
|
|
282
|
+
*
|
|
283
|
+
*
|
|
284
|
+
* Experimental API
|
|
285
|
+
* ----------------
|
|
286
|
+
*
|
|
287
|
+
* The optimization process is undergoing active development and may change.
|
|
288
|
+
* Our goal with these changes is to improve the performance of optimization and
|
|
289
|
+
* reduce the complexity.
|
|
290
|
+
*
|
|
291
|
+
* That being said, it is essential today to run optimize if you want the best
|
|
292
|
+
* performance. It should be stable and safe to use in production, but it our
|
|
293
|
+
* hope that the API may be simplified (or not even need to be called) in the
|
|
294
|
+
* future.
|
|
295
|
+
*
|
|
296
|
+
* The frequency an application shoudl call optimize is based on the frequency of
|
|
297
|
+
* data modifications. If data is frequently added, deleted, or updated then
|
|
298
|
+
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
299
|
+
* you have added or modified 100,000 or more records or run more than 20 data
|
|
300
|
+
* modification operations.
|
|
301
|
+
*/
|
|
302
|
+
optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
|
|
256
303
|
/** List all indices that have been created with {@link Table.createIndex} */
|
|
257
304
|
listIndices(): Promise<IndexConfig[]>;
|
|
258
305
|
}
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Table = void 0;
|
|
17
17
|
const apache_arrow_1 = require("apache-arrow");
|
|
18
|
-
const query_1 = require("./query");
|
|
19
18
|
const arrow_1 = require("./arrow");
|
|
19
|
+
const query_1 = require("./query");
|
|
20
20
|
/**
|
|
21
21
|
* A Table is a collection of Records in a LanceDB Database.
|
|
22
22
|
*
|
|
@@ -140,7 +140,7 @@ class Table {
|
|
|
140
140
|
*/
|
|
141
141
|
async createIndex(column, options) {
|
|
142
142
|
// Bit of a hack to get around the fact that TS has no package-scope.
|
|
143
|
-
//
|
|
143
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
144
144
|
const nativeIndex = options?.config?.inner;
|
|
145
145
|
await this.inner.createIndex(nativeIndex, column, options?.replace);
|
|
146
146
|
}
|
|
@@ -296,6 +296,45 @@ class Table {
|
|
|
296
296
|
async restore() {
|
|
297
297
|
await this.inner.restore();
|
|
298
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Optimize the on-disk data and indices for better performance.
|
|
301
|
+
*
|
|
302
|
+
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
303
|
+
*
|
|
304
|
+
* Optimization covers three operations:
|
|
305
|
+
*
|
|
306
|
+
* - Compaction: Merges small files into larger ones
|
|
307
|
+
* - Prune: Removes old versions of the dataset
|
|
308
|
+
* - Index: Optimizes the indices, adding new data to existing indices
|
|
309
|
+
*
|
|
310
|
+
*
|
|
311
|
+
* Experimental API
|
|
312
|
+
* ----------------
|
|
313
|
+
*
|
|
314
|
+
* The optimization process is undergoing active development and may change.
|
|
315
|
+
* Our goal with these changes is to improve the performance of optimization and
|
|
316
|
+
* reduce the complexity.
|
|
317
|
+
*
|
|
318
|
+
* That being said, it is essential today to run optimize if you want the best
|
|
319
|
+
* performance. It should be stable and safe to use in production, but it our
|
|
320
|
+
* hope that the API may be simplified (or not even need to be called) in the
|
|
321
|
+
* future.
|
|
322
|
+
*
|
|
323
|
+
* The frequency an application shoudl call optimize is based on the frequency of
|
|
324
|
+
* data modifications. If data is frequently added, deleted, or updated then
|
|
325
|
+
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
326
|
+
* you have added or modified 100,000 or more records or run more than 20 data
|
|
327
|
+
* modification operations.
|
|
328
|
+
*/
|
|
329
|
+
async optimize(options) {
|
|
330
|
+
let cleanupOlderThanMs;
|
|
331
|
+
if (options?.cleanupOlderThan !== undefined &&
|
|
332
|
+
options?.cleanupOlderThan !== null) {
|
|
333
|
+
cleanupOlderThanMs =
|
|
334
|
+
new Date().getTime() - options.cleanupOlderThan.getTime();
|
|
335
|
+
}
|
|
336
|
+
return await this.inner.optimize(cleanupOlderThanMs);
|
|
337
|
+
}
|
|
299
338
|
/** List all indices that have been created with {@link Table.createIndex} */
|
|
300
339
|
async listIndices() {
|
|
301
340
|
return await this.inner.listIndices();
|