vectordb / Exports / LocalTable
类:LocalTable\
LanceDB表是记录的集合。每条记录包含一个或多个向量字段。
类型参数
| 名称 | 类型 |
|---|---|
T |
number[] |
实现
Table\<T>
目录
构造函数
属性
访问器
方法
- add
- addColumns
- alterColumns
- checkElectron
- cleanupOldVersions
- compactFiles
- countRows
- createIndex
- createScalarIndex
- delete
- dropColumns
- dropIndex
- filter
- getSchema
- indexStats
- listIndices
- mergeInsert
- overwrite
- search
- update
- withMiddleware
构造函数
构造函数
• new LocalTable\<T>(tbl, name, options)
类型参数
| 名称 | 类型 |
|---|---|
T |
number[] |
参数
| 名称 | 类型 |
|---|---|
tbl |
any |
name |
string |
options |
ConnectionOptions |
定义于
• new LocalTable\<T>(tbl, name, options, embeddings)
类型参数
| 名称 | 类型 |
|---|---|
T |
number[] |
参数
| 名称 | 类型 | 描述 |
|---|---|---|
tbl |
any |
|
name |
string |
|
options |
ConnectionOptions |
|
embeddings |
EmbeddingFunction\<T> |
An embedding function to use when interacting with this table |
定义于
属性
_嵌入向量
• Private Optional Readonly _embeddings: EmbeddingFunction\<T>
定义于
_isElectron
• Private Readonly _isElectron: boolean
定义于
_name
• Private Readonly _name: string
定义于
_选项
• Private Readonly _options: () => ConnectionOptions
类型声明
▸ (): ConnectionOptions
返回
定义于
_tbl
• Private _tbl: any
定义于
where条件筛选
• where: (value: string) => Query\<T>
类型声明
▸ (value): Query\<T>
创建一个过滤查询以查找符合指定条件的所有行
参数
| 名称 | 类型 | 描述 |
|---|---|---|
value |
string |
The filter criteria (like SQL where clause syntax) |
返回
Query\<T>
定义于
访问器
名称
• get name(): string
返回值
string
的实现
定义于
架构
• get schema(): Promise\<Schema\<any>>
返回值
Promise\<Schema\<any>>
的实现
定义于
方法
添加
▸ add(data): Promise\<number>
将记录插入此表中。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
data |
Table\<any> | Record\<string, unknown>[] |
Records to be inserted into the Table |
返回值
Promise\<number>
添加到表中的行数
的实现
定义于
addColumns
▸ addColumns(newColumnTransforms): Promise\<void>
使用定义的值添加新列。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
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. |
返回值
Promise\<void>
的实现
定义于
alterColumns
▸ alterColumns(columnAlterations): Promise\<void>
修改列的名称或可空性。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
columnAlterations |
ColumnAlteration[] |
One or more alterations to apply to columns. |
返回值
Promise\<void>
的实现
定义于
checkElectron
▸ Private checkElectron(): boolean
返回值
boolean
定义于
清理旧版本
▸ cleanupOldVersions(olderThan?, deleteUnverified?): Promise\<CleanupStats>
清理表的旧版本,释放磁盘空间。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
olderThan? |
number |
The minimum age in minutes of the versions to delete. If not provided, defaults to two weeks. |
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. |
返回值
Promise\<CleanupStats>
定义于
compactFiles
▸ compactFiles(options?): Promise\<CompactionMetrics>
对表运行压缩过程。
在对表进行多次小规模追加操作后,可以运行此功能以优化表结构,从而提升读取速度。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
options? |
CompactionOptions |
Advanced options configuring compaction. In most cases, you can omit this arguments, as the default options are sensible for most tables. |
返回值
Promise\<CompactionMetrics>
关于压缩操作的指标。
定义于
countRows
▸ countRows(filter?): Promise\<number>
返回此表中的行数。
参数
| 名称 | 类型 |
|---|---|
filter? |
string |
返回值
Promise<number>
的实现
定义于
createIndex
▸ createIndex(indexParams): Promise\<any>
在此表的向量索引上创建一个ANN索引。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
indexParams |
IvfPQIndexConfig |
The parameters of this Index, |
返回值
Promise\<any>
查看
VectorIndexParams参数。
的实现
定义于
createScalarIndex
▸ createScalarIndex(column, replace?): Promise\<void>
在给定列上为此表创建标量索引
参数
| 名称 | 类型 | 描述 |
|---|---|---|
column |
string |
The column to index |
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. |
返回值
Promise\<void>
示例
const con = await lancedb.connect('././lancedb')
const table = await con.openTable('images')
await table.createScalarIndex('my_col')
的实现
定义于
删除
▸ 删除(filter): Promise\<void>
从该表中删除行。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
filter |
string |
A filter in the same format used by a sql WHERE clause. |
返回值
Promise\<void>
的实现
定义于
dropColumns
▸ dropColumns(columnNames): Promise\<void>
从数据集中删除一列或多列
这是一个仅涉及元数据的操作,不会从底层存储中删除实际数据。若要删除数据,您必须随后调用compact_files重写不包含被删除列的数据,然后调用cleanup_files来移除旧文件。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
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"). |
返回值
Promise\<void>
的实现
定义于
dropIndex
▸ dropIndex(indexName): Promise\<void>
从表中删除索引
参数
| 名称 | 类型 | 描述 |
|---|---|---|
indexName |
string |
The name of the index to drop |
返回值
Promise\<void>
的实现
定义于
筛选器
▸ 筛选(value): Query\<T>
创建一个过滤查询以查找符合指定条件的所有行
参数
| 名称 | 类型 | 描述 |
|---|---|---|
value |
string |
The filter criteria (like SQL where clause syntax) |
返回值
Query\<T>
的实现
定义于
getSchema
▸ Private getSchema(): Promise\<Schema\<any>>
返回值
Promise\<Schema\<any>>
定义于
indexStats
▸ indexStats(indexName): Promise\<IndexStats>
获取索引的统计信息。
参数
| 名称 | 类型 |
|---|---|
indexName |
string |
返回值
Promise\<IndexStats>
的实现
定义于
listIndices
▸ listIndices(): Promise\<VectorIndex[]>
列出此表上的索引。
返回值
Promise<VectorIndex[]>
的实现
定义于
mergeInsert
▸ mergeInsert(on, data, args): Promise\<void>
对表执行"合并插入"操作
该操作可以在单个事务中完成添加行、更新行和删除行。这是一个非常通用的工具,可用于实现诸如"不存在则插入"、"更新或插入(即upsert)"等行为,甚至可以用新数据替换部分现有数据(例如替换所有month="january"的数据)
合并插入操作通过使用连接将源表中的新数据与目标表中的现有数据相结合。记录分为三类。
"匹配"记录是指同时存在于源表和目标表中的记录。"未匹配"记录仅存在于源表中(例如这些是新数据)"源表未匹配"记录仅存在于目标表中(这是旧数据)
MergeInsertArgs可用于自定义每类数据的处理方式。
请注意,数据在此操作过程中可能会被重新排序。这是因为更新的行会先从数据集中删除,然后以新值重新插入到末尾。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
on |
string |
a column to join on. This is how records from the source table and target table are matched. |
data |
Table\<any> | Record\<string, unknown>[] |
the new data to insert |
args |
MergeInsertArgs |
parameters controlling how the operation should behave |
返回值
Promise\<void>
的实现
定义于
覆盖
▸ 覆盖写入(data): Promise\<number>
将记录插入此表,替换其内容。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
data |
Table\<any> | Record\<string, unknown>[] |
Records to be inserted into the Table |
返回值
Promise<number>
添加到表中的行数
的实现
定义于
搜索
▸ 搜索(query): Query\<T>
创建一个搜索查询以查找给定搜索词的最邻近邻居
参数
| 名称 | 类型 | 描述 |
|---|---|---|
query |
T |
The query search term |
返回值
Query\<T>
的实现
定义于
更新
▸ 更新(args): Promise\<void>
更新此表中的行。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
args |
UpdateArgs | UpdateSqlArgs |
see UpdateArgs and UpdateSqlArgs for more details |
返回值
Promise\<void>
的实现
定义于
withMiddleware
▸ withMiddleware(middleware): Table\<T>
使用中间件来监控此表的行为。
中间件将按照它们被添加的顺序依次调用。
目前此功能仅支持远程表。
参数
| 名称 | 类型 |
|---|---|
middleware |
HttpMiddleware |
返回值
Table\<T>
- 这个Table由传入的中间件进行检测