@lancedb/lancedb 0.4.20 → 0.5.1
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 +142 -0
- package/dist/arrow.d.ts +35 -9
- package/dist/arrow.js +247 -19
- package/dist/connection.d.ts +4 -1
- package/dist/connection.js +11 -5
- package/dist/embedding/embedding_function.d.ts +54 -28
- package/dist/embedding/embedding_function.js +71 -10
- package/dist/embedding/index.d.ts +28 -2
- package/dist/embedding/index.js +111 -4
- package/dist/embedding/openai.d.ts +16 -7
- package/dist/embedding/openai.js +62 -12
- package/dist/embedding/registry.d.ts +54 -0
- package/dist/embedding/registry.js +123 -0
- package/dist/native.d.ts +26 -0
- package/dist/query.d.ts +1 -1
- package/dist/query.js +7 -6
- package/dist/sanitize.d.ts +22 -1
- package/dist/sanitize.js +126 -113
- package/dist/table.d.ts +50 -4
- package/dist/table.js +47 -5
- package/lancedb/arrow.ts +283 -49
- package/lancedb/connection.ts +27 -6
- package/lancedb/embedding/embedding_function.ts +126 -42
- package/lancedb/embedding/index.ts +113 -2
- package/lancedb/embedding/openai.ts +62 -16
- package/lancedb/embedding/registry.ts +172 -0
- package/lancedb/query.ts +9 -6
- package/lancedb/sanitize.ts +62 -62
- package/lancedb/table.ts +72 -5
- package/nodejs-artifacts/arrow.d.ts +35 -9
- package/nodejs-artifacts/arrow.js +247 -19
- package/nodejs-artifacts/connection.d.ts +4 -1
- package/nodejs-artifacts/connection.js +11 -5
- package/nodejs-artifacts/embedding/embedding_function.d.ts +54 -28
- package/nodejs-artifacts/embedding/embedding_function.js +71 -10
- package/nodejs-artifacts/embedding/index.d.ts +28 -2
- package/nodejs-artifacts/embedding/index.js +111 -4
- package/nodejs-artifacts/embedding/openai.d.ts +16 -7
- package/nodejs-artifacts/embedding/openai.js +62 -12
- package/nodejs-artifacts/embedding/registry.d.ts +54 -0
- package/nodejs-artifacts/embedding/registry.js +123 -0
- package/nodejs-artifacts/native.d.ts +26 -0
- package/nodejs-artifacts/query.d.ts +1 -1
- package/nodejs-artifacts/query.js +7 -6
- package/nodejs-artifacts/sanitize.d.ts +22 -1
- package/nodejs-artifacts/sanitize.js +126 -113
- package/nodejs-artifacts/table.d.ts +50 -4
- package/nodejs-artifacts/table.js +47 -5
- package/package.json +23 -21
- package/tsconfig.json +3 -1
- package/.eslintignore +0 -3
- package/eslint.config.js +0 -28
package/lancedb/sanitize.ts
CHANGED
|
@@ -20,65 +20,65 @@
|
|
|
20
20
|
// comes from the exact same library instance. This is not always the case
|
|
21
21
|
// and so we must sanitize the input to ensure that it is compatible.
|
|
22
22
|
|
|
23
|
+
import type { IntBitWidth, TKeys, TimeBitWidth } from "apache-arrow/type";
|
|
23
24
|
import {
|
|
24
|
-
|
|
25
|
-
Utf8,
|
|
26
|
-
FixedSizeBinary,
|
|
27
|
-
FixedSizeList,
|
|
28
|
-
Schema,
|
|
29
|
-
List,
|
|
30
|
-
Struct,
|
|
31
|
-
Float,
|
|
25
|
+
Binary,
|
|
32
26
|
Bool,
|
|
27
|
+
DataType,
|
|
28
|
+
DateDay,
|
|
29
|
+
DateMillisecond,
|
|
30
|
+
type DateUnit,
|
|
33
31
|
Date_,
|
|
34
32
|
Decimal,
|
|
35
|
-
|
|
33
|
+
DenseUnion,
|
|
36
34
|
Dictionary,
|
|
37
|
-
Binary,
|
|
38
|
-
Float32,
|
|
39
|
-
Interval,
|
|
40
|
-
Map_,
|
|
41
35
|
Duration,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
DurationMicrosecond,
|
|
37
|
+
DurationMillisecond,
|
|
38
|
+
DurationNanosecond,
|
|
39
|
+
DurationSecond,
|
|
40
|
+
Field,
|
|
41
|
+
FixedSizeBinary,
|
|
42
|
+
FixedSizeList,
|
|
43
|
+
Float,
|
|
44
|
+
Float16,
|
|
45
|
+
Float32,
|
|
46
|
+
Float64,
|
|
47
47
|
Int,
|
|
48
|
-
type Precision,
|
|
49
|
-
type DateUnit,
|
|
50
48
|
Int8,
|
|
51
49
|
Int16,
|
|
52
50
|
Int32,
|
|
53
51
|
Int64,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
DenseUnion,
|
|
52
|
+
Interval,
|
|
53
|
+
IntervalDayTime,
|
|
54
|
+
IntervalYearMonth,
|
|
55
|
+
List,
|
|
56
|
+
Map_,
|
|
57
|
+
Null,
|
|
58
|
+
type Precision,
|
|
59
|
+
Schema,
|
|
63
60
|
SparseUnion,
|
|
64
|
-
|
|
61
|
+
Struct,
|
|
62
|
+
Time,
|
|
65
63
|
TimeMicrosecond,
|
|
66
64
|
TimeMillisecond,
|
|
65
|
+
TimeNanosecond,
|
|
67
66
|
TimeSecond,
|
|
68
|
-
|
|
67
|
+
Timestamp,
|
|
69
68
|
TimestampMicrosecond,
|
|
70
69
|
TimestampMillisecond,
|
|
70
|
+
TimestampNanosecond,
|
|
71
71
|
TimestampSecond,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
Type,
|
|
73
|
+
Uint8,
|
|
74
|
+
Uint16,
|
|
75
|
+
Uint32,
|
|
76
|
+
Uint64,
|
|
77
|
+
Union,
|
|
78
|
+
Utf8,
|
|
79
|
+
} from "./arrow";
|
|
80
80
|
|
|
81
|
-
function sanitizeMetadata(
|
|
81
|
+
export function sanitizeMetadata(
|
|
82
82
|
metadataLike?: unknown,
|
|
83
83
|
): Map<string, string> | undefined {
|
|
84
84
|
if (metadataLike === undefined || metadataLike === null) {
|
|
@@ -97,7 +97,7 @@ function sanitizeMetadata(
|
|
|
97
97
|
return metadataLike as Map<string, string>;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function sanitizeInt(typeLike: object) {
|
|
100
|
+
export function sanitizeInt(typeLike: object) {
|
|
101
101
|
if (
|
|
102
102
|
!("bitWidth" in typeLike) ||
|
|
103
103
|
typeof typeLike.bitWidth !== "number" ||
|
|
@@ -111,14 +111,14 @@ function sanitizeInt(typeLike: object) {
|
|
|
111
111
|
return new Int(typeLike.isSigned, typeLike.bitWidth as IntBitWidth);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
function sanitizeFloat(typeLike: object) {
|
|
114
|
+
export function sanitizeFloat(typeLike: object) {
|
|
115
115
|
if (!("precision" in typeLike) || typeof typeLike.precision !== "number") {
|
|
116
116
|
throw Error("Expected a Float Type to have a `precision` property");
|
|
117
117
|
}
|
|
118
118
|
return new Float(typeLike.precision as Precision);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
function sanitizeDecimal(typeLike: object) {
|
|
121
|
+
export function sanitizeDecimal(typeLike: object) {
|
|
122
122
|
if (
|
|
123
123
|
!("scale" in typeLike) ||
|
|
124
124
|
typeof typeLike.scale !== "number" ||
|
|
@@ -134,14 +134,14 @@ function sanitizeDecimal(typeLike: object) {
|
|
|
134
134
|
return new Decimal(typeLike.scale, typeLike.precision, typeLike.bitWidth);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
function sanitizeDate(typeLike: object) {
|
|
137
|
+
export function sanitizeDate(typeLike: object) {
|
|
138
138
|
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
139
139
|
throw Error("Expected a Date type to have a `unit` property");
|
|
140
140
|
}
|
|
141
141
|
return new Date_(typeLike.unit as DateUnit);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
function sanitizeTime(typeLike: object) {
|
|
144
|
+
export function sanitizeTime(typeLike: object) {
|
|
145
145
|
if (
|
|
146
146
|
!("unit" in typeLike) ||
|
|
147
147
|
typeof typeLike.unit !== "number" ||
|
|
@@ -155,7 +155,7 @@ function sanitizeTime(typeLike: object) {
|
|
|
155
155
|
return new Time(typeLike.unit, typeLike.bitWidth as TimeBitWidth);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
function sanitizeTimestamp(typeLike: object) {
|
|
158
|
+
export function sanitizeTimestamp(typeLike: object) {
|
|
159
159
|
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
160
160
|
throw Error("Expected a Timestamp type to have a `unit` property");
|
|
161
161
|
}
|
|
@@ -166,7 +166,7 @@ function sanitizeTimestamp(typeLike: object) {
|
|
|
166
166
|
return new Timestamp(typeLike.unit, timezone);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
function sanitizeTypedTimestamp(
|
|
169
|
+
export function sanitizeTypedTimestamp(
|
|
170
170
|
typeLike: object,
|
|
171
171
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
172
172
|
Datatype:
|
|
@@ -182,14 +182,14 @@ function sanitizeTypedTimestamp(
|
|
|
182
182
|
return new Datatype(timezone);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
function sanitizeInterval(typeLike: object) {
|
|
185
|
+
export function sanitizeInterval(typeLike: object) {
|
|
186
186
|
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
187
187
|
throw Error("Expected an Interval type to have a `unit` property");
|
|
188
188
|
}
|
|
189
189
|
return new Interval(typeLike.unit);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
function sanitizeList(typeLike: object) {
|
|
192
|
+
export function sanitizeList(typeLike: object) {
|
|
193
193
|
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
194
194
|
throw Error(
|
|
195
195
|
"Expected a List type to have an array-like `children` property",
|
|
@@ -201,7 +201,7 @@ function sanitizeList(typeLike: object) {
|
|
|
201
201
|
return new List(sanitizeField(typeLike.children[0]));
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
function sanitizeStruct(typeLike: object) {
|
|
204
|
+
export function sanitizeStruct(typeLike: object) {
|
|
205
205
|
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
206
206
|
throw Error(
|
|
207
207
|
"Expected a Struct type to have an array-like `children` property",
|
|
@@ -210,7 +210,7 @@ function sanitizeStruct(typeLike: object) {
|
|
|
210
210
|
return new Struct(typeLike.children.map((child) => sanitizeField(child)));
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
function sanitizeUnion(typeLike: object) {
|
|
213
|
+
export function sanitizeUnion(typeLike: object) {
|
|
214
214
|
if (
|
|
215
215
|
!("typeIds" in typeLike) ||
|
|
216
216
|
!("mode" in typeLike) ||
|
|
@@ -228,13 +228,13 @@ 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
|
);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
function sanitizeTypedUnion(
|
|
237
|
+
export function sanitizeTypedUnion(
|
|
238
238
|
typeLike: object,
|
|
239
239
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
240
240
|
UnionType: typeof DenseUnion | typeof SparseUnion,
|
|
@@ -256,7 +256,7 @@ function sanitizeTypedUnion(
|
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
function sanitizeFixedSizeBinary(typeLike: object) {
|
|
259
|
+
export function sanitizeFixedSizeBinary(typeLike: object) {
|
|
260
260
|
if (!("byteWidth" in typeLike) || typeof typeLike.byteWidth !== "number") {
|
|
261
261
|
throw Error(
|
|
262
262
|
"Expected a FixedSizeBinary type to have a `byteWidth` property",
|
|
@@ -265,7 +265,7 @@ function sanitizeFixedSizeBinary(typeLike: object) {
|
|
|
265
265
|
return new FixedSizeBinary(typeLike.byteWidth);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
function sanitizeFixedSizeList(typeLike: object) {
|
|
268
|
+
export function sanitizeFixedSizeList(typeLike: object) {
|
|
269
269
|
if (!("listSize" in typeLike) || typeof typeLike.listSize !== "number") {
|
|
270
270
|
throw Error("Expected a FixedSizeList type to have a `listSize` property");
|
|
271
271
|
}
|
|
@@ -283,7 +283,7 @@ function sanitizeFixedSizeList(typeLike: object) {
|
|
|
283
283
|
);
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
function sanitizeMap(typeLike: object) {
|
|
286
|
+
export function sanitizeMap(typeLike: object) {
|
|
287
287
|
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
288
288
|
throw Error(
|
|
289
289
|
"Expected a Map type to have an array-like `children` property",
|
|
@@ -294,20 +294,20 @@ 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
|
);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
function sanitizeDuration(typeLike: object) {
|
|
303
|
+
export function sanitizeDuration(typeLike: object) {
|
|
304
304
|
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
305
305
|
throw Error("Expected a Duration type to have a `unit` property");
|
|
306
306
|
}
|
|
307
307
|
return new Duration(typeLike.unit);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
function sanitizeDictionary(typeLike: object) {
|
|
310
|
+
export function sanitizeDictionary(typeLike: object) {
|
|
311
311
|
if (!("id" in typeLike) || typeof typeLike.id !== "number") {
|
|
312
312
|
throw Error("Expected a Dictionary type to have an `id` property");
|
|
313
313
|
}
|
|
@@ -328,8 +328,8 @@ function sanitizeDictionary(typeLike: object) {
|
|
|
328
328
|
);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
//
|
|
332
|
-
function sanitizeType(typeLike: unknown): DataType<any> {
|
|
331
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
332
|
+
export 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");
|
|
335
335
|
}
|
|
@@ -449,7 +449,7 @@ function sanitizeType(typeLike: unknown): DataType<any> {
|
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
function sanitizeField(fieldLike: unknown): Field {
|
|
452
|
+
export function sanitizeField(fieldLike: unknown): Field {
|
|
453
453
|
if (fieldLike instanceof Field) {
|
|
454
454
|
return fieldLike;
|
|
455
455
|
}
|
package/lancedb/table.ts
CHANGED
|
@@ -12,16 +12,18 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
-
import { Schema, tableFromIPC } from "
|
|
15
|
+
import { Data, Schema, fromDataToBuffer, tableFromIPC } from "./arrow";
|
|
16
|
+
|
|
17
|
+
import { getRegistry } from "./embedding/registry";
|
|
18
|
+
import { IndexOptions } from "./indices";
|
|
16
19
|
import {
|
|
17
20
|
AddColumnsSql,
|
|
18
21
|
ColumnAlteration,
|
|
19
22
|
IndexConfig,
|
|
23
|
+
OptimizeStats,
|
|
20
24
|
Table as _NativeTable,
|
|
21
25
|
} from "./native";
|
|
22
26
|
import { Query, VectorQuery } from "./query";
|
|
23
|
-
import { IndexOptions } from "./indices";
|
|
24
|
-
import { Data, fromDataToBuffer } from "./arrow";
|
|
25
27
|
|
|
26
28
|
export { IndexConfig } from "./native";
|
|
27
29
|
/**
|
|
@@ -50,6 +52,23 @@ export interface UpdateOptions {
|
|
|
50
52
|
where: string;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
export interface OptimizeOptions {
|
|
56
|
+
/**
|
|
57
|
+
* If set then all versions older than the given date
|
|
58
|
+
* be removed. The current version will never be removed.
|
|
59
|
+
* The default is 7 days
|
|
60
|
+
* @example
|
|
61
|
+
* // Delete all versions older than 1 day
|
|
62
|
+
* const olderThan = new Date();
|
|
63
|
+
* olderThan.setDate(olderThan.getDate() - 1));
|
|
64
|
+
* tbl.cleanupOlderVersions(olderThan);
|
|
65
|
+
*
|
|
66
|
+
* // Delete all versions except the current version
|
|
67
|
+
* tbl.cleanupOlderVersions(new Date());
|
|
68
|
+
*/
|
|
69
|
+
cleanupOlderThan: Date;
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
/**
|
|
54
73
|
* A Table is a collection of Records in a LanceDB Database.
|
|
55
74
|
*
|
|
@@ -104,8 +123,14 @@ export class Table {
|
|
|
104
123
|
*/
|
|
105
124
|
async add(data: Data, options?: Partial<AddDataOptions>): Promise<void> {
|
|
106
125
|
const mode = options?.mode ?? "append";
|
|
126
|
+
const schema = await this.schema();
|
|
127
|
+
const registry = getRegistry();
|
|
128
|
+
const functions = registry.parseFunctions(schema.metadata);
|
|
107
129
|
|
|
108
|
-
const buffer = await fromDataToBuffer(
|
|
130
|
+
const buffer = await fromDataToBuffer(
|
|
131
|
+
data,
|
|
132
|
+
functions.values().next().value,
|
|
133
|
+
);
|
|
109
134
|
await this.inner.add(buffer, mode);
|
|
110
135
|
}
|
|
111
136
|
|
|
@@ -186,7 +211,7 @@ export class Table {
|
|
|
186
211
|
*/
|
|
187
212
|
async createIndex(column: string, options?: Partial<IndexOptions>) {
|
|
188
213
|
// Bit of a hack to get around the fact that TS has no package-scope.
|
|
189
|
-
//
|
|
214
|
+
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
190
215
|
const nativeIndex = (options?.config as any)?.inner;
|
|
191
216
|
await this.inner.createIndex(nativeIndex, column, options?.replace);
|
|
192
217
|
}
|
|
@@ -352,6 +377,48 @@ export class Table {
|
|
|
352
377
|
await this.inner.restore();
|
|
353
378
|
}
|
|
354
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Optimize the on-disk data and indices for better performance.
|
|
382
|
+
*
|
|
383
|
+
* Modeled after ``VACUUM`` in PostgreSQL.
|
|
384
|
+
*
|
|
385
|
+
* Optimization covers three operations:
|
|
386
|
+
*
|
|
387
|
+
* - Compaction: Merges small files into larger ones
|
|
388
|
+
* - Prune: Removes old versions of the dataset
|
|
389
|
+
* - Index: Optimizes the indices, adding new data to existing indices
|
|
390
|
+
*
|
|
391
|
+
*
|
|
392
|
+
* Experimental API
|
|
393
|
+
* ----------------
|
|
394
|
+
*
|
|
395
|
+
* The optimization process is undergoing active development and may change.
|
|
396
|
+
* Our goal with these changes is to improve the performance of optimization and
|
|
397
|
+
* reduce the complexity.
|
|
398
|
+
*
|
|
399
|
+
* That being said, it is essential today to run optimize if you want the best
|
|
400
|
+
* performance. It should be stable and safe to use in production, but it our
|
|
401
|
+
* hope that the API may be simplified (or not even need to be called) in the
|
|
402
|
+
* future.
|
|
403
|
+
*
|
|
404
|
+
* The frequency an application shoudl call optimize is based on the frequency of
|
|
405
|
+
* data modifications. If data is frequently added, deleted, or updated then
|
|
406
|
+
* optimize should be run frequently. A good rule of thumb is to run optimize if
|
|
407
|
+
* you have added or modified 100,000 or more records or run more than 20 data
|
|
408
|
+
* modification operations.
|
|
409
|
+
*/
|
|
410
|
+
async optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats> {
|
|
411
|
+
let cleanupOlderThanMs;
|
|
412
|
+
if (
|
|
413
|
+
options?.cleanupOlderThan !== undefined &&
|
|
414
|
+
options?.cleanupOlderThan !== null
|
|
415
|
+
) {
|
|
416
|
+
cleanupOlderThanMs =
|
|
417
|
+
new Date().getTime() - options.cleanupOlderThan.getTime();
|
|
418
|
+
}
|
|
419
|
+
return await this.inner.optimize(cleanupOlderThanMs);
|
|
420
|
+
}
|
|
421
|
+
|
|
355
422
|
/** List all indices that have been created with {@link Table.createIndex} */
|
|
356
423
|
async listIndices(): Promise<IndexConfig[]> {
|
|
357
424
|
return await this.inner.listIndices();
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Table as ArrowTable, Binary, DataType, FixedSizeBinary, FixedSizeList, Float, Int, LargeBinary, List, Null, Schema, Struct, Utf8 } from "apache-arrow";
|
|
3
3
|
import { type EmbeddingFunction } from "./embedding/embedding_function";
|
|
4
|
+
import { EmbeddingFunctionConfig } from "./embedding/registry";
|
|
5
|
+
export * from "apache-arrow";
|
|
6
|
+
export declare function isArrowTable(value: object): value is ArrowTable;
|
|
7
|
+
export declare function isDataType(value: unknown): value is DataType;
|
|
8
|
+
export declare function isNull(value: unknown): value is Null;
|
|
9
|
+
export declare function isInt(value: unknown): value is Int;
|
|
10
|
+
export declare function isFloat(value: unknown): value is Float;
|
|
11
|
+
export declare function isBinary(value: unknown): value is Binary;
|
|
12
|
+
export declare function isLargeBinary(value: unknown): value is LargeBinary;
|
|
13
|
+
export declare function isUtf8(value: unknown): value is Utf8;
|
|
14
|
+
export declare function isLargeUtf8(value: unknown): value is Utf8;
|
|
15
|
+
export declare function isBool(value: unknown): value is Utf8;
|
|
16
|
+
export declare function isDecimal(value: unknown): value is Utf8;
|
|
17
|
+
export declare function isDate(value: unknown): value is Utf8;
|
|
18
|
+
export declare function isTime(value: unknown): value is Utf8;
|
|
19
|
+
export declare function isTimestamp(value: unknown): value is Utf8;
|
|
20
|
+
export declare function isInterval(value: unknown): value is Utf8;
|
|
21
|
+
export declare function isDuration(value: unknown): value is Utf8;
|
|
22
|
+
export declare function isList(value: unknown): value is List;
|
|
23
|
+
export declare function isStruct(value: unknown): value is Struct;
|
|
24
|
+
export declare function isUnion(value: unknown): value is Struct;
|
|
25
|
+
export declare function isFixedSizeBinary(value: unknown): value is FixedSizeBinary;
|
|
26
|
+
export declare function isFixedSizeList(value: unknown): value is FixedSizeList;
|
|
4
27
|
/** Data type accepted by NodeJS SDK */
|
|
5
28
|
export type Data = Record<string, unknown>[] | ArrowTable;
|
|
6
29
|
export declare class VectorColumnOptions {
|
|
@@ -12,6 +35,7 @@ export declare class VectorColumnOptions {
|
|
|
12
35
|
export declare class MakeArrowTableOptions {
|
|
13
36
|
schema?: Schema;
|
|
14
37
|
vectorColumns: Record<string, VectorColumnOptions>;
|
|
38
|
+
embeddings?: EmbeddingFunction<unknown>;
|
|
15
39
|
/**
|
|
16
40
|
* If true then string columns will be encoded with dictionary encoding
|
|
17
41
|
*
|
|
@@ -116,11 +140,11 @@ export declare class MakeArrowTableOptions {
|
|
|
116
140
|
* assert.deepEqual(table.schema, schema)
|
|
117
141
|
* ```
|
|
118
142
|
*/
|
|
119
|
-
export declare function makeArrowTable(data: Array<Record<string, unknown>>, options?: Partial<MakeArrowTableOptions>): ArrowTable;
|
|
143
|
+
export declare function makeArrowTable(data: Array<Record<string, unknown>>, options?: Partial<MakeArrowTableOptions>, metadata?: Map<string, string>): ArrowTable;
|
|
120
144
|
/**
|
|
121
145
|
* Create an empty Arrow table with the provided schema
|
|
122
146
|
*/
|
|
123
|
-
export declare function makeEmptyTable(schema: Schema): ArrowTable;
|
|
147
|
+
export declare function makeEmptyTable(schema: Schema, metadata?: Map<string, string>): ArrowTable;
|
|
124
148
|
/**
|
|
125
149
|
* Convert an Array of records into an Arrow Table, optionally applying an
|
|
126
150
|
* embeddings function to it.
|
|
@@ -139,7 +163,9 @@ export declare function makeEmptyTable(schema: Schema): ArrowTable;
|
|
|
139
163
|
* embedding columns. If no schema is provded then embedding columns will
|
|
140
164
|
* be placed at the end of the table, after all of the input columns.
|
|
141
165
|
*/
|
|
142
|
-
export declare function convertToTable
|
|
166
|
+
export declare function convertToTable(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunctionConfig, makeTableOptions?: Partial<MakeArrowTableOptions>): Promise<ArrowTable>;
|
|
167
|
+
/** Creates the Arrow Type for a Vector column with dimension `dim` */
|
|
168
|
+
export declare function newVectorType<T extends Float>(dim: number, innerType: T): FixedSizeList<T>;
|
|
143
169
|
/**
|
|
144
170
|
* Serialize an Array of records into a buffer using the Arrow IPC File serialization
|
|
145
171
|
*
|
|
@@ -147,7 +173,7 @@ export declare function convertToTable<T>(data: Array<Record<string, unknown>>,
|
|
|
147
173
|
*
|
|
148
174
|
* `schema` is required if data is empty
|
|
149
175
|
*/
|
|
150
|
-
export declare function fromRecordsToBuffer
|
|
176
|
+
export declare function fromRecordsToBuffer(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunctionConfig, schema?: Schema): Promise<Buffer>;
|
|
151
177
|
/**
|
|
152
178
|
* Serialize an Array of records into a buffer using the Arrow IPC Stream serialization
|
|
153
179
|
*
|
|
@@ -155,7 +181,7 @@ export declare function fromRecordsToBuffer<T>(data: Array<Record<string, unknow
|
|
|
155
181
|
*
|
|
156
182
|
* `schema` is required if data is empty
|
|
157
183
|
*/
|
|
158
|
-
export declare function fromRecordsToStreamBuffer
|
|
184
|
+
export declare function fromRecordsToStreamBuffer(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunctionConfig, schema?: Schema): Promise<Buffer>;
|
|
159
185
|
/**
|
|
160
186
|
* Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
|
|
161
187
|
*
|
|
@@ -164,7 +190,7 @@ export declare function fromRecordsToStreamBuffer<T>(data: Array<Record<string,
|
|
|
164
190
|
*
|
|
165
191
|
* `schema` is required if the table is empty
|
|
166
192
|
*/
|
|
167
|
-
export declare function fromTableToBuffer
|
|
193
|
+
export declare function fromTableToBuffer(table: ArrowTable, embeddings?: EmbeddingFunctionConfig, schema?: Schema): Promise<Buffer>;
|
|
168
194
|
/**
|
|
169
195
|
* Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
|
|
170
196
|
*
|
|
@@ -173,7 +199,7 @@ export declare function fromTableToBuffer<T>(table: ArrowTable, embeddings?: Emb
|
|
|
173
199
|
*
|
|
174
200
|
* `schema` is required if the table is empty
|
|
175
201
|
*/
|
|
176
|
-
export declare function fromDataToBuffer
|
|
202
|
+
export declare function fromDataToBuffer(data: Data, embeddings?: EmbeddingFunctionConfig, schema?: Schema): Promise<Buffer>;
|
|
177
203
|
/**
|
|
178
204
|
* Serialize an Arrow Table into a buffer using the Arrow IPC Stream serialization
|
|
179
205
|
*
|
|
@@ -182,7 +208,7 @@ export declare function fromDataToBuffer<T>(data: Data, embeddings?: EmbeddingFu
|
|
|
182
208
|
*
|
|
183
209
|
* `schema` is required if the table is empty
|
|
184
210
|
*/
|
|
185
|
-
export declare function fromTableToStreamBuffer
|
|
211
|
+
export declare function fromTableToStreamBuffer(table: ArrowTable, embeddings?: EmbeddingFunctionConfig, schema?: Schema): Promise<Buffer>;
|
|
186
212
|
/**
|
|
187
213
|
* Create an empty table with the given schema
|
|
188
214
|
*/
|