@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/native.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/* prettier-ignore */
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
const { existsSync, readFileSync } = require('fs');
|
|
7
|
+
const { join } = require('path');
|
|
8
|
+
const { platform, arch } = process;
|
|
9
|
+
let nativeBinding = null;
|
|
10
|
+
let localFileExisted = false;
|
|
11
|
+
let loadError = null;
|
|
12
|
+
function isMusl() {
|
|
13
|
+
// For Node 10
|
|
14
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
15
|
+
try {
|
|
16
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
17
|
+
return readFileSync(lddPath, 'utf8').includes('musl');
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
25
|
+
return !glibcVersionRuntime;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case 'android':
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case 'arm64':
|
|
32
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.android-arm64.node'));
|
|
33
|
+
try {
|
|
34
|
+
if (localFileExisted) {
|
|
35
|
+
nativeBinding = require('./lancedb.android-arm64.node');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
nativeBinding = require('@lancedb/lancedb-android-arm64');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
loadError = e;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'arm':
|
|
46
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.android-arm-eabi.node'));
|
|
47
|
+
try {
|
|
48
|
+
if (localFileExisted) {
|
|
49
|
+
nativeBinding = require('./lancedb.android-arm-eabi.node');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
nativeBinding = require('@lancedb/lancedb-android-arm-eabi');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
loadError = e;
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Unsupported architecture on Android ${arch}`);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case 'win32':
|
|
64
|
+
switch (arch) {
|
|
65
|
+
case 'x64':
|
|
66
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.win32-x64-msvc.node'));
|
|
67
|
+
try {
|
|
68
|
+
if (localFileExisted) {
|
|
69
|
+
nativeBinding = require('./lancedb.win32-x64-msvc.node');
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
nativeBinding = require('@lancedb/lancedb-win32-x64-msvc');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
loadError = e;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case 'ia32':
|
|
80
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.win32-ia32-msvc.node'));
|
|
81
|
+
try {
|
|
82
|
+
if (localFileExisted) {
|
|
83
|
+
nativeBinding = require('./lancedb.win32-ia32-msvc.node');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
nativeBinding = require('@lancedb/lancedb-win32-ia32-msvc');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
loadError = e;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case 'arm64':
|
|
94
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.win32-arm64-msvc.node'));
|
|
95
|
+
try {
|
|
96
|
+
if (localFileExisted) {
|
|
97
|
+
nativeBinding = require('./lancedb.win32-arm64-msvc.node');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
nativeBinding = require('@lancedb/lancedb-win32-arm64-msvc');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
loadError = e;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case 'darwin':
|
|
112
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.darwin-universal.node'));
|
|
113
|
+
try {
|
|
114
|
+
if (localFileExisted) {
|
|
115
|
+
nativeBinding = require('./lancedb.darwin-universal.node');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
nativeBinding = require('@lancedb/lancedb-darwin-universal');
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
switch (arch) {
|
|
124
|
+
case 'x64':
|
|
125
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.darwin-x64.node'));
|
|
126
|
+
try {
|
|
127
|
+
if (localFileExisted) {
|
|
128
|
+
nativeBinding = require('./lancedb.darwin-x64.node');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
nativeBinding = require('@lancedb/lancedb-darwin-x64');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
loadError = e;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case 'arm64':
|
|
139
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.darwin-arm64.node'));
|
|
140
|
+
try {
|
|
141
|
+
if (localFileExisted) {
|
|
142
|
+
nativeBinding = require('./lancedb.darwin-arm64.node');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
nativeBinding = require('@lancedb/lancedb-darwin-arm64');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
loadError = e;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case 'freebsd':
|
|
157
|
+
if (arch !== 'x64') {
|
|
158
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
|
|
159
|
+
}
|
|
160
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.freebsd-x64.node'));
|
|
161
|
+
try {
|
|
162
|
+
if (localFileExisted) {
|
|
163
|
+
nativeBinding = require('./lancedb.freebsd-x64.node');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
nativeBinding = require('@lancedb/lancedb-freebsd-x64');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
loadError = e;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'linux':
|
|
174
|
+
switch (arch) {
|
|
175
|
+
case 'x64':
|
|
176
|
+
if (isMusl()) {
|
|
177
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-x64-musl.node'));
|
|
178
|
+
try {
|
|
179
|
+
if (localFileExisted) {
|
|
180
|
+
nativeBinding = require('./lancedb.linux-x64-musl.node');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
nativeBinding = require('@lancedb/lancedb-linux-x64-musl');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
loadError = e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-x64-gnu.node'));
|
|
192
|
+
try {
|
|
193
|
+
if (localFileExisted) {
|
|
194
|
+
nativeBinding = require('./lancedb.linux-x64-gnu.node');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
nativeBinding = require('@lancedb/lancedb-linux-x64-gnu');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
loadError = e;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case 'arm64':
|
|
206
|
+
if (isMusl()) {
|
|
207
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm64-musl.node'));
|
|
208
|
+
try {
|
|
209
|
+
if (localFileExisted) {
|
|
210
|
+
nativeBinding = require('./lancedb.linux-arm64-musl.node');
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm64-musl');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
loadError = e;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm64-gnu.node'));
|
|
222
|
+
try {
|
|
223
|
+
if (localFileExisted) {
|
|
224
|
+
nativeBinding = require('./lancedb.linux-arm64-gnu.node');
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm64-gnu');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
loadError = e;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case 'arm':
|
|
236
|
+
if (isMusl()) {
|
|
237
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm-musleabihf.node'));
|
|
238
|
+
try {
|
|
239
|
+
if (localFileExisted) {
|
|
240
|
+
nativeBinding = require('./lancedb.linux-arm-musleabihf.node');
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm-musleabihf');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
loadError = e;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-arm-gnueabihf.node'));
|
|
252
|
+
try {
|
|
253
|
+
if (localFileExisted) {
|
|
254
|
+
nativeBinding = require('./lancedb.linux-arm-gnueabihf.node');
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
nativeBinding = require('@lancedb/lancedb-linux-arm-gnueabihf');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
loadError = e;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
case 'riscv64':
|
|
266
|
+
if (isMusl()) {
|
|
267
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-riscv64-musl.node'));
|
|
268
|
+
try {
|
|
269
|
+
if (localFileExisted) {
|
|
270
|
+
nativeBinding = require('./lancedb.linux-riscv64-musl.node');
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
nativeBinding = require('@lancedb/lancedb-linux-riscv64-musl');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
loadError = e;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-riscv64-gnu.node'));
|
|
282
|
+
try {
|
|
283
|
+
if (localFileExisted) {
|
|
284
|
+
nativeBinding = require('./lancedb.linux-riscv64-gnu.node');
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
nativeBinding = require('@lancedb/lancedb-linux-riscv64-gnu');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
loadError = e;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
295
|
+
case 's390x':
|
|
296
|
+
localFileExisted = existsSync(join(__dirname, 'lancedb.linux-s390x-gnu.node'));
|
|
297
|
+
try {
|
|
298
|
+
if (localFileExisted) {
|
|
299
|
+
nativeBinding = require('./lancedb.linux-s390x-gnu.node');
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
nativeBinding = require('@lancedb/lancedb-linux-s390x-gnu');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
loadError = e;
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
default:
|
|
310
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
311
|
+
}
|
|
312
|
+
break;
|
|
313
|
+
default:
|
|
314
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
315
|
+
}
|
|
316
|
+
if (!nativeBinding) {
|
|
317
|
+
if (loadError) {
|
|
318
|
+
throw loadError;
|
|
319
|
+
}
|
|
320
|
+
throw new Error(`Failed to load native binding`);
|
|
321
|
+
}
|
|
322
|
+
const { Connection, JsHeaderProvider, Index, RecordBatchIterator, NativeMergeInsertBuilder, PermutationBuilder, permutationBuilder, Query, VectorQuery, TakeQuery, JsFullTextQuery, Reranker, RrfReranker, Session, Table, TagContents, Tags } = nativeBinding;
|
|
323
|
+
module.exports.Connection = Connection;
|
|
324
|
+
module.exports.JsHeaderProvider = JsHeaderProvider;
|
|
325
|
+
module.exports.Index = Index;
|
|
326
|
+
module.exports.RecordBatchIterator = RecordBatchIterator;
|
|
327
|
+
module.exports.NativeMergeInsertBuilder = NativeMergeInsertBuilder;
|
|
328
|
+
module.exports.PermutationBuilder = PermutationBuilder;
|
|
329
|
+
module.exports.permutationBuilder = permutationBuilder;
|
|
330
|
+
module.exports.Query = Query;
|
|
331
|
+
module.exports.VectorQuery = VectorQuery;
|
|
332
|
+
module.exports.TakeQuery = TakeQuery;
|
|
333
|
+
module.exports.JsFullTextQuery = JsFullTextQuery;
|
|
334
|
+
module.exports.Reranker = Reranker;
|
|
335
|
+
module.exports.RrfReranker = RrfReranker;
|
|
336
|
+
module.exports.Session = Session;
|
|
337
|
+
module.exports.Table = Table;
|
|
338
|
+
module.exports.TagContents = TagContents;
|
|
339
|
+
module.exports.Tags = Tags;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Connection } from "./connection.js";
|
|
2
|
+
import { PermutationBuilder as NativePermutationBuilder, ShuffleOptions, SplitCalculatedOptions, SplitHashOptions, SplitRandomOptions, SplitSequentialOptions } from "./native.js";
|
|
3
|
+
import { Table } from "./table";
|
|
4
|
+
/**
|
|
5
|
+
* A PermutationBuilder for creating data permutations with splits, shuffling, and filtering.
|
|
6
|
+
*
|
|
7
|
+
* This class provides a TypeScript wrapper around the native Rust PermutationBuilder,
|
|
8
|
+
* offering methods to configure data splits, shuffling, and filtering before executing
|
|
9
|
+
* the permutation to create a new table.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PermutationBuilder {
|
|
12
|
+
private inner;
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
constructor(inner: NativePermutationBuilder);
|
|
17
|
+
/**
|
|
18
|
+
* Configure the permutation to be persisted.
|
|
19
|
+
*
|
|
20
|
+
* @param connection - The connection to persist the permutation to
|
|
21
|
+
* @param tableName - The name of the table to create
|
|
22
|
+
* @returns A new PermutationBuilder instance
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* builder.persist(connection, "permutation_table");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
persist(connection: Connection, tableName: string): PermutationBuilder;
|
|
29
|
+
/**
|
|
30
|
+
* Configure random splits for the permutation.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Configuration for random splitting
|
|
33
|
+
* @returns A new PermutationBuilder instance
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Split by ratios
|
|
37
|
+
* builder.splitRandom({ ratios: [0.7, 0.3], seed: 42 });
|
|
38
|
+
*
|
|
39
|
+
* // Split by counts
|
|
40
|
+
* builder.splitRandom({ counts: [1000, 500], seed: 42 });
|
|
41
|
+
*
|
|
42
|
+
* // Split with fixed size
|
|
43
|
+
* builder.splitRandom({ fixed: 100, seed: 42 });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
splitRandom(options: SplitRandomOptions): PermutationBuilder;
|
|
47
|
+
/**
|
|
48
|
+
* Configure hash-based splits for the permutation.
|
|
49
|
+
*
|
|
50
|
+
* @param options - Configuration for hash-based splitting
|
|
51
|
+
* @returns A new PermutationBuilder instance
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* builder.splitHash({
|
|
55
|
+
* columns: ["user_id"],
|
|
56
|
+
* splitWeights: [70, 30],
|
|
57
|
+
* discardWeight: 0
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
splitHash(options: SplitHashOptions): PermutationBuilder;
|
|
62
|
+
/**
|
|
63
|
+
* Configure sequential splits for the permutation.
|
|
64
|
+
*
|
|
65
|
+
* @param options - Configuration for sequential splitting
|
|
66
|
+
* @returns A new PermutationBuilder instance
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* // Split by ratios
|
|
70
|
+
* builder.splitSequential({ ratios: [0.8, 0.2] });
|
|
71
|
+
*
|
|
72
|
+
* // Split by counts
|
|
73
|
+
* builder.splitSequential({ counts: [800, 200] });
|
|
74
|
+
*
|
|
75
|
+
* // Split with fixed size
|
|
76
|
+
* builder.splitSequential({ fixed: 1000 });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
splitSequential(options: SplitSequentialOptions): PermutationBuilder;
|
|
80
|
+
/**
|
|
81
|
+
* Configure calculated splits for the permutation.
|
|
82
|
+
*
|
|
83
|
+
* @param options - Configuration for calculated splitting
|
|
84
|
+
* @returns A new PermutationBuilder instance
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* builder.splitCalculated({ calculation: "user_id % 3" });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
splitCalculated(options: SplitCalculatedOptions): PermutationBuilder;
|
|
91
|
+
/**
|
|
92
|
+
* Configure shuffling for the permutation.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Configuration for shuffling
|
|
95
|
+
* @returns A new PermutationBuilder instance
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* // Basic shuffle
|
|
99
|
+
* builder.shuffle({ seed: 42 });
|
|
100
|
+
*
|
|
101
|
+
* // Shuffle with clump size
|
|
102
|
+
* builder.shuffle({ seed: 42, clumpSize: 10 });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
shuffle(options: ShuffleOptions): PermutationBuilder;
|
|
106
|
+
/**
|
|
107
|
+
* Configure filtering for the permutation.
|
|
108
|
+
*
|
|
109
|
+
* @param filter - SQL filter expression
|
|
110
|
+
* @returns A new PermutationBuilder instance
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* builder.filter("age > 18 AND status = 'active'");
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
filter(filter: string): PermutationBuilder;
|
|
117
|
+
/**
|
|
118
|
+
* Execute the permutation and create the destination table.
|
|
119
|
+
*
|
|
120
|
+
* @returns A Promise that resolves to the new Table instance
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const permutationTable = await builder.execute();
|
|
124
|
+
* console.log(`Created table: ${permutationTable.name}`);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
execute(): Promise<Table>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a permutation builder for the given table.
|
|
131
|
+
*
|
|
132
|
+
* @param table - The source table to create a permutation from
|
|
133
|
+
* @returns A PermutationBuilder instance
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const builder = permutationBuilder(sourceTable, "training_data")
|
|
137
|
+
* .splitRandom({ ratios: [0.8, 0.2], seed: 42 })
|
|
138
|
+
* .shuffle({ seed: 123 });
|
|
139
|
+
*
|
|
140
|
+
* const trainingTable = await builder.execute();
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function permutationBuilder(table: Table): PermutationBuilder;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PermutationBuilder = void 0;
|
|
6
|
+
exports.permutationBuilder = permutationBuilder;
|
|
7
|
+
const native_js_1 = require("./native.js");
|
|
8
|
+
const table_1 = require("./table");
|
|
9
|
+
/**
|
|
10
|
+
* A PermutationBuilder for creating data permutations with splits, shuffling, and filtering.
|
|
11
|
+
*
|
|
12
|
+
* This class provides a TypeScript wrapper around the native Rust PermutationBuilder,
|
|
13
|
+
* offering methods to configure data splits, shuffling, and filtering before executing
|
|
14
|
+
* the permutation to create a new table.
|
|
15
|
+
*/
|
|
16
|
+
class PermutationBuilder {
|
|
17
|
+
inner;
|
|
18
|
+
/**
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
constructor(inner) {
|
|
22
|
+
this.inner = inner;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configure the permutation to be persisted.
|
|
26
|
+
*
|
|
27
|
+
* @param connection - The connection to persist the permutation to
|
|
28
|
+
* @param tableName - The name of the table to create
|
|
29
|
+
* @returns A new PermutationBuilder instance
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* builder.persist(connection, "permutation_table");
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
persist(connection, tableName) {
|
|
36
|
+
const localConnection = connection;
|
|
37
|
+
const newInner = this.inner.persist(localConnection.inner, tableName);
|
|
38
|
+
return new PermutationBuilder(newInner);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configure random splits for the permutation.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration for random splitting
|
|
44
|
+
* @returns A new PermutationBuilder instance
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Split by ratios
|
|
48
|
+
* builder.splitRandom({ ratios: [0.7, 0.3], seed: 42 });
|
|
49
|
+
*
|
|
50
|
+
* // Split by counts
|
|
51
|
+
* builder.splitRandom({ counts: [1000, 500], seed: 42 });
|
|
52
|
+
*
|
|
53
|
+
* // Split with fixed size
|
|
54
|
+
* builder.splitRandom({ fixed: 100, seed: 42 });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
splitRandom(options) {
|
|
58
|
+
const newInner = this.inner.splitRandom(options);
|
|
59
|
+
return new PermutationBuilder(newInner);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Configure hash-based splits for the permutation.
|
|
63
|
+
*
|
|
64
|
+
* @param options - Configuration for hash-based splitting
|
|
65
|
+
* @returns A new PermutationBuilder instance
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* builder.splitHash({
|
|
69
|
+
* columns: ["user_id"],
|
|
70
|
+
* splitWeights: [70, 30],
|
|
71
|
+
* discardWeight: 0
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
splitHash(options) {
|
|
76
|
+
const newInner = this.inner.splitHash(options);
|
|
77
|
+
return new PermutationBuilder(newInner);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Configure sequential splits for the permutation.
|
|
81
|
+
*
|
|
82
|
+
* @param options - Configuration for sequential splitting
|
|
83
|
+
* @returns A new PermutationBuilder instance
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* // Split by ratios
|
|
87
|
+
* builder.splitSequential({ ratios: [0.8, 0.2] });
|
|
88
|
+
*
|
|
89
|
+
* // Split by counts
|
|
90
|
+
* builder.splitSequential({ counts: [800, 200] });
|
|
91
|
+
*
|
|
92
|
+
* // Split with fixed size
|
|
93
|
+
* builder.splitSequential({ fixed: 1000 });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
splitSequential(options) {
|
|
97
|
+
const newInner = this.inner.splitSequential(options);
|
|
98
|
+
return new PermutationBuilder(newInner);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Configure calculated splits for the permutation.
|
|
102
|
+
*
|
|
103
|
+
* @param options - Configuration for calculated splitting
|
|
104
|
+
* @returns A new PermutationBuilder instance
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* builder.splitCalculated({ calculation: "user_id % 3" });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
splitCalculated(options) {
|
|
111
|
+
const newInner = this.inner.splitCalculated(options);
|
|
112
|
+
return new PermutationBuilder(newInner);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Configure shuffling for the permutation.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Configuration for shuffling
|
|
118
|
+
* @returns A new PermutationBuilder instance
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* // Basic shuffle
|
|
122
|
+
* builder.shuffle({ seed: 42 });
|
|
123
|
+
*
|
|
124
|
+
* // Shuffle with clump size
|
|
125
|
+
* builder.shuffle({ seed: 42, clumpSize: 10 });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
shuffle(options) {
|
|
129
|
+
const newInner = this.inner.shuffle(options);
|
|
130
|
+
return new PermutationBuilder(newInner);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Configure filtering for the permutation.
|
|
134
|
+
*
|
|
135
|
+
* @param filter - SQL filter expression
|
|
136
|
+
* @returns A new PermutationBuilder instance
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* builder.filter("age > 18 AND status = 'active'");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
filter(filter) {
|
|
143
|
+
const newInner = this.inner.filter(filter);
|
|
144
|
+
return new PermutationBuilder(newInner);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Execute the permutation and create the destination table.
|
|
148
|
+
*
|
|
149
|
+
* @returns A Promise that resolves to the new Table instance
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const permutationTable = await builder.execute();
|
|
153
|
+
* console.log(`Created table: ${permutationTable.name}`);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
async execute() {
|
|
157
|
+
const nativeTable = await this.inner.execute();
|
|
158
|
+
return new table_1.LocalTable(nativeTable);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.PermutationBuilder = PermutationBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* Create a permutation builder for the given table.
|
|
164
|
+
*
|
|
165
|
+
* @param table - The source table to create a permutation from
|
|
166
|
+
* @returns A PermutationBuilder instance
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const builder = permutationBuilder(sourceTable, "training_data")
|
|
170
|
+
* .splitRandom({ ratios: [0.8, 0.2], seed: 42 })
|
|
171
|
+
* .shuffle({ seed: 123 });
|
|
172
|
+
*
|
|
173
|
+
* const trainingTable = await builder.execute();
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function permutationBuilder(table) {
|
|
177
|
+
// Extract the inner native table from the TypeScript wrapper
|
|
178
|
+
const localTable = table;
|
|
179
|
+
// Access inner through type assertion since it's private
|
|
180
|
+
const nativeBuilder = (0, native_js_1.permutationBuilder)(
|
|
181
|
+
// biome-ignore lint/suspicious/noExplicitAny: need access to private variable
|
|
182
|
+
localTable.inner);
|
|
183
|
+
return new PermutationBuilder(nativeBuilder);
|
|
184
|
+
}
|