Elffuss BraidHub

kikocis/lancedb public

main · 19.0 KiBRenderedRawPermalink
1[vectordb](../README.md) / [Exports](../modules.md) / LocalTable
2
3# Class: LocalTable\<T\>
4
5A LanceDB Table is the collection of Records. Each Record has one or more vector fields.
6
7## Type parameters
8
9| Name | Type |
10| :------ | :------ |
11| `T` | `number`[] |
12
13## Implements
14
15- [`Table`](../interfaces/Table.md)\<`T`\>
16
17## Table of contents
18
19### Constructors
20
21- [constructor](LocalTable.md#constructor)
22
23### Properties
24
25- [\_embeddings](LocalTable.md#_embeddings)
26- [\_isElectron](LocalTable.md#_iselectron)
27- [\_name](LocalTable.md#_name)
28- [\_options](LocalTable.md#_options)
29- [\_tbl](LocalTable.md#_tbl)
30- [where](LocalTable.md#where)
31
32### Accessors
33
34- [name](LocalTable.md#name)
35- [schema](LocalTable.md#schema)
36
37### Methods
38
39- [add](LocalTable.md#add)
40- [addColumns](LocalTable.md#addcolumns)
41- [alterColumns](LocalTable.md#altercolumns)
42- [checkElectron](LocalTable.md#checkelectron)
43- [cleanupOldVersions](LocalTable.md#cleanupoldversions)
44- [compactFiles](LocalTable.md#compactfiles)
45- [countRows](LocalTable.md#countrows)
46- [createIndex](LocalTable.md#createindex)
47- [createScalarIndex](LocalTable.md#createscalarindex)
48- [delete](LocalTable.md#delete)
49- [dropColumns](LocalTable.md#dropcolumns)
50- [filter](LocalTable.md#filter)
51- [getSchema](LocalTable.md#getschema)
52- [indexStats](LocalTable.md#indexstats)
53- [listIndices](LocalTable.md#listindices)
54- [mergeInsert](LocalTable.md#mergeinsert)
55- [overwrite](LocalTable.md#overwrite)
56- [search](LocalTable.md#search)
57- [update](LocalTable.md#update)
58- [withMiddleware](LocalTable.md#withmiddleware)
59
60## Constructors
61
62### constructor
63
64• **new LocalTable**\<`T`\>(`tbl`, `name`, `options`)
65
66#### Type parameters
67
68| Name | Type |
69| :------ | :------ |
70| `T` | `number`[] |
71
72#### Parameters
73
74| Name | Type |
75| :------ | :------ |
76| `tbl` | `any` |
77| `name` | `string` |
78| `options` | [`ConnectionOptions`](../interfaces/ConnectionOptions.md) |
79
80#### Defined in
81
82[index.ts:892](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L892)
83
84• **new LocalTable**\<`T`\>(`tbl`, `name`, `options`, `embeddings`)
85
86#### Type parameters
87
88| Name | Type |
89| :------ | :------ |
90| `T` | `number`[] |
91
92#### Parameters
93
94| Name | Type | Description |
95| :------ | :------ | :------ |
96| `tbl` | `any` | |
97| `name` | `string` | |
98| `options` | [`ConnectionOptions`](../interfaces/ConnectionOptions.md) | |
99| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> | An embedding function to use when interacting with this table |
100
101#### Defined in
102
103[index.ts:899](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L899)
104
105## Properties
106
107### \_embeddings
108
109• `Private` `Optional` `Readonly` **\_embeddings**: [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\>
110
111#### Defined in
112
113[index.ts:889](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L889)
114
115___
116
117### \_isElectron
118
119• `Private` `Readonly` **\_isElectron**: `boolean`
120
121#### Defined in
122
123[index.ts:888](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L888)
124
125___
126
127### \_name
128
129• `Private` `Readonly` **\_name**: `string`
130
131#### Defined in
132
133[index.ts:887](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L887)
134
135___
136
137### \_options
138
139• `Private` `Readonly` **\_options**: () => [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
140
141#### Type declaration
142
143▸ (): [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
144
145##### Returns
146
147[`ConnectionOptions`](../interfaces/ConnectionOptions.md)
148
149#### Defined in
150
151[index.ts:890](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L890)
152
153___
154
155### \_tbl
156
157• `Private` **\_tbl**: `any`
158
159#### Defined in
160
161[index.ts:886](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L886)
162
163___
164
165### where
166
167• **where**: (`value`: `string`) => [`Query`](Query.md)\<`T`\>
168
169#### Type declaration
170
171▸ (`value`): [`Query`](Query.md)\<`T`\>
172
173Creates a filter query to find all rows matching the specified criteria
174
175##### Parameters
176
177| Name | Type | Description |
178| :------ | :------ | :------ |
179| `value` | `string` | The filter criteria (like SQL where clause syntax) |
180
181##### Returns
182
183[`Query`](Query.md)\<`T`\>
184
185#### Defined in
186
187[index.ts:938](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L938)
188
189## Accessors
190
191### name
192
193• `get` **name**(): `string`
194
195#### Returns
196
197`string`
198
199#### Implementation of
200
201[Table](../interfaces/Table.md).[name](../interfaces/Table.md#name)
202
203#### Defined in
204
205[index.ts:918](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L918)
206
207___
208
209### schema
210
211• `get` **schema**(): `Promise`\<`Schema`\<`any`\>\>
212
213#### Returns
214
215`Promise`\<`Schema`\<`any`\>\>
216
217#### Implementation of
218
219[Table](../interfaces/Table.md).[schema](../interfaces/Table.md#schema)
220
221#### Defined in
222
223[index.ts:1171](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1171)
224
225## Methods
226
227### add
228
229▸ **add**(`data`): `Promise`\<`number`\>
230
231Insert records into this Table.
232
233#### Parameters
234
235| Name | Type | Description |
236| :------ | :------ | :------ |
237| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
238
239#### Returns
240
241`Promise`\<`number`\>
242
243The number of rows added to the table
244
245#### Implementation of
246
247[Table](../interfaces/Table.md).[add](../interfaces/Table.md#add)
248
249#### Defined in
250
251[index.ts:946](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L946)
252
253___
254
255### addColumns
256
257▸ **addColumns**(`newColumnTransforms`): `Promise`\<`void`\>
258
259Add new columns with defined values.
260
261#### Parameters
262
263| Name | Type | Description |
264| :------ | :------ | :------ |
265| `newColumnTransforms` | \{ `name`: `string` ; `valueSql`: `string` }[] | pairs of column names and the SQL expression to use to calculate the value of the new column. These expressions will be evaluated for each row in the table, and can reference existing columns in the table. |
266
267#### Returns
268
269`Promise`\<`void`\>
270
271#### Implementation of
272
273[Table](../interfaces/Table.md).[addColumns](../interfaces/Table.md#addcolumns)
274
275#### Defined in
276
277[index.ts:1195](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1195)
278
279___
280
281### alterColumns
282
283▸ **alterColumns**(`columnAlterations`): `Promise`\<`void`\>
284
285Alter the name or nullability of columns.
286
287#### Parameters
288
289| Name | Type | Description |
290| :------ | :------ | :------ |
291| `columnAlterations` | [`ColumnAlteration`](../interfaces/ColumnAlteration.md)[] | One or more alterations to apply to columns. |
292
293#### Returns
294
295`Promise`\<`void`\>
296
297#### Implementation of
298
299[Table](../interfaces/Table.md).[alterColumns](../interfaces/Table.md#altercolumns)
300
301#### Defined in
302
303[index.ts:1201](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1201)
304
305___
306
307### checkElectron
308
309▸ `Private` **checkElectron**(): `boolean`
310
311#### Returns
312
313`boolean`
314
315#### Defined in
316
317[index.ts:1183](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1183)
318
319___
320
321### cleanupOldVersions
322
323▸ **cleanupOldVersions**(`olderThan?`, `deleteUnverified?`): `Promise`\<[`CleanupStats`](../interfaces/CleanupStats.md)\>
324
325Clean up old versions of the table, freeing disk space.
326
327#### Parameters
328
329| Name | Type | Description |
330| :------ | :------ | :------ |
331| `olderThan?` | `number` | The minimum age in minutes of the versions to delete. If not provided, defaults to two weeks. |
332| `deleteUnverified?` | `boolean` | Because they may be part of an in-progress transaction, uncommitted files newer than 7 days old are not deleted by default. This means that failed transactions can leave around data that takes up disk space for up to 7 days. You can override this safety mechanism by setting this option to `true`, only if you promise there are no in progress writes while you run this operation. Failure to uphold this promise can lead to corrupted tables. |
333
334#### Returns
335
336`Promise`\<[`CleanupStats`](../interfaces/CleanupStats.md)\>
337
338#### Defined in
339
340[index.ts:1130](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1130)
341
342___
343
344### compactFiles
345
346▸ **compactFiles**(`options?`): `Promise`\<[`CompactionMetrics`](../interfaces/CompactionMetrics.md)\>
347
348Run the compaction process on the table.
349
350This can be run after making several small appends to optimize the table
351for faster reads.
352
353#### Parameters
354
355| Name | Type | Description |
356| :------ | :------ | :------ |
357| `options?` | [`CompactionOptions`](../interfaces/CompactionOptions.md) | Advanced options configuring compaction. In most cases, you can omit this arguments, as the default options are sensible for most tables. |
358
359#### Returns
360
361`Promise`\<[`CompactionMetrics`](../interfaces/CompactionMetrics.md)\>
362
363Metrics about the compaction operation.
364
365#### Defined in
366
367[index.ts:1153](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1153)
368
369___
370
371### countRows
372
373▸ **countRows**(`filter?`): `Promise`\<`number`\>
374
375Returns the number of rows in this table.
376
377#### Parameters
378
379| Name | Type |
380| :------ | :------ |
381| `filter?` | `string` |
382
383#### Returns
384
385`Promise`\<`number`\>
386
387#### Implementation of
388
389[Table](../interfaces/Table.md).[countRows](../interfaces/Table.md#countrows)
390
391#### Defined in
392
393[index.ts:1021](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1021)
394
395___
396
397### createIndex
398
399▸ **createIndex**(`indexParams`): `Promise`\<`any`\>
400
401Create an ANN index on this Table vector index.
402
403#### Parameters
404
405| Name | Type | Description |
406| :------ | :------ | :------ |
407| `indexParams` | [`IvfPQIndexConfig`](../interfaces/IvfPQIndexConfig.md) | The parameters of this Index, |
408
409#### Returns
410
411`Promise`\<`any`\>
412
413**`See`**
414
415VectorIndexParams.
416
417#### Implementation of
418
419[Table](../interfaces/Table.md).[createIndex](../interfaces/Table.md#createindex)
420
421#### Defined in
422
423[index.ts:1003](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1003)
424
425___
426
427### createScalarIndex
428
429▸ **createScalarIndex**(`column`, `replace?`): `Promise`\<`void`\>
430
431Create a scalar index on this Table for the given column
432
433#### Parameters
434
435| Name | Type | Description |
436| :------ | :------ | :------ |
437| `column` | `string` | The column to index |
438| `replace?` | `boolean` | If false, fail if an index already exists on the column it is always set to true for remote connections Scalar indices, like vector indices, can be used to speed up scans. A scalar index can speed up scans that contain filter expressions on the indexed column. For example, the following scan will be faster if the column `my_col` has a scalar index: ```ts const con = await lancedb.connect('./.lancedb'); const table = await con.openTable('images'); const results = await table.where('my_col = 7').execute(); ``` Scalar indices can also speed up scans containing a vector search and a prefilter: ```ts const con = await lancedb.connect('././lancedb'); const table = await con.openTable('images'); const results = await table.search([1.0, 2.0]).where('my_col != 7').prefilter(true); ``` Scalar indices can only speed up scans for basic filters using equality, comparison, range (e.g. `my_col BETWEEN 0 AND 100`), and set membership (e.g. `my_col IN (0, 1, 2)`) Scalar indices can be used if the filter contains multiple indexed columns and the filter criteria are AND'd or OR'd together (e.g. `my_col < 0 AND other_col> 100`) Scalar indices may be used if the filter contains non-indexed columns but, depending on the structure of the filter, they may not be usable. For example, if the column `not_indexed` does not have a scalar index then the filter `my_col = 0 OR not_indexed = 1` will not be able to use any scalar index on `my_col`. |
439
440#### Returns
441
442`Promise`\<`void`\>
443
444**`Examples`**
445
446```ts
447const con = await lancedb.connect('././lancedb')
448const table = await con.openTable('images')
449await table.createScalarIndex('my_col')
450```
451
452#### Implementation of
453
454[Table](../interfaces/Table.md).[createScalarIndex](../interfaces/Table.md#createscalarindex)
455
456#### Defined in
457
458[index.ts:1011](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1011)
459
460___
461
462### delete
463
464▸ **delete**(`filter`): `Promise`\<`void`\>
465
466Delete rows from this table.
467
468#### Parameters
469
470| Name | Type | Description |
471| :------ | :------ | :------ |
472| `filter` | `string` | A filter in the same format used by a sql WHERE clause. |
473
474#### Returns
475
476`Promise`\<`void`\>
477
478#### Implementation of
479
480[Table](../interfaces/Table.md).[delete](../interfaces/Table.md#delete)
481
482#### Defined in
483
484[index.ts:1030](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1030)
485
486___
487
488### dropColumns
489
490▸ **dropColumns**(`columnNames`): `Promise`\<`void`\>
491
492Drop one or more columns from the dataset
493
494This is a metadata-only operation and does not remove the data from the
495underlying storage. In order to remove the data, you must subsequently
496call ``compact_files`` to rewrite the data without the removed columns and
497then call ``cleanup_files`` to remove the old files.
498
499#### Parameters
500
501| Name | Type | Description |
502| :------ | :------ | :------ |
503| `columnNames` | `string`[] | The names of the columns to drop. These can be nested column references (e.g. "a.b.c") or top-level column names (e.g. "a"). |
504
505#### Returns
506
507`Promise`\<`void`\>
508
509#### Implementation of
510
511[Table](../interfaces/Table.md).[dropColumns](../interfaces/Table.md#dropcolumns)
512
513#### Defined in
514
515[index.ts:1205](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1205)
516
517___
518
519### filter
520
521▸ **filter**(`value`): [`Query`](Query.md)\<`T`\>
522
523Creates a filter query to find all rows matching the specified criteria
524
525#### Parameters
526
527| Name | Type | Description |
528| :------ | :------ | :------ |
529| `value` | `string` | The filter criteria (like SQL where clause syntax) |
530
531#### Returns
532
533[`Query`](Query.md)\<`T`\>
534
535#### Implementation of
536
537[Table](../interfaces/Table.md).[filter](../interfaces/Table.md#filter)
538
539#### Defined in
540
541[index.ts:934](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L934)
542
543___
544
545### getSchema
546
547▸ `Private` **getSchema**(): `Promise`\<`Schema`\<`any`\>\>
548
549#### Returns
550
551`Promise`\<`Schema`\<`any`\>\>
552
553#### Defined in
554
555[index.ts:1176](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1176)
556
557___
558
559### indexStats
560
561▸ **indexStats**(`indexName`): `Promise`\<[`IndexStats`](../interfaces/IndexStats.md)\>
562
563Get statistics about an index.
564
565#### Parameters
566
567| Name | Type |
568| :------ | :------ |
569| `indexName` | `string` |
570
571#### Returns
572
573`Promise`\<[`IndexStats`](../interfaces/IndexStats.md)\>
574
575#### Implementation of
576
577[Table](../interfaces/Table.md).[indexStats](../interfaces/Table.md#indexstats)
578
579#### Defined in
580
581[index.ts:1167](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1167)
582
583___
584
585### listIndices
586
587▸ **listIndices**(): `Promise`\<[`VectorIndex`](../interfaces/VectorIndex.md)[]\>
588
589List the indicies on this table.
590
591#### Returns
592
593`Promise`\<[`VectorIndex`](../interfaces/VectorIndex.md)[]\>
594
595#### Implementation of
596
597[Table](../interfaces/Table.md).[listIndices](../interfaces/Table.md#listindices)
598
599#### Defined in
600
601[index.ts:1163](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1163)
602
603___
604
605### mergeInsert
606
607▸ **mergeInsert**(`on`, `data`, `args`): `Promise`\<`void`\>
608
609Runs a "merge insert" operation on the table
610
611This operation can add rows, update rows, and remove rows all in a single
612transaction. It is a very generic tool that can be used to create
613behaviors like "insert if not exists", "update or insert (i.e. upsert)",
614or even replace a portion of existing data with new data (e.g. replace
615all data where month="january")
616
617The merge insert operation works by combining new data from a
618**source table** with existing data in a **target table** by using a
619join. There are three categories of records.
620
621"Matched" records are records that exist in both the source table and
622the target table. "Not matched" records exist only in the source table
623(e.g. these are new data) "Not matched by source" records exist only
624in the target table (this is old data)
625
626The MergeInsertArgs can be used to customize what should happen for
627each category of data.
628
629Please note that the data may appear to be reordered as part of this
630operation. This is because updated rows will be deleted from the
631dataset and then reinserted at the end with the new values.
632
633#### Parameters
634
635| Name | Type | Description |
636| :------ | :------ | :------ |
637| `on` | `string` | a column to join on. This is how records from the source table and target table are matched. |
638| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | the new data to insert |
639| `args` | [`MergeInsertArgs`](../interfaces/MergeInsertArgs.md) | parameters controlling how the operation should behave |
640
641#### Returns
642
643`Promise`\<`void`\>
644
645#### Implementation of
646
647[Table](../interfaces/Table.md).[mergeInsert](../interfaces/Table.md#mergeinsert)
648
649#### Defined in
650
651[index.ts:1065](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1065)
652
653___
654
655### overwrite
656
657▸ **overwrite**(`data`): `Promise`\<`number`\>
658
659Insert records into this Table, replacing its contents.
660
661#### Parameters
662
663| Name | Type | Description |
664| :------ | :------ | :------ |
665| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
666
667#### Returns
668
669`Promise`\<`number`\>
670
671The number of rows added to the table
672
673#### Implementation of
674
675[Table](../interfaces/Table.md).[overwrite](../interfaces/Table.md#overwrite)
676
677#### Defined in
678
679[index.ts:977](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L977)
680
681___
682
683### search
684
685▸ **search**(`query`): [`Query`](Query.md)\<`T`\>
686
687Creates a search query to find the nearest neighbors of the given search term
688
689#### Parameters
690
691| Name | Type | Description |
692| :------ | :------ | :------ |
693| `query` | `T` | The query search term |
694
695#### Returns
696
697[`Query`](Query.md)\<`T`\>
698
699#### Implementation of
700
701[Table](../interfaces/Table.md).[search](../interfaces/Table.md#search)
702
703#### Defined in
704
705[index.ts:926](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L926)
706
707___
708
709### update
710
711▸ **update**(`args`): `Promise`\<`void`\>
712
713Update rows in this table.
714
715#### Parameters
716
717| Name | Type | Description |
718| :------ | :------ | :------ |
719| `args` | [`UpdateArgs`](../interfaces/UpdateArgs.md) \| [`UpdateSqlArgs`](../interfaces/UpdateSqlArgs.md) | see [UpdateArgs](../interfaces/UpdateArgs.md) and [UpdateSqlArgs](../interfaces/UpdateSqlArgs.md) for more details |
720
721#### Returns
722
723`Promise`\<`void`\>
724
725#### Implementation of
726
727[Table](../interfaces/Table.md).[update](../interfaces/Table.md#update)
728
729#### Defined in
730
731[index.ts:1043](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1043)
732
733___
734
735### withMiddleware
736
737▸ **withMiddleware**(`middleware`): [`Table`](../interfaces/Table.md)\<`T`\>
738
739Instrument the behavior of this Table with middleware.
740
741The middleware will be called in the order they are added.
742
743Currently this functionality is only supported for remote tables.
744
745#### Parameters
746
747| Name | Type |
748| :------ | :------ |
749| `middleware` | `HttpMiddleware` |
750
751#### Returns
752
753[`Table`](../interfaces/Table.md)\<`T`\>
754
755- this Table instrumented by the passed middleware
756
757#### Implementation of
758
759[Table](../interfaces/Table.md).[withMiddleware](../interfaces/Table.md#withmiddleware)
760
761#### Defined in
762
763[index.ts:1209](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L1209)