| 1 | [vectordb](../README.md) / [Exports](../modules.md) / Table |
| 2 | |
| 3 | # Interface: Table\<T\> |
| 4 | |
| 5 | A 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 | - [name](Table.md#name) |
| 29 | - [overwrite](Table.md#overwrite) |
| 30 | - [schema](Table.md#schema) |
| 31 | - [search](Table.md#search) |
| 32 | - [update](Table.md#update) |
| 33 | |
| 34 | ## Properties |
| 35 | |
| 36 | ### add |
| 37 | |
| 38 | • **add**: (`data`: `Record`\<`string`, `unknown`\>[]) => `Promise`\<`number`\> |
| 39 | |
| 40 | #### Type declaration |
| 41 | |
| 42 | ▸ (`data`): `Promise`\<`number`\> |
| 43 | |
| 44 | Insert records into this Table. |
| 45 | |
| 46 | ##### Parameters |
| 47 | |
| 48 | | Name | Type | Description | |
| 49 | | :------ | :------ | :------ | |
| 50 | | `data` | `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table | |
| 51 | |
| 52 | ##### Returns |
| 53 | |
| 54 | `Promise`\<`number`\> |
| 55 | |
| 56 | The number of rows added to the table |
| 57 | |
| 58 | #### Defined in |
| 59 | |
| 60 | [index.ts:291](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L291) |
| 61 | |
| 62 | ___ |
| 63 | |
| 64 | ### countRows |
| 65 | |
| 66 | • **countRows**: () => `Promise`\<`number`\> |
| 67 | |
| 68 | #### Type declaration |
| 69 | |
| 70 | ▸ (): `Promise`\<`number`\> |
| 71 | |
| 72 | Returns the number of rows in this table. |
| 73 | |
| 74 | ##### Returns |
| 75 | |
| 76 | `Promise`\<`number`\> |
| 77 | |
| 78 | #### Defined in |
| 79 | |
| 80 | [index.ts:361](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L361) |
| 81 | |
| 82 | ___ |
| 83 | |
| 84 | ### createIndex |
| 85 | |
| 86 | • **createIndex**: (`indexParams`: [`IvfPQIndexConfig`](IvfPQIndexConfig.md)) => `Promise`\<`any`\> |
| 87 | |
| 88 | #### Type declaration |
| 89 | |
| 90 | ▸ (`indexParams`): `Promise`\<`any`\> |
| 91 | |
| 92 | Create an ANN index on this Table vector index. |
| 93 | |
| 94 | ##### Parameters |
| 95 | |
| 96 | | Name | Type | Description | |
| 97 | | :------ | :------ | :------ | |
| 98 | | `indexParams` | [`IvfPQIndexConfig`](IvfPQIndexConfig.md) | The parameters of this Index, | |
| 99 | |
| 100 | ##### Returns |
| 101 | |
| 102 | `Promise`\<`any`\> |
| 103 | |
| 104 | **`See`** |
| 105 | |
| 106 | VectorIndexParams. |
| 107 | |
| 108 | #### Defined in |
| 109 | |
| 110 | [index.ts:306](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L306) |
| 111 | |
| 112 | ___ |
| 113 | |
| 114 | ### createScalarIndex |
| 115 | |
| 116 | • **createScalarIndex**: (`column`: `string`, `replace`: `boolean`) => `Promise`\<`void`\> |
| 117 | |
| 118 | #### Type declaration |
| 119 | |
| 120 | ▸ (`column`, `replace`): `Promise`\<`void`\> |
| 121 | |
| 122 | Create a scalar index on this Table for the given column |
| 123 | |
| 124 | ##### Parameters |
| 125 | |
| 126 | | Name | Type | Description | |
| 127 | | :------ | :------ | :------ | |
| 128 | | `column` | `string` | The column to index | |
| 129 | | `replace` | `boolean` | If false, fail if an index already exists on the column 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`. | |
| 130 | |
| 131 | ##### Returns |
| 132 | |
| 133 | `Promise`\<`void`\> |
| 134 | |
| 135 | **`Examples`** |
| 136 | |
| 137 | ```ts |
| 138 | const con = await lancedb.connect('././lancedb') |
| 139 | const table = await con.openTable('images') |
| 140 | await table.createScalarIndex('my_col') |
| 141 | ``` |
| 142 | |
| 143 | #### Defined in |
| 144 | |
| 145 | [index.ts:356](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L356) |
| 146 | |
| 147 | ___ |
| 148 | |
| 149 | ### delete |
| 150 | |
| 151 | • **delete**: (`filter`: `string`) => `Promise`\<`void`\> |
| 152 | |
| 153 | #### Type declaration |
| 154 | |
| 155 | ▸ (`filter`): `Promise`\<`void`\> |
| 156 | |
| 157 | Delete rows from this table. |
| 158 | |
| 159 | This can be used to delete a single row, many rows, all rows, or |
| 160 | sometimes no rows (if your predicate matches nothing). |
| 161 | |
| 162 | ##### Parameters |
| 163 | |
| 164 | | Name | Type | Description | |
| 165 | | :------ | :------ | :------ | |
| 166 | | `filter` | `string` | A filter in the same format used by a sql WHERE clause. The filter must not be empty. | |
| 167 | |
| 168 | ##### Returns |
| 169 | |
| 170 | `Promise`\<`void`\> |
| 171 | |
| 172 | **`Examples`** |
| 173 | |
| 174 | ```ts |
| 175 | const con = await lancedb.connect("./.lancedb") |
| 176 | const data = [ |
| 177 | {id: 1, vector: [1, 2]}, |
| 178 | {id: 2, vector: [3, 4]}, |
| 179 | {id: 3, vector: [5, 6]}, |
| 180 | ]; |
| 181 | const tbl = await con.createTable("my_table", data) |
| 182 | await tbl.delete("id = 2") |
| 183 | await tbl.countRows() // Returns 2 |
| 184 | ``` |
| 185 | |
| 186 | If you have a list of values to delete, you can combine them into a |
| 187 | stringified list and use the `IN` operator: |
| 188 | |
| 189 | ```ts |
| 190 | const to_remove = [1, 5]; |
| 191 | await tbl.delete(`id IN (${to_remove.join(",")})`) |
| 192 | await tbl.countRows() // Returns 1 |
| 193 | ``` |
| 194 | |
| 195 | #### Defined in |
| 196 | |
| 197 | [index.ts:395](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L395) |
| 198 | |
| 199 | ___ |
| 200 | |
| 201 | ### indexStats |
| 202 | |
| 203 | • **indexStats**: (`indexUuid`: `string`) => `Promise`\<[`IndexStats`](IndexStats.md)\> |
| 204 | |
| 205 | #### Type declaration |
| 206 | |
| 207 | ▸ (`indexUuid`): `Promise`\<[`IndexStats`](IndexStats.md)\> |
| 208 | |
| 209 | Get statistics about an index. |
| 210 | |
| 211 | ##### Parameters |
| 212 | |
| 213 | | Name | Type | |
| 214 | | :------ | :------ | |
| 215 | | `indexUuid` | `string` | |
| 216 | |
| 217 | ##### Returns |
| 218 | |
| 219 | `Promise`\<[`IndexStats`](IndexStats.md)\> |
| 220 | |
| 221 | #### Defined in |
| 222 | |
| 223 | [index.ts:438](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L438) |
| 224 | |
| 225 | ___ |
| 226 | |
| 227 | ### listIndices |
| 228 | |
| 229 | • **listIndices**: () => `Promise`\<[`VectorIndex`](VectorIndex.md)[]\> |
| 230 | |
| 231 | #### Type declaration |
| 232 | |
| 233 | ▸ (): `Promise`\<[`VectorIndex`](VectorIndex.md)[]\> |
| 234 | |
| 235 | List the indicies on this table. |
| 236 | |
| 237 | ##### Returns |
| 238 | |
| 239 | `Promise`\<[`VectorIndex`](VectorIndex.md)[]\> |
| 240 | |
| 241 | #### Defined in |
| 242 | |
| 243 | [index.ts:433](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L433) |
| 244 | |
| 245 | ___ |
| 246 | |
| 247 | ### name |
| 248 | |
| 249 | • **name**: `string` |
| 250 | |
| 251 | #### Defined in |
| 252 | |
| 253 | [index.ts:277](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L277) |
| 254 | |
| 255 | ___ |
| 256 | |
| 257 | ### overwrite |
| 258 | |
| 259 | • **overwrite**: (`data`: `Record`\<`string`, `unknown`\>[]) => `Promise`\<`number`\> |
| 260 | |
| 261 | #### Type declaration |
| 262 | |
| 263 | ▸ (`data`): `Promise`\<`number`\> |
| 264 | |
| 265 | Insert records into this Table, replacing its contents. |
| 266 | |
| 267 | ##### Parameters |
| 268 | |
| 269 | | Name | Type | Description | |
| 270 | | :------ | :------ | :------ | |
| 271 | | `data` | `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table | |
| 272 | |
| 273 | ##### Returns |
| 274 | |
| 275 | `Promise`\<`number`\> |
| 276 | |
| 277 | The number of rows added to the table |
| 278 | |
| 279 | #### Defined in |
| 280 | |
| 281 | [index.ts:299](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L299) |
| 282 | |
| 283 | ___ |
| 284 | |
| 285 | ### schema |
| 286 | |
| 287 | • **schema**: `Promise`\<`Schema`\<`any`\>\> |
| 288 | |
| 289 | #### Defined in |
| 290 | |
| 291 | [index.ts:440](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L440) |
| 292 | |
| 293 | ___ |
| 294 | |
| 295 | ### search |
| 296 | |
| 297 | • **search**: (`query`: `T`) => [`Query`](../classes/Query.md)\<`T`\> |
| 298 | |
| 299 | #### Type declaration |
| 300 | |
| 301 | ▸ (`query`): [`Query`](../classes/Query.md)\<`T`\> |
| 302 | |
| 303 | Creates a search query to find the nearest neighbors of the given search term |
| 304 | |
| 305 | ##### Parameters |
| 306 | |
| 307 | | Name | Type | Description | |
| 308 | | :------ | :------ | :------ | |
| 309 | | `query` | `T` | The query search term | |
| 310 | |
| 311 | ##### Returns |
| 312 | |
| 313 | [`Query`](../classes/Query.md)\<`T`\> |
| 314 | |
| 315 | #### Defined in |
| 316 | |
| 317 | [index.ts:283](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L283) |
| 318 | |
| 319 | ___ |
| 320 | |
| 321 | ### update |
| 322 | |
| 323 | • **update**: (`args`: [`UpdateArgs`](UpdateArgs.md) \| [`UpdateSqlArgs`](UpdateSqlArgs.md)) => `Promise`\<`void`\> |
| 324 | |
| 325 | #### Type declaration |
| 326 | |
| 327 | ▸ (`args`): `Promise`\<`void`\> |
| 328 | |
| 329 | Update rows in this table. |
| 330 | |
| 331 | This can be used to update a single row, many rows, all rows, or |
| 332 | sometimes no rows (if your predicate matches nothing). |
| 333 | |
| 334 | ##### Parameters |
| 335 | |
| 336 | | Name | Type | Description | |
| 337 | | :------ | :------ | :------ | |
| 338 | | `args` | [`UpdateArgs`](UpdateArgs.md) \| [`UpdateSqlArgs`](UpdateSqlArgs.md) | see [UpdateArgs](UpdateArgs.md) and [UpdateSqlArgs](UpdateSqlArgs.md) for more details | |
| 339 | |
| 340 | ##### Returns |
| 341 | |
| 342 | `Promise`\<`void`\> |
| 343 | |
| 344 | **`Examples`** |
| 345 | |
| 346 | ```ts |
| 347 | const con = await lancedb.connect("./.lancedb") |
| 348 | const data = [ |
| 349 | {id: 1, vector: [3, 3], name: 'Ye'}, |
| 350 | {id: 2, vector: [4, 4], name: 'Mike'}, |
| 351 | ]; |
| 352 | const tbl = await con.createTable("my_table", data) |
| 353 | |
| 354 | await tbl.update({ |
| 355 | where: "id = 2", |
| 356 | values: { vector: [2, 2], name: "Michael" }, |
| 357 | }) |
| 358 | |
| 359 | let results = await tbl.search([1, 1]).execute(); |
| 360 | // Returns [ |
| 361 | // {id: 2, vector: [2, 2], name: 'Michael'} |
| 362 | // {id: 1, vector: [3, 3], name: 'Ye'} |
| 363 | // ] |
| 364 | ``` |
| 365 | |
| 366 | #### Defined in |
| 367 | |
| 368 | [index.ts:428](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L428) |