Elffuss BraidHub

kikocis/lancedb public

main · 13.7 KiBRenderedRawPermalink
1[vectordb](../README.md) / [Exports](../modules.md) / Table
2
3# Interface: Table\<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## Implemented by
14
15- [`LocalTable`](../classes/LocalTable.md)
16
17## Table of contents
18
19### Properties
20
21- [add](Table.md#add)
22- [countRows](Table.md#countrows)
23- [createIndex](Table.md#createindex)
24- [createScalarIndex](Table.md#createscalarindex)
25- [delete](Table.md#delete)
26- [indexStats](Table.md#indexstats)
27- [listIndices](Table.md#listindices)
28- [mergeInsert](Table.md#mergeinsert)
29- [name](Table.md#name)
30- [overwrite](Table.md#overwrite)
31- [schema](Table.md#schema)
32- [search](Table.md#search)
33- [update](Table.md#update)
34
35### Methods
36
37- [addColumns](Table.md#addcolumns)
38- [alterColumns](Table.md#altercolumns)
39- [dropColumns](Table.md#dropcolumns)
40- [filter](Table.md#filter)
41- [withMiddleware](Table.md#withmiddleware)
42
43## Properties
44
45### add
46
47• **add**: (`data`: `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[]) => `Promise`\<`number`\>
48
49#### Type declaration
50
51▸ (`data`): `Promise`\<`number`\>
52
53Insert records into this Table.
54
55##### Parameters
56
57| Name | Type | Description |
58| :------ | :------ | :------ |
59| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
60
61##### Returns
62
63`Promise`\<`number`\>
64
65The number of rows added to the table
66
67#### Defined in
68
69[index.ts:381](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L381)
70
71___
72
73### countRows
74
75• **countRows**: (`filter?`: `string`) => `Promise`\<`number`\>
76
77#### Type declaration
78
79▸ (`filter?`): `Promise`\<`number`\>
80
81Returns the number of rows in this table.
82
83##### Parameters
84
85| Name | Type |
86| :------ | :------ |
87| `filter?` | `string` |
88
89##### Returns
90
91`Promise`\<`number`\>
92
93#### Defined in
94
95[index.ts:454](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L454)
96
97___
98
99### createIndex
100
101• **createIndex**: (`indexParams`: [`IvfPQIndexConfig`](IvfPQIndexConfig.md)) => `Promise`\<`any`\>
102
103#### Type declaration
104
105▸ (`indexParams`): `Promise`\<`any`\>
106
107Create an ANN index on this Table vector index.
108
109##### Parameters
110
111| Name | Type | Description |
112| :------ | :------ | :------ |
113| `indexParams` | [`IvfPQIndexConfig`](IvfPQIndexConfig.md) | The parameters of this Index, |
114
115##### Returns
116
117`Promise`\<`any`\>
118
119**`See`**
120
121VectorIndexParams.
122
123#### Defined in
124
125[index.ts:398](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L398)
126
127___
128
129### createScalarIndex
130
131• **createScalarIndex**: (`column`: `string`, `replace?`: `boolean`) => `Promise`\<`void`\>
132
133#### Type declaration
134
135▸ (`column`, `replace?`): `Promise`\<`void`\>
136
137Create a scalar index on this Table for the given column
138
139##### Parameters
140
141| Name | Type | Description |
142| :------ | :------ | :------ |
143| `column` | `string` | The column to index |
144| `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`. |
145
146##### Returns
147
148`Promise`\<`void`\>
149
150**`Examples`**
151
152```ts
153const con = await lancedb.connect('././lancedb')
154const table = await con.openTable('images')
155await table.createScalarIndex('my_col')
156```
157
158#### Defined in
159
160[index.ts:449](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L449)
161
162___
163
164### delete
165
166• **delete**: (`filter`: `string`) => `Promise`\<`void`\>
167
168#### Type declaration
169
170▸ (`filter`): `Promise`\<`void`\>
171
172Delete rows from this table.
173
174This can be used to delete a single row, many rows, all rows, or
175sometimes no rows (if your predicate matches nothing).
176
177##### Parameters
178
179| Name | Type | Description |
180| :------ | :------ | :------ |
181| `filter` | `string` | A filter in the same format used by a sql WHERE clause. The filter must not be empty. |
182
183##### Returns
184
185`Promise`\<`void`\>
186
187**`Examples`**
188
189```ts
190const con = await lancedb.connect("./.lancedb")
191const data = [
192 {id: 1, vector: [1, 2]},
193 {id: 2, vector: [3, 4]},
194 {id: 3, vector: [5, 6]},
195];
196const tbl = await con.createTable("my_table", data)
197await tbl.delete("id = 2")
198await tbl.countRows() // Returns 2
199```
200
201If you have a list of values to delete, you can combine them into a
202stringified list and use the `IN` operator:
203
204```ts
205const to_remove = [1, 5];
206await tbl.delete(`id IN (${to_remove.join(",")})`)
207await tbl.countRows() // Returns 1
208```
209
210#### Defined in
211
212[index.ts:488](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L488)
213
214___
215
216### indexStats
217
218• **indexStats**: (`indexName`: `string`) => `Promise`\<[`IndexStats`](IndexStats.md)\>
219
220#### Type declaration
221
222▸ (`indexName`): `Promise`\<[`IndexStats`](IndexStats.md)\>
223
224Get statistics about an index.
225
226##### Parameters
227
228| Name | Type |
229| :------ | :------ |
230| `indexName` | `string` |
231
232##### Returns
233
234`Promise`\<[`IndexStats`](IndexStats.md)\>
235
236#### Defined in
237
238[index.ts:567](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L567)
239
240___
241
242### listIndices
243
244• **listIndices**: () => `Promise`\<[`VectorIndex`](VectorIndex.md)[]\>
245
246#### Type declaration
247
248▸ (): `Promise`\<[`VectorIndex`](VectorIndex.md)[]\>
249
250List the indicies on this table.
251
252##### Returns
253
254`Promise`\<[`VectorIndex`](VectorIndex.md)[]\>
255
256#### Defined in
257
258[index.ts:562](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L562)
259
260___
261
262### mergeInsert
263
264• **mergeInsert**: (`on`: `string`, `data`: `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[], `args`: [`MergeInsertArgs`](MergeInsertArgs.md)) => `Promise`\<`void`\>
265
266#### Type declaration
267
268▸ (`on`, `data`, `args`): `Promise`\<`void`\>
269
270Runs a "merge insert" operation on the table
271
272This operation can add rows, update rows, and remove rows all in a single
273transaction. It is a very generic tool that can be used to create
274behaviors like "insert if not exists", "update or insert (i.e. upsert)",
275or even replace a portion of existing data with new data (e.g. replace
276all data where month="january")
277
278The merge insert operation works by combining new data from a
279**source table** with existing data in a **target table** by using a
280join. There are three categories of records.
281
282"Matched" records are records that exist in both the source table and
283the target table. "Not matched" records exist only in the source table
284(e.g. these are new data) "Not matched by source" records exist only
285in the target table (this is old data)
286
287The MergeInsertArgs can be used to customize what should happen for
288each category of data.
289
290Please note that the data may appear to be reordered as part of this
291operation. This is because updated rows will be deleted from the
292dataset and then reinserted at the end with the new values.
293
294##### Parameters
295
296| Name | Type | Description |
297| :------ | :------ | :------ |
298| `on` | `string` | a column to join on. This is how records from the source table and target table are matched. |
299| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | the new data to insert |
300| `args` | [`MergeInsertArgs`](MergeInsertArgs.md) | parameters controlling how the operation should behave |
301
302##### Returns
303
304`Promise`\<`void`\>
305
306#### Defined in
307
308[index.ts:553](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L553)
309
310___
311
312### name
313
314• **name**: `string`
315
316#### Defined in
317
318[index.ts:367](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L367)
319
320___
321
322### overwrite
323
324• **overwrite**: (`data`: `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[]) => `Promise`\<`number`\>
325
326#### Type declaration
327
328▸ (`data`): `Promise`\<`number`\>
329
330Insert records into this Table, replacing its contents.
331
332##### Parameters
333
334| Name | Type | Description |
335| :------ | :------ | :------ |
336| `data` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
337
338##### Returns
339
340`Promise`\<`number`\>
341
342The number of rows added to the table
343
344#### Defined in
345
346[index.ts:389](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L389)
347
348___
349
350### schema
351
352• **schema**: `Promise`\<`Schema`\<`any`\>\>
353
354#### Defined in
355
356[index.ts:571](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L571)
357
358___
359
360### search
361
362• **search**: (`query`: `T`) => [`Query`](../classes/Query.md)\<`T`\>
363
364#### Type declaration
365
366▸ (`query`): [`Query`](../classes/Query.md)\<`T`\>
367
368Creates a search query to find the nearest neighbors of the given search term
369
370##### Parameters
371
372| Name | Type | Description |
373| :------ | :------ | :------ |
374| `query` | `T` | The query search term |
375
376##### Returns
377
378[`Query`](../classes/Query.md)\<`T`\>
379
380#### Defined in
381
382[index.ts:373](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L373)
383
384___
385
386### update
387
388• **update**: (`args`: [`UpdateArgs`](UpdateArgs.md) \| [`UpdateSqlArgs`](UpdateSqlArgs.md)) => `Promise`\<`void`\>
389
390#### Type declaration
391
392▸ (`args`): `Promise`\<`void`\>
393
394Update rows in this table.
395
396This can be used to update a single row, many rows, all rows, or
397sometimes no rows (if your predicate matches nothing).
398
399##### Parameters
400
401| Name | Type | Description |
402| :------ | :------ | :------ |
403| `args` | [`UpdateArgs`](UpdateArgs.md) \| [`UpdateSqlArgs`](UpdateSqlArgs.md) | see [UpdateArgs](UpdateArgs.md) and [UpdateSqlArgs](UpdateSqlArgs.md) for more details |
404
405##### Returns
406
407`Promise`\<`void`\>
408
409**`Examples`**
410
411```ts
412const con = await lancedb.connect("./.lancedb")
413const data = [
414 {id: 1, vector: [3, 3], name: 'Ye'},
415 {id: 2, vector: [4, 4], name: 'Mike'},
416];
417const tbl = await con.createTable("my_table", data)
418
419await tbl.update({
420 where: "id = 2",
421 values: { vector: [2, 2], name: "Michael" },
422})
423
424let results = await tbl.search([1, 1]).execute();
425// Returns [
426// {id: 2, vector: [2, 2], name: 'Michael'}
427// {id: 1, vector: [3, 3], name: 'Ye'}
428// ]
429```
430
431#### Defined in
432
433[index.ts:521](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L521)
434
435## Methods
436
437### addColumns
438
439▸ **addColumns**(`newColumnTransforms`): `Promise`\<`void`\>
440
441Add new columns with defined values.
442
443#### Parameters
444
445| Name | Type | Description |
446| :------ | :------ | :------ |
447| `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. |
448
449#### Returns
450
451`Promise`\<`void`\>
452
453#### Defined in
454
455[index.ts:582](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L582)
456
457___
458
459### alterColumns
460
461▸ **alterColumns**(`columnAlterations`): `Promise`\<`void`\>
462
463Alter the name or nullability of columns.
464
465#### Parameters
466
467| Name | Type | Description |
468| :------ | :------ | :------ |
469| `columnAlterations` | [`ColumnAlteration`](ColumnAlteration.md)[] | One or more alterations to apply to columns. |
470
471#### Returns
472
473`Promise`\<`void`\>
474
475#### Defined in
476
477[index.ts:591](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L591)
478
479___
480
481### dropColumns
482
483▸ **dropColumns**(`columnNames`): `Promise`\<`void`\>
484
485Drop one or more columns from the dataset
486
487This is a metadata-only operation and does not remove the data from the
488underlying storage. In order to remove the data, you must subsequently
489call ``compact_files`` to rewrite the data without the removed columns and
490then call ``cleanup_files`` to remove the old files.
491
492#### Parameters
493
494| Name | Type | Description |
495| :------ | :------ | :------ |
496| `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"). |
497
498#### Returns
499
500`Promise`\<`void`\>
501
502#### Defined in
503
504[index.ts:605](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L605)
505
506___
507
508### filter
509
510▸ **filter**(`value`): [`Query`](../classes/Query.md)\<`T`\>
511
512#### Parameters
513
514| Name | Type |
515| :------ | :------ |
516| `value` | `string` |
517
518#### Returns
519
520[`Query`](../classes/Query.md)\<`T`\>
521
522#### Defined in
523
524[index.ts:569](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L569)
525
526___
527
528### withMiddleware
529
530▸ **withMiddleware**(`middleware`): [`Table`](Table.md)\<`T`\>
531
532Instrument the behavior of this Table with middleware.
533
534The middleware will be called in the order they are added.
535
536Currently this functionality is only supported for remote tables.
537
538#### Parameters
539
540| Name | Type |
541| :------ | :------ |
542| `middleware` | `HttpMiddleware` |
543
544#### Returns
545
546[`Table`](Table.md)\<`T`\>
547
548- this Table instrumented by the passed middleware
549
550#### Defined in
551
552[index.ts:617](https://github.com/lancedb/lancedb/blob/92179835/node/src/index.ts#L617)