@lancedb/lancedb 0.5.1 → 0.7.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.
Files changed (91) hide show
  1. package/Cargo.toml +3 -3
  2. package/biome.json +19 -3
  3. package/dist/arrow.d.ts +42 -7
  4. package/dist/arrow.js +6 -5
  5. package/dist/connection.d.ts +55 -29
  6. package/dist/connection.js +22 -74
  7. package/dist/embedding/embedding_function.d.ts +11 -3
  8. package/dist/embedding/embedding_function.js +36 -12
  9. package/dist/embedding/openai.d.ts +6 -5
  10. package/dist/embedding/openai.js +4 -2
  11. package/dist/embedding/registry.d.ts +10 -11
  12. package/dist/embedding/registry.js +4 -0
  13. package/dist/index.d.ts +51 -3
  14. package/dist/index.js +28 -4
  15. package/dist/merge.d.ts +54 -0
  16. package/dist/merge.js +64 -0
  17. package/dist/native.d.ts +34 -7
  18. package/dist/native.js +26 -9
  19. package/dist/query.d.ts +51 -16
  20. package/dist/query.js +122 -21
  21. package/dist/remote/client.d.ts +28 -0
  22. package/dist/remote/client.js +172 -0
  23. package/dist/remote/connection.d.ts +25 -0
  24. package/dist/remote/connection.js +110 -0
  25. package/dist/remote/index.d.ts +3 -0
  26. package/dist/remote/index.js +9 -0
  27. package/dist/remote/table.d.ts +42 -0
  28. package/dist/remote/table.js +179 -0
  29. package/dist/sanitize.d.ts +3 -2
  30. package/dist/sanitize.js +55 -1
  31. package/dist/table.d.ts +116 -25
  32. package/dist/table.js +117 -233
  33. package/dist/util.d.ts +14 -0
  34. package/dist/util.js +65 -0
  35. package/examples/ann_indexes.ts +49 -0
  36. package/examples/basic.ts +149 -0
  37. package/examples/embedding.ts +83 -0
  38. package/examples/filtering.ts +34 -0
  39. package/examples/jsconfig.json +27 -0
  40. package/examples/package-lock.json +79 -0
  41. package/examples/package.json +18 -0
  42. package/examples/search.ts +37 -0
  43. package/lancedb/arrow.ts +87 -24
  44. package/lancedb/connection.ts +115 -92
  45. package/lancedb/embedding/embedding_function.ts +48 -16
  46. package/lancedb/embedding/openai.ts +11 -6
  47. package/lancedb/embedding/registry.ts +38 -22
  48. package/lancedb/index.ts +101 -2
  49. package/lancedb/merge.ts +70 -0
  50. package/lancedb/query.ts +168 -39
  51. package/lancedb/remote/client.ts +221 -0
  52. package/lancedb/remote/connection.ts +201 -0
  53. package/lancedb/remote/index.ts +3 -0
  54. package/lancedb/remote/table.ts +226 -0
  55. package/lancedb/sanitize.ts +73 -1
  56. package/lancedb/table.ts +344 -101
  57. package/lancedb/util.ts +69 -0
  58. package/native.d.ts +208 -0
  59. package/nodejs-artifacts/arrow.d.ts +42 -7
  60. package/nodejs-artifacts/arrow.js +6 -5
  61. package/nodejs-artifacts/connection.d.ts +55 -29
  62. package/nodejs-artifacts/connection.js +22 -74
  63. package/nodejs-artifacts/embedding/embedding_function.d.ts +11 -3
  64. package/nodejs-artifacts/embedding/embedding_function.js +36 -12
  65. package/nodejs-artifacts/embedding/openai.d.ts +6 -5
  66. package/nodejs-artifacts/embedding/openai.js +4 -2
  67. package/nodejs-artifacts/embedding/registry.d.ts +10 -11
  68. package/nodejs-artifacts/embedding/registry.js +4 -0
  69. package/nodejs-artifacts/index.d.ts +51 -3
  70. package/nodejs-artifacts/index.js +28 -4
  71. package/nodejs-artifacts/merge.d.ts +54 -0
  72. package/nodejs-artifacts/merge.js +64 -0
  73. package/nodejs-artifacts/native.d.ts +34 -7
  74. package/nodejs-artifacts/native.js +26 -9
  75. package/nodejs-artifacts/query.d.ts +51 -16
  76. package/nodejs-artifacts/query.js +122 -21
  77. package/nodejs-artifacts/remote/client.d.ts +28 -0
  78. package/nodejs-artifacts/remote/client.js +172 -0
  79. package/nodejs-artifacts/remote/connection.d.ts +25 -0
  80. package/nodejs-artifacts/remote/connection.js +110 -0
  81. package/nodejs-artifacts/remote/index.d.ts +3 -0
  82. package/nodejs-artifacts/remote/index.js +9 -0
  83. package/nodejs-artifacts/remote/table.d.ts +42 -0
  84. package/nodejs-artifacts/remote/table.js +179 -0
  85. package/nodejs-artifacts/sanitize.d.ts +3 -2
  86. package/nodejs-artifacts/sanitize.js +55 -1
  87. package/nodejs-artifacts/table.d.ts +116 -25
  88. package/nodejs-artifacts/table.js +117 -233
  89. package/nodejs-artifacts/util.d.ts +14 -0
  90. package/nodejs-artifacts/util.js +65 -0
  91. package/package.json +25 -11
@@ -1,7 +1,11 @@
1
- import { Data, Schema } from "./arrow";
1
+ /// <reference types="node" />
2
+ import { Table as ArrowTable, Data, IntoVector, Schema, TableLike } from "./arrow";
3
+ import { CreateTableOptions } from "./connection";
2
4
  import { IndexOptions } from "./indices";
3
- import { AddColumnsSql, ColumnAlteration, IndexConfig, OptimizeStats, Table as _NativeTable } from "./native";
5
+ import { MergeInsertBuilder } from "./merge";
6
+ import { AddColumnsSql, ColumnAlteration, IndexConfig, IndexStatistics, OptimizeStats, Table as _NativeTable } from "./native";
4
7
  import { Query, VectorQuery } from "./query";
8
+ import { IntoSql } from "./util";
5
9
  export { IndexConfig } from "./native";
6
10
  /**
7
11
  * Options for adding data to a table.
@@ -55,12 +59,11 @@ export interface OptimizeOptions {
55
59
  * Closing a table is optional. It not closed, it will be closed when it is garbage
56
60
  * collected.
57
61
  */
58
- export declare class Table {
59
- private readonly inner;
60
- /** Construct a Table. Internal use only. */
61
- constructor(inner: _NativeTable);
62
+ export declare abstract class Table {
63
+ /** Returns the name of the table */
64
+ abstract get name(): string;
62
65
  /** Return true if the table has not been closed */
63
- isOpen(): boolean;
66
+ abstract isOpen(): boolean;
64
67
  /**
65
68
  * Close the table, releasing any underlying resources.
66
69
  *
@@ -68,16 +71,40 @@ export declare class Table {
68
71
  *
69
72
  * Any attempt to use the table after it is closed will result in an error.
70
73
  */
71
- close(): void;
74
+ abstract close(): void;
72
75
  /** Return a brief description of the table */
73
- display(): string;
76
+ abstract display(): string;
74
77
  /** Get the schema of the table. */
75
- schema(): Promise<Schema>;
78
+ abstract schema(): Promise<Schema>;
76
79
  /**
77
80
  * Insert records into this Table.
78
81
  * @param {Data} data Records to be inserted into the Table
79
82
  */
80
- add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
83
+ abstract add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
84
+ /**
85
+ * Update existing records in the Table
86
+ * @param opts.values The values to update. The keys are the column names and the values
87
+ * are the values to set.
88
+ * @example
89
+ * ```ts
90
+ * table.update({where:"x = 2", values:{"vector": [10, 10]}})
91
+ * ```
92
+ */
93
+ abstract update(opts: {
94
+ values: Map<string, IntoSql> | Record<string, IntoSql>;
95
+ } & Partial<UpdateOptions>): Promise<void>;
96
+ /**
97
+ * Update existing records in the Table
98
+ * @param opts.valuesSql The values to update. The keys are the column names and the values
99
+ * are the values to set. The values are SQL expressions.
100
+ * @example
101
+ * ```ts
102
+ * table.update({where:"x = 2", valuesSql:{"x": "x + 1"}})
103
+ * ```
104
+ */
105
+ abstract update(opts: {
106
+ valuesSql: Map<string, string> | Record<string, string>;
107
+ } & Partial<UpdateOptions>): Promise<void>;
81
108
  /**
82
109
  * Update existing records in the Table
83
110
  *
@@ -103,11 +130,11 @@ export declare class Table {
103
130
  * @param {Partial<UpdateOptions>} options - additional options to control
104
131
  * the update behavior
105
132
  */
106
- update(updates: Map<string, string> | Record<string, string>, options?: Partial<UpdateOptions>): Promise<void>;
133
+ abstract update(updates: Map<string, string> | Record<string, string>, options?: Partial<UpdateOptions>): Promise<void>;
107
134
  /** Count the total number of rows in the dataset. */
108
- countRows(filter?: string): Promise<number>;
135
+ abstract countRows(filter?: string): Promise<number>;
109
136
  /** Delete the rows that satisfy the predicate. */
110
- delete(predicate: string): Promise<void>;
137
+ abstract delete(predicate: string): Promise<void>;
111
138
  /**
112
139
  * Create an index to speed up queries.
113
140
  *
@@ -115,6 +142,9 @@ export declare class Table {
115
142
  * Indices on vector columns will speed up vector searches.
116
143
  * Indices on scalar columns will speed up filtering (in both
117
144
  * vector and non-vector searches)
145
+ *
146
+ * @note We currently don't support custom named indexes,
147
+ * The index name will always be `${column}_idx`
118
148
  * @example
119
149
  * // If the column has a vector (fixed size list) data type then
120
150
  * // an IvfPq vector index will be created.
@@ -134,7 +164,7 @@ export declare class Table {
134
164
  * // Or create a Scalar index
135
165
  * await table.createIndex("my_float_col");
136
166
  */
137
- createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
167
+ abstract createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
138
168
  /**
139
169
  * Create a {@link Query} Builder.
140
170
  *
@@ -185,7 +215,20 @@ export declare class Table {
185
215
  * }
186
216
  * @returns {Query} A builder that can be used to parameterize the query
187
217
  */
188
- query(): Query;
218
+ abstract query(): Query;
219
+ /**
220
+ * Create a search query to find the nearest neighbors
221
+ * of the given query vector
222
+ * @param {string} query - the query. This will be converted to a vector using the table's provided embedding function
223
+ * @note If no embedding functions are defined in the table, this will error when collecting the results.
224
+ */
225
+ abstract search(query: string): VectorQuery;
226
+ /**
227
+ * Create a search query to find the nearest neighbors
228
+ * of the given query vector
229
+ * @param {IntoVector} query - the query vector
230
+ */
231
+ abstract search(query: IntoVector): VectorQuery;
189
232
  /**
190
233
  * Search the table with a given query vector.
191
234
  *
@@ -193,7 +236,7 @@ export declare class Table {
193
236
  * is the same thing as calling `nearestTo` on the builder returned
194
237
  * by `query`. @see {@link Query#nearestTo} for more details.
195
238
  */
196
- vectorSearch(vector: unknown): VectorQuery;
239
+ abstract vectorSearch(vector: IntoVector): VectorQuery;
197
240
  /**
198
241
  * Add new columns with defined values.
199
242
  * @param {AddColumnsSql[]} newColumnTransforms pairs of column names and
@@ -201,13 +244,13 @@ export declare class Table {
201
244
  * expressions will be evaluated for each row in the table, and can
202
245
  * reference existing columns in the table.
203
246
  */
204
- addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
247
+ abstract addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
205
248
  /**
206
249
  * Alter the name or nullability of columns.
207
250
  * @param {ColumnAlteration[]} columnAlterations One or more alterations to
208
251
  * apply to columns.
209
252
  */
210
- alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
253
+ abstract alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
211
254
  /**
212
255
  * Drop one or more columns from the dataset
213
256
  *
@@ -219,9 +262,9 @@ export declare class Table {
219
262
  * be nested column references (e.g. "a.b.c") or top-level column names
220
263
  * (e.g. "a").
221
264
  */
222
- dropColumns(columnNames: string[]): Promise<void>;
265
+ abstract dropColumns(columnNames: string[]): Promise<void>;
223
266
  /** Retrieve the version of the table */
224
- version(): Promise<number>;
267
+ abstract version(): Promise<number>;
225
268
  /**
226
269
  * Checks out a specific version of the table _This is an in-place operation._
227
270
  *
@@ -247,14 +290,14 @@ export declare class Table {
247
290
  * console.log(await table.version()); // 2
248
291
  * ```
249
292
  */
250
- checkout(version: number): Promise<void>;
293
+ abstract checkout(version: number): Promise<void>;
251
294
  /**
252
295
  * Checkout the latest version of the table. _This is an in-place operation._
253
296
  *
254
297
  * The table will be set back into standard mode, and will track the latest
255
298
  * version of the table.
256
299
  */
257
- checkoutLatest(): Promise<void>;
300
+ abstract checkoutLatest(): Promise<void>;
258
301
  /**
259
302
  * Restore the table to the currently checked out version
260
303
  *
@@ -267,7 +310,7 @@ export declare class Table {
267
310
  * Once the operation concludes the table will no longer be in a checked
268
311
  * out state and the read_consistency_interval, if any, will apply.
269
312
  */
270
- restore(): Promise<void>;
313
+ abstract restore(): Promise<void>;
271
314
  /**
272
315
  * Optimize the on-disk data and indices for better performance.
273
316
  *
@@ -298,7 +341,55 @@ export declare class Table {
298
341
  * you have added or modified 100,000 or more records or run more than 20 data
299
342
  * modification operations.
300
343
  */
301
- optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
344
+ abstract optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
302
345
  /** List all indices that have been created with {@link Table.createIndex} */
346
+ abstract listIndices(): Promise<IndexConfig[]>;
347
+ /** Return the table as an arrow table */
348
+ abstract toArrow(): Promise<ArrowTable>;
349
+ abstract mergeInsert(on: string | string[]): MergeInsertBuilder;
350
+ /** List all the stats of a specified index
351
+ *
352
+ * @param {string} name The name of the index.
353
+ * @returns {IndexStatistics | undefined} The stats of the index. If the index does not exist, it will return undefined
354
+ */
355
+ abstract indexStats(name: string): Promise<IndexStatistics | undefined>;
356
+ static parseTableData(data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>, streaming?: boolean): Promise<{
357
+ buf: Buffer;
358
+ mode: string;
359
+ }>;
360
+ }
361
+ export declare class LocalTable extends Table {
362
+ private readonly inner;
363
+ constructor(inner: _NativeTable);
364
+ get name(): string;
365
+ isOpen(): boolean;
366
+ close(): void;
367
+ display(): string;
368
+ private getEmbeddingFunctions;
369
+ /** Get the schema of the table. */
370
+ schema(): Promise<Schema>;
371
+ add(data: Data, options?: Partial<AddDataOptions>): Promise<void>;
372
+ update(optsOrUpdates: (Map<string, string> | Record<string, string>) | ({
373
+ values: Map<string, IntoSql> | Record<string, IntoSql>;
374
+ } & Partial<UpdateOptions>) | ({
375
+ valuesSql: Map<string, string> | Record<string, string>;
376
+ } & Partial<UpdateOptions>), options?: Partial<UpdateOptions>): Promise<void>;
377
+ countRows(filter?: string): Promise<number>;
378
+ delete(predicate: string): Promise<void>;
379
+ createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
380
+ query(): Query;
381
+ search(query: string | IntoVector): VectorQuery;
382
+ vectorSearch(vector: IntoVector): VectorQuery;
383
+ addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
384
+ alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
385
+ dropColumns(columnNames: string[]): Promise<void>;
386
+ version(): Promise<number>;
387
+ checkout(version: number): Promise<void>;
388
+ checkoutLatest(): Promise<void>;
389
+ restore(): Promise<void>;
390
+ optimize(options?: Partial<OptimizeOptions>): Promise<OptimizeStats>;
303
391
  listIndices(): Promise<IndexConfig[]>;
392
+ toArrow(): Promise<ArrowTable>;
393
+ indexStats(name: string): Promise<IndexStatistics | undefined>;
394
+ mergeInsert(on: string | string[]): MergeInsertBuilder;
304
395
  }