@lancedb/lancedb 0.4.3 → 0.4.15
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 +35 -3
- package/dist/arrow.d.ts +189 -0
- package/dist/arrow.js +539 -0
- package/dist/connection.d.ts +97 -0
- package/dist/connection.js +126 -0
- package/dist/embedding/embedding_function.d.ts +45 -0
- package/dist/embedding/embedding_function.js +27 -0
- package/dist/embedding/index.d.ts +2 -0
- package/dist/embedding/index.js +7 -0
- package/dist/embedding/openai.d.ts +8 -0
- package/dist/embedding/openai.js +53 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +52 -0
- package/dist/indices.d.ts +165 -0
- package/dist/indices.js +71 -0
- package/dist/native.d.ts +147 -0
- package/dist/native.js +314 -0
- package/dist/query.d.ts +248 -0
- package/dist/query.js +346 -0
- package/dist/sanitize.d.ts +9 -0
- package/dist/sanitize.js +369 -0
- package/dist/table.d.ts +252 -0
- package/dist/table.js +298 -0
- package/nodejs-artifacts/arrow.d.ts +189 -0
- package/nodejs-artifacts/arrow.js +539 -0
- package/nodejs-artifacts/connection.d.ts +97 -0
- package/nodejs-artifacts/connection.js +126 -0
- package/nodejs-artifacts/embedding/embedding_function.d.ts +45 -0
- package/nodejs-artifacts/embedding/embedding_function.js +27 -0
- package/nodejs-artifacts/embedding/index.d.ts +2 -0
- package/nodejs-artifacts/embedding/index.js +7 -0
- package/nodejs-artifacts/embedding/openai.d.ts +8 -0
- package/nodejs-artifacts/embedding/openai.js +53 -0
- package/nodejs-artifacts/index.d.ts +22 -0
- package/nodejs-artifacts/index.js +52 -0
- package/nodejs-artifacts/indices.d.ts +165 -0
- package/nodejs-artifacts/indices.js +71 -0
- package/nodejs-artifacts/native.d.ts +147 -0
- package/nodejs-artifacts/native.js +314 -0
- package/nodejs-artifacts/query.d.ts +248 -0
- package/nodejs-artifacts/query.js +346 -0
- package/nodejs-artifacts/sanitize.d.ts +9 -0
- package/nodejs-artifacts/sanitize.js +369 -0
- package/nodejs-artifacts/table.d.ts +252 -0
- package/nodejs-artifacts/table.js +298 -0
- package/package.json +9 -11
- package/typedoc.json +10 -0
- package/examples/js/index.mjs +0 -40
- package/examples/js/package.json +0 -14
- package/examples/js-openai/index.mjs +0 -43
- package/examples/js-openai/package-lock.json +0 -256
- package/examples/js-openai/package.json +0 -15
- package/examples/js-transformers/index.mjs +0 -65
- package/examples/js-transformers/package-lock.json +0 -1418
- package/examples/js-transformers/package.json +0 -15
- package/examples/js-youtube-transcripts/index.mjs +0 -135
- package/examples/js-youtube-transcripts/package.json +0 -15
- package/examples/ts/data/sample-lancedb/vectors.lance/_latest.manifest +0 -0
- package/examples/ts/data/sample-lancedb/vectors.lance/_transactions/0-adde4e05-fcfc-415c-86a6-5b252cb9e79a.txn +0 -0
- package/examples/ts/data/sample-lancedb/vectors.lance/_versions/1.manifest +0 -0
- package/examples/ts/data/sample-lancedb/vectors.lance/data/3618b33e-3eea-4b5e-a0fc-7d1f718d551e.lance +0 -0
- package/examples/ts/package-lock.json +0 -1340
- package/examples/ts/package.json +0 -22
- package/examples/ts/tsconfig.json +0 -10
package/dist/table.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
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.Table = void 0;
|
|
17
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
18
|
+
const query_1 = require("./query");
|
|
19
|
+
const arrow_1 = require("./arrow");
|
|
20
|
+
/**
|
|
21
|
+
* A Table is a collection of Records in a LanceDB Database.
|
|
22
|
+
*
|
|
23
|
+
* A Table object is expected to be long lived and reused for multiple operations.
|
|
24
|
+
* Table objects will cache a certain amount of index data in memory. This cache
|
|
25
|
+
* will be freed when the Table is garbage collected. To eagerly free the cache you
|
|
26
|
+
* can call the `close` method. Once the Table is closed, it cannot be used for any
|
|
27
|
+
* further operations.
|
|
28
|
+
*
|
|
29
|
+
* Closing a table is optional. It not closed, it will be closed when it is garbage
|
|
30
|
+
* collected.
|
|
31
|
+
*/
|
|
32
|
+
class Table {
|
|
33
|
+
inner;
|
|
34
|
+
/** Construct a Table. Internal use only. */
|
|
35
|
+
constructor(inner) {
|
|
36
|
+
this.inner = inner;
|
|
37
|
+
}
|
|
38
|
+
/** Return true if the table has not been closed */
|
|
39
|
+
isOpen() {
|
|
40
|
+
return this.inner.isOpen();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Close the table, releasing any underlying resources.
|
|
44
|
+
*
|
|
45
|
+
* It is safe to call this method multiple times.
|
|
46
|
+
*
|
|
47
|
+
* Any attempt to use the table after it is closed will result in an error.
|
|
48
|
+
*/
|
|
49
|
+
close() {
|
|
50
|
+
this.inner.close();
|
|
51
|
+
}
|
|
52
|
+
/** Return a brief description of the table */
|
|
53
|
+
display() {
|
|
54
|
+
return this.inner.display();
|
|
55
|
+
}
|
|
56
|
+
/** Get the schema of the table. */
|
|
57
|
+
async schema() {
|
|
58
|
+
const schemaBuf = await this.inner.schema();
|
|
59
|
+
const tbl = (0, apache_arrow_1.tableFromIPC)(schemaBuf);
|
|
60
|
+
return tbl.schema;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Insert records into this Table.
|
|
64
|
+
* @param {Data} data Records to be inserted into the Table
|
|
65
|
+
*/
|
|
66
|
+
async add(data, options) {
|
|
67
|
+
const mode = options?.mode ?? "append";
|
|
68
|
+
const buffer = await (0, arrow_1.fromDataToBuffer)(data);
|
|
69
|
+
await this.inner.add(buffer, mode);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Update existing records in the Table
|
|
73
|
+
*
|
|
74
|
+
* An update operation can be used to adjust existing values. Use the
|
|
75
|
+
* returned builder to specify which columns to update. The new value
|
|
76
|
+
* can be a literal value (e.g. replacing nulls with some default value)
|
|
77
|
+
* or an expression applied to the old value (e.g. incrementing a value)
|
|
78
|
+
*
|
|
79
|
+
* An optional condition can be specified (e.g. "only update if the old
|
|
80
|
+
* value is 0")
|
|
81
|
+
*
|
|
82
|
+
* Note: if your condition is something like "some_id_column == 7" and
|
|
83
|
+
* you are updating many rows (with different ids) then you will get
|
|
84
|
+
* better performance with a single [`merge_insert`] call instead of
|
|
85
|
+
* repeatedly calilng this method.
|
|
86
|
+
* @param {Map<string, string> | Record<string, string>} updates - the
|
|
87
|
+
* columns to update
|
|
88
|
+
*
|
|
89
|
+
* Keys in the map should specify the name of the column to update.
|
|
90
|
+
* Values in the map provide the new value of the column. These can
|
|
91
|
+
* be SQL literal strings (e.g. "7" or "'foo'") or they can be expressions
|
|
92
|
+
* based on the row being updated (e.g. "my_col + 1")
|
|
93
|
+
* @param {Partial<UpdateOptions>} options - additional options to control
|
|
94
|
+
* the update behavior
|
|
95
|
+
*/
|
|
96
|
+
async update(updates, options) {
|
|
97
|
+
const onlyIf = options?.where;
|
|
98
|
+
let columns;
|
|
99
|
+
if (updates instanceof Map) {
|
|
100
|
+
columns = Array.from(updates.entries());
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
columns = Object.entries(updates);
|
|
104
|
+
}
|
|
105
|
+
await this.inner.update(onlyIf, columns);
|
|
106
|
+
}
|
|
107
|
+
/** Count the total number of rows in the dataset. */
|
|
108
|
+
async countRows(filter) {
|
|
109
|
+
return await this.inner.countRows(filter);
|
|
110
|
+
}
|
|
111
|
+
/** Delete the rows that satisfy the predicate. */
|
|
112
|
+
async delete(predicate) {
|
|
113
|
+
await this.inner.delete(predicate);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create an index to speed up queries.
|
|
117
|
+
*
|
|
118
|
+
* Indices can be created on vector columns or scalar columns.
|
|
119
|
+
* Indices on vector columns will speed up vector searches.
|
|
120
|
+
* Indices on scalar columns will speed up filtering (in both
|
|
121
|
+
* vector and non-vector searches)
|
|
122
|
+
* @example
|
|
123
|
+
* // If the column has a vector (fixed size list) data type then
|
|
124
|
+
* // an IvfPq vector index will be created.
|
|
125
|
+
* const table = await conn.openTable("my_table");
|
|
126
|
+
* await table.createIndex(["vector"]);
|
|
127
|
+
* @example
|
|
128
|
+
* // For advanced control over vector index creation you can specify
|
|
129
|
+
* // the index type and options.
|
|
130
|
+
* const table = await conn.openTable("my_table");
|
|
131
|
+
* await table.createIndex(["vector"], I)
|
|
132
|
+
* .ivf_pq({ num_partitions: 128, num_sub_vectors: 16 })
|
|
133
|
+
* .build();
|
|
134
|
+
* @example
|
|
135
|
+
* // Or create a Scalar index
|
|
136
|
+
* await table.createIndex("my_float_col").build();
|
|
137
|
+
*/
|
|
138
|
+
async createIndex(column, options) {
|
|
139
|
+
// Bit of a hack to get around the fact that TS has no package-scope.
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
const nativeIndex = options?.config?.inner;
|
|
142
|
+
await this.inner.createIndex(nativeIndex, column, options?.replace);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a {@link Query} Builder.
|
|
146
|
+
*
|
|
147
|
+
* Queries allow you to search your existing data. By default the query will
|
|
148
|
+
* return all the data in the table in no particular order. The builder
|
|
149
|
+
* returned by this method can be used to control the query using filtering,
|
|
150
|
+
* vector similarity, sorting, and more.
|
|
151
|
+
*
|
|
152
|
+
* Note: By default, all columns are returned. For best performance, you should
|
|
153
|
+
* only fetch the columns you need. See [`Query::select_with_projection`] for
|
|
154
|
+
* more details.
|
|
155
|
+
*
|
|
156
|
+
* When appropriate, various indices and statistics based pruning will be used to
|
|
157
|
+
* accelerate the query.
|
|
158
|
+
* @example
|
|
159
|
+
* // SQL-style filtering
|
|
160
|
+
* //
|
|
161
|
+
* // This query will return up to 1000 rows whose value in the `id` column
|
|
162
|
+
* // is greater than 5. LanceDb supports a broad set of filtering functions.
|
|
163
|
+
* for await (const batch of table.query()
|
|
164
|
+
* .filter("id > 1").select(["id"]).limit(20)) {
|
|
165
|
+
* console.log(batch);
|
|
166
|
+
* }
|
|
167
|
+
* @example
|
|
168
|
+
* // Vector Similarity Search
|
|
169
|
+
* //
|
|
170
|
+
* // This example will find the 10 rows whose value in the "vector" column are
|
|
171
|
+
* // closest to the query vector [1.0, 2.0, 3.0]. If an index has been created
|
|
172
|
+
* // on the "vector" column then this will perform an ANN search.
|
|
173
|
+
* //
|
|
174
|
+
* // The `refine_factor` and `nprobes` methods are used to control the recall /
|
|
175
|
+
* // latency tradeoff of the search.
|
|
176
|
+
* for await (const batch of table.query()
|
|
177
|
+
* .nearestTo([1, 2, 3])
|
|
178
|
+
* .refineFactor(5).nprobe(10)
|
|
179
|
+
* .limit(10)) {
|
|
180
|
+
* console.log(batch);
|
|
181
|
+
* }
|
|
182
|
+
* @example
|
|
183
|
+
* // Scan the full dataset
|
|
184
|
+
* //
|
|
185
|
+
* // This query will return everything in the table in no particular order.
|
|
186
|
+
* for await (const batch of table.query()) {
|
|
187
|
+
* console.log(batch);
|
|
188
|
+
* }
|
|
189
|
+
* @returns {Query} A builder that can be used to parameterize the query
|
|
190
|
+
*/
|
|
191
|
+
query() {
|
|
192
|
+
return new query_1.Query(this.inner);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Search the table with a given query vector.
|
|
196
|
+
*
|
|
197
|
+
* This is a convenience method for preparing a vector query and
|
|
198
|
+
* is the same thing as calling `nearestTo` on the builder returned
|
|
199
|
+
* by `query`. @see {@link Query#nearestTo} for more details.
|
|
200
|
+
*/
|
|
201
|
+
vectorSearch(vector) {
|
|
202
|
+
return this.query().nearestTo(vector);
|
|
203
|
+
}
|
|
204
|
+
// TODO: Support BatchUDF
|
|
205
|
+
/**
|
|
206
|
+
* Add new columns with defined values.
|
|
207
|
+
* @param {AddColumnsSql[]} newColumnTransforms pairs of column names and
|
|
208
|
+
* the SQL expression to use to calculate the value of the new column. These
|
|
209
|
+
* expressions will be evaluated for each row in the table, and can
|
|
210
|
+
* reference existing columns in the table.
|
|
211
|
+
*/
|
|
212
|
+
async addColumns(newColumnTransforms) {
|
|
213
|
+
await this.inner.addColumns(newColumnTransforms);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Alter the name or nullability of columns.
|
|
217
|
+
* @param {ColumnAlteration[]} columnAlterations One or more alterations to
|
|
218
|
+
* apply to columns.
|
|
219
|
+
*/
|
|
220
|
+
async alterColumns(columnAlterations) {
|
|
221
|
+
await this.inner.alterColumns(columnAlterations);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Drop one or more columns from the dataset
|
|
225
|
+
*
|
|
226
|
+
* This is a metadata-only operation and does not remove the data from the
|
|
227
|
+
* underlying storage. In order to remove the data, you must subsequently
|
|
228
|
+
* call ``compact_files`` to rewrite the data without the removed columns and
|
|
229
|
+
* then call ``cleanup_files`` to remove the old files.
|
|
230
|
+
* @param {string[]} columnNames The names of the columns to drop. These can
|
|
231
|
+
* be nested column references (e.g. "a.b.c") or top-level column names
|
|
232
|
+
* (e.g. "a").
|
|
233
|
+
*/
|
|
234
|
+
async dropColumns(columnNames) {
|
|
235
|
+
await this.inner.dropColumns(columnNames);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Retrieve the version of the table
|
|
239
|
+
*
|
|
240
|
+
* LanceDb supports versioning. Every operation that modifies the table increases
|
|
241
|
+
* version. As long as a version hasn't been deleted you can `[Self::checkout]` that
|
|
242
|
+
* version to view the data at that point. In addition, you can `[Self::restore]` the
|
|
243
|
+
* version to replace the current table with a previous version.
|
|
244
|
+
*/
|
|
245
|
+
async version() {
|
|
246
|
+
return await this.inner.version();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Checks out a specific version of the Table
|
|
250
|
+
*
|
|
251
|
+
* Any read operation on the table will now access the data at the checked out version.
|
|
252
|
+
* As a consequence, calling this method will disable any read consistency interval
|
|
253
|
+
* that was previously set.
|
|
254
|
+
*
|
|
255
|
+
* This is a read-only operation that turns the table into a sort of "view"
|
|
256
|
+
* or "detached head". Other table instances will not be affected. To make the change
|
|
257
|
+
* permanent you can use the `[Self::restore]` method.
|
|
258
|
+
*
|
|
259
|
+
* Any operation that modifies the table will fail while the table is in a checked
|
|
260
|
+
* out state.
|
|
261
|
+
*
|
|
262
|
+
* To return the table to a normal state use `[Self::checkout_latest]`
|
|
263
|
+
*/
|
|
264
|
+
async checkout(version) {
|
|
265
|
+
await this.inner.checkout(version);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Ensures the table is pointing at the latest version
|
|
269
|
+
*
|
|
270
|
+
* This can be used to manually update a table when the read_consistency_interval is None
|
|
271
|
+
* It can also be used to undo a `[Self::checkout]` operation
|
|
272
|
+
*/
|
|
273
|
+
async checkoutLatest() {
|
|
274
|
+
await this.inner.checkoutLatest();
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Restore the table to the currently checked out version
|
|
278
|
+
*
|
|
279
|
+
* This operation will fail if checkout has not been called previously
|
|
280
|
+
*
|
|
281
|
+
* This operation will overwrite the latest version of the table with a
|
|
282
|
+
* previous version. Any changes made since the checked out version will
|
|
283
|
+
* no longer be visible.
|
|
284
|
+
*
|
|
285
|
+
* Once the operation concludes the table will no longer be in a checked
|
|
286
|
+
* out state and the read_consistency_interval, if any, will apply.
|
|
287
|
+
*/
|
|
288
|
+
async restore() {
|
|
289
|
+
await this.inner.restore();
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* List all indices that have been created with Self::create_index
|
|
293
|
+
*/
|
|
294
|
+
async listIndices() {
|
|
295
|
+
return await this.inner.listIndices();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type Schema, Table as ArrowTable, type Float } from "apache-arrow";
|
|
3
|
+
import { type EmbeddingFunction } from "./embedding/embedding_function";
|
|
4
|
+
/** Data type accepted by NodeJS SDK */
|
|
5
|
+
export type Data = Record<string, unknown>[] | ArrowTable;
|
|
6
|
+
export declare class VectorColumnOptions {
|
|
7
|
+
/** Vector column type. */
|
|
8
|
+
type: Float;
|
|
9
|
+
constructor(values?: Partial<VectorColumnOptions>);
|
|
10
|
+
}
|
|
11
|
+
/** Options to control the makeArrowTable call. */
|
|
12
|
+
export declare class MakeArrowTableOptions {
|
|
13
|
+
schema?: Schema;
|
|
14
|
+
vectorColumns: Record<string, VectorColumnOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* If true then string columns will be encoded with dictionary encoding
|
|
17
|
+
*
|
|
18
|
+
* Set this to true if your string columns tend to repeat the same values
|
|
19
|
+
* often. For more precise control use the `schema` property to specify the
|
|
20
|
+
* data type for individual columns.
|
|
21
|
+
*
|
|
22
|
+
* If `schema` is provided then this property is ignored.
|
|
23
|
+
*/
|
|
24
|
+
dictionaryEncodeStrings: boolean;
|
|
25
|
+
constructor(values?: Partial<MakeArrowTableOptions>);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An enhanced version of the {@link makeTable} function from Apache Arrow
|
|
29
|
+
* that supports nested fields and embeddings columns.
|
|
30
|
+
*
|
|
31
|
+
* (typically you do not need to call this function. It will be called automatically
|
|
32
|
+
* when creating a table or adding data to it)
|
|
33
|
+
*
|
|
34
|
+
* This function converts an array of Record<String, any> (row-major JS objects)
|
|
35
|
+
* to an Arrow Table (a columnar structure)
|
|
36
|
+
*
|
|
37
|
+
* Note that it currently does not support nulls.
|
|
38
|
+
*
|
|
39
|
+
* If a schema is provided then it will be used to determine the resulting array
|
|
40
|
+
* types. Fields will also be reordered to fit the order defined by the schema.
|
|
41
|
+
*
|
|
42
|
+
* If a schema is not provided then the types will be inferred and the field order
|
|
43
|
+
* will be controlled by the order of properties in the first record. If a type
|
|
44
|
+
* is inferred it will always be nullable.
|
|
45
|
+
*
|
|
46
|
+
* If the input is empty then a schema must be provided to create an empty table.
|
|
47
|
+
*
|
|
48
|
+
* When a schema is not specified then data types will be inferred. The inference
|
|
49
|
+
* rules are as follows:
|
|
50
|
+
*
|
|
51
|
+
* - boolean => Bool
|
|
52
|
+
* - number => Float64
|
|
53
|
+
* - String => Utf8
|
|
54
|
+
* - Buffer => Binary
|
|
55
|
+
* - Record<String, any> => Struct
|
|
56
|
+
* - Array<any> => List
|
|
57
|
+
* @example
|
|
58
|
+
* import { fromTableToBuffer, makeArrowTable } from "../arrow";
|
|
59
|
+
* import { Field, FixedSizeList, Float16, Float32, Int32, Schema } from "apache-arrow";
|
|
60
|
+
*
|
|
61
|
+
* const schema = new Schema([
|
|
62
|
+
* new Field("a", new Int32()),
|
|
63
|
+
* new Field("b", new Float32()),
|
|
64
|
+
* new Field("c", new FixedSizeList(3, new Field("item", new Float16()))),
|
|
65
|
+
* ]);
|
|
66
|
+
* const table = makeArrowTable([
|
|
67
|
+
* { a: 1, b: 2, c: [1, 2, 3] },
|
|
68
|
+
* { a: 4, b: 5, c: [4, 5, 6] },
|
|
69
|
+
* { a: 7, b: 8, c: [7, 8, 9] },
|
|
70
|
+
* ], { schema });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* By default it assumes that the column named `vector` is a vector column
|
|
74
|
+
* and it will be converted into a fixed size list array of type float32.
|
|
75
|
+
* The `vectorColumns` option can be used to support other vector column
|
|
76
|
+
* names and data types.
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
*
|
|
80
|
+
* const schema = new Schema([
|
|
81
|
+
new Field("a", new Float64()),
|
|
82
|
+
new Field("b", new Float64()),
|
|
83
|
+
new Field(
|
|
84
|
+
"vector",
|
|
85
|
+
new FixedSizeList(3, new Field("item", new Float32()))
|
|
86
|
+
),
|
|
87
|
+
]);
|
|
88
|
+
const table = makeArrowTable([
|
|
89
|
+
{ a: 1, b: 2, vector: [1, 2, 3] },
|
|
90
|
+
{ a: 4, b: 5, vector: [4, 5, 6] },
|
|
91
|
+
{ a: 7, b: 8, vector: [7, 8, 9] },
|
|
92
|
+
]);
|
|
93
|
+
assert.deepEqual(table.schema, schema);
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* You can specify the vector column types and names using the options as well
|
|
97
|
+
*
|
|
98
|
+
* ```typescript
|
|
99
|
+
*
|
|
100
|
+
* const schema = new Schema([
|
|
101
|
+
new Field('a', new Float64()),
|
|
102
|
+
new Field('b', new Float64()),
|
|
103
|
+
new Field('vec1', new FixedSizeList(3, new Field('item', new Float16()))),
|
|
104
|
+
new Field('vec2', new FixedSizeList(3, new Field('item', new Float16())))
|
|
105
|
+
]);
|
|
106
|
+
* const table = makeArrowTable([
|
|
107
|
+
{ a: 1, b: 2, vec1: [1, 2, 3], vec2: [2, 4, 6] },
|
|
108
|
+
{ a: 4, b: 5, vec1: [4, 5, 6], vec2: [8, 10, 12] },
|
|
109
|
+
{ a: 7, b: 8, vec1: [7, 8, 9], vec2: [14, 16, 18] }
|
|
110
|
+
], {
|
|
111
|
+
vectorColumns: {
|
|
112
|
+
vec1: { type: new Float16() },
|
|
113
|
+
vec2: { type: new Float16() }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
* assert.deepEqual(table.schema, schema)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function makeArrowTable(data: Array<Record<string, unknown>>, options?: Partial<MakeArrowTableOptions>): ArrowTable;
|
|
120
|
+
/**
|
|
121
|
+
* Create an empty Arrow table with the provided schema
|
|
122
|
+
*/
|
|
123
|
+
export declare function makeEmptyTable(schema: Schema): ArrowTable;
|
|
124
|
+
/**
|
|
125
|
+
* Convert an Array of records into an Arrow Table, optionally applying an
|
|
126
|
+
* embeddings function to it.
|
|
127
|
+
*
|
|
128
|
+
* This function calls `makeArrowTable` first to create the Arrow Table.
|
|
129
|
+
* Any provided `makeTableOptions` (e.g. a schema) will be passed on to
|
|
130
|
+
* that call.
|
|
131
|
+
*
|
|
132
|
+
* The embedding function will be passed a column of values (based on the
|
|
133
|
+
* `sourceColumn` of the embedding function) and expects to receive back
|
|
134
|
+
* number[][] which will be converted into a fixed size list column. By
|
|
135
|
+
* default this will be a fixed size list of Float32 but that can be
|
|
136
|
+
* customized by the `embeddingDataType` property of the embedding function.
|
|
137
|
+
*
|
|
138
|
+
* If a schema is provided in `makeTableOptions` then it should include the
|
|
139
|
+
* embedding columns. If no schema is provded then embedding columns will
|
|
140
|
+
* be placed at the end of the table, after all of the input columns.
|
|
141
|
+
*/
|
|
142
|
+
export declare function convertToTable<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, makeTableOptions?: Partial<MakeArrowTableOptions>): Promise<ArrowTable>;
|
|
143
|
+
/**
|
|
144
|
+
* Serialize an Array of records into a buffer using the Arrow IPC File serialization
|
|
145
|
+
*
|
|
146
|
+
* This function will call `convertToTable` and pass on `embeddings` and `schema`
|
|
147
|
+
*
|
|
148
|
+
* `schema` is required if data is empty
|
|
149
|
+
*/
|
|
150
|
+
export declare function fromRecordsToBuffer<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
|
|
151
|
+
/**
|
|
152
|
+
* Serialize an Array of records into a buffer using the Arrow IPC Stream serialization
|
|
153
|
+
*
|
|
154
|
+
* This function will call `convertToTable` and pass on `embeddings` and `schema`
|
|
155
|
+
*
|
|
156
|
+
* `schema` is required if data is empty
|
|
157
|
+
*/
|
|
158
|
+
export declare function fromRecordsToStreamBuffer<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
|
|
159
|
+
/**
|
|
160
|
+
* Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
|
|
161
|
+
*
|
|
162
|
+
* This function will apply `embeddings` to the table in a manner similar to
|
|
163
|
+
* `convertToTable`.
|
|
164
|
+
*
|
|
165
|
+
* `schema` is required if the table is empty
|
|
166
|
+
*/
|
|
167
|
+
export declare function fromTableToBuffer<T>(table: ArrowTable, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
|
|
168
|
+
/**
|
|
169
|
+
* Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
|
|
170
|
+
*
|
|
171
|
+
* This function will apply `embeddings` to the table in a manner similar to
|
|
172
|
+
* `convertToTable`.
|
|
173
|
+
*
|
|
174
|
+
* `schema` is required if the table is empty
|
|
175
|
+
*/
|
|
176
|
+
export declare function fromDataToBuffer<T>(data: Data, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
|
|
177
|
+
/**
|
|
178
|
+
* Serialize an Arrow Table into a buffer using the Arrow IPC Stream serialization
|
|
179
|
+
*
|
|
180
|
+
* This function will apply `embeddings` to the table in a manner similar to
|
|
181
|
+
* `convertToTable`.
|
|
182
|
+
*
|
|
183
|
+
* `schema` is required if the table is empty
|
|
184
|
+
*/
|
|
185
|
+
export declare function fromTableToStreamBuffer<T>(table: ArrowTable, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
|
|
186
|
+
/**
|
|
187
|
+
* Create an empty table with the given schema
|
|
188
|
+
*/
|
|
189
|
+
export declare function createEmptyTable(schema: Schema): ArrowTable;
|