Index 操作
更新时间:2024-06-11
创建索引
接口描述
为指定表和字段新建索引,当前仅支持新建向量索引。支持同时建立多个索引(针对不同字段)。
请求结构
POST /v{version}/index?create HTTP/1.1
HOST: {Endpoint}
Authorization: {Authorization}
{
"database": "db_name",
"table": "table_name",
"indexes": [
{
"field": "vector_field",
"indexName": "vector_idx",
"indexType": "HNSW",
"metricType": "L2",
"params": {
"M": 32,
"efConstruction": 200
}
}
]
}
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 是否必填 | 参数位置 | 描述 |
---|---|---|---|---|
version | String | 是 | URL参数 | API版本号,当前取1。 |
database | String | 是 | RequestBody参数 | 指定库的名称。 |
table | String | 是 | RequestBody参数 | 指定表的名称。 |
indexs | List Index | 是 | RequestBody参数 | 索引定义详情列表。 |
Index参数
参数名称 | 参数类型 | 描述 |
---|---|---|
indexName | String | 索引名称,要求表内唯一。索引名称的命名要求如下: 1. 仅支持大小写字母、数字以及下划线(_),必须以字母开头; 2. 长度限制为1~255。 |
indexType | String | 索引类型。当前支持如下类型: |
metricType | String | 向量索引的距离度量算法。支持如下距离类型: |
params | VectorIndexParams | 向量索引的参数详情。 |
field | String | 索引作用于的字段名称。 |
autoBuild | Boolean | 是否自动构建向量索引,默认false。 仅当索引为向量索引时才需要指定该字段。 |
VectorIndexParams参数
HNSW索引
参数名称 | 参数类型 | 描述 |
---|---|---|
M | Int | HNSW索引算法参数,取值范围为[4, 128]。 该参数表示每个节点在索引构图中可以连接多少个邻居节点。 |
efConstruction | Int | HNSW索引算法参数,取值范围为[8, 1024]。 该参数表示搜索时指定寻找节点邻居遍历的范围。数值越大构图效果越好,构图时间也越长。 |
PUCK索引
参数名称 | 参数类型 | 描述 |
---|---|---|
coarseClusterCount | Int | PUCK索引算法参数,取值范围为[1, 5000]。 该参数表示索引中粗聚类中心个数。 |
fineClusterCount | Int | PUCK索引算法参数,取值范围为[1, 5000]。 该参数表示每个粗聚类中心下细聚类中心个数。 |
响应头域
除公共头域外,无其它特殊头域。
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
code | Int | 返回码 |
msg | String | 返回信息 |
请求示例
POST http://vdb.nXWNyPCOSLci.vdb.bj.baidubce.com/v1/index?create
Host: vdb.nXWNyPCOSLci.vdb.bj.baidubce.com
Authorization: Bearer account=root&api_key=eC4bLRy2va******************************
{
"database": "db_name",
"table": "table_name",
"indexes": [
{
"field": "vector_field"
"indexName": "vector_idx",
"indexType": "HNSW",
"metricType": "L2",
"params": {
"M": 32,
"efConstruction": 200
}
}
]
}
响应示例
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Date: Wed, 08 Jul 2015 03:28:11 GMT
Request-ID: d8752367-38e8-45e4-b4c7-e53be3137ce5
{
"code": 0,
"msg": "Success"
}
查询索引详情
接口描述
查询指定索引的详情。
请求结构
POST /v{version}/index?desc HTTP/1.1
HOST: {Endpoint}
Authorization: {Authorization}
{
"database": "db_name",
"table": "table_name",
"indexName": "vector_idx"
}
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 是否必填 | 参数位置 | 描述 |
---|---|---|---|---|
version | String | 是 | URL参数 | API版本号,当前取1。 |
database | String | 是 | RequestBody参数 | 指定库的名称。 |
table | String | 是 | RequestBody参数 | 指定表的名称。 |
indexName | String | 是 | RequestBody参数 | 指定索引的名称。 |
响应头域
除公共头域外,无其它特殊头域。
响应参数
Index参数
参数名称 | 参数类型 | 描述 |
---|---|---|
indexName | String | 索引名称。 |
indexType | String | 索引类型。当前支持如下类型: |
metricType | String | 向量索引的距离度量算法。支持如下距离类型 |
params | VectorIndexParams | 向量索引的参数详情。 |
field | String | 索引作用于的字段名称。 |
state | String | 索引状态。取值如下: |
VectorIndexParams参数
HNSW索引
参数名称 | 参数类型 | 描述 |
---|---|---|
M | Int | HNSW索引算法参数。 该参数表示每个节点在索引构图中可以连接多少个邻居节点。 |
efConstruction | Int | HNSW索引算法参数。 该参数表示搜索时指定寻找节点邻居遍历的范围。数值越大构图效果越好,构图时间也越长。 |
PUCK索引
参数名称 | 参数类型 | 描述 |
---|---|---|
coarseClusterCount | Int | PUCK索引算法参数。 该参数表示索引中粗聚类中心的个数。 |
fineClusterCount | Int | PUCK索引算法参数。 该参数表示索引中每个粗聚类中心下细聚类中心的个数。 |
请求示例
POST http://vdb.nXWNyPCOSLci.vdb.bj.baidubce.com/v1/index?desc
Host: vdb.nXWNyPCOSLci.vdb.bj.baidubce.com
Authorization: Bearer account=root&api_key=eC4bLRy2va******************************
{
"database": "db_test",
"table": "table_test",
"indexName": "vector_idx"
}
响应示例
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Date: Wed, 08 Jul 2015 03:28:11 GMT
Request-ID: d8752367-38e8-45e4-b4c7-e53be3137ce5
{
"index": {
"indexName": "vector_idx",
"field": "vector_field",
"autoBuild": false,
"indexType": "HNSW",
"metricType": "L2",
"params": {
"M": 32,
"efConstruction": 200
},
"state": "NORMAL"
},
"code": 0,
"msg": "Success"
}
重建索引
接口描述
重建指定索引,仅支持重建向量索引。
请求结构
POST /v{version}/index?rebuild HTTP/1.1
HOST: {Endpoint}
Authorization: {Authorization}
{
"database": "db_name",
"table": "table_name",
"indexName": "vector_idx"
}
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 是否必填 | 参数位置 | 描述 |
---|---|---|---|---|
version | String | 是 | URL参数 | API版本号,当前取1。 |
database | String | 是 | Request Body参数 | 指定库的名称。 |
table | String | 是 | Request Body参数 | 指定表的名称。 |
indexName | Index | 是 | Request Body参数 | 指定索引的名称。 |
响应头域
除公共头域外,无其它特殊头域。
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
code | Int | 返回码 |
msg | String | 返回信息 |
请求示例
POST http://vdb.nXWNyPCOSLci.vdb.bj.baidubce.com/v1/index?rebuild
Host: vdb.nXWNyPCOSLci.vdb.bj.baidubce.com
Authorization: Bearer account=root&api_key=eC4bLRy2va******************************
{
"database": "db_test",
"table": "table_test",
"indexName": "vector_idx"
}
响应示例
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Date: Wed, 08 Jul 2015 03:28:11 GMT
Request-ID: d8752367-38e8-45e4-b4c7-e53be3137ce5
{
"code": 0,
"msg": "Success"
}
删除索引
接口描述
删除指定索引。
请求结构
DELETE /v{version}/index HTTP/1.1
HOST: {Endpoint}
Authorization: {Authorization}
{
"database": "db_name",
"table": "table_name",
"indexName": "index_name"
}
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 是否必填 | 参数位置 | 描述 |
---|---|---|---|---|
version | String | 是 | URL参数 | API版本号,当前取1。 |
database | String | 是 | Query参数 | 指定库的名称。 |
table | String | 是 | Query参数 | 指定表的名称。 |
indexName | Index | 是 | Query参数 | 指定索引的名称。 |
响应头域
除公共头域外,无其它特殊头域。
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
code | Int | 返回码 |
msg | String | 返回信息 |
请求示例
DELETE http://vdb.nXWNyPCOSLci.vdb.bj.baidubce.com/v1/index
Host: vdb.nXWNyPCOSLci.vdb.bj.baidubce.com
Authorization: Bearer account=root&api_key=eC4bLRy2va******************************
{
"database": "db_test",
"table": "table_test",
"indexName": "vector_idx"
}
响应示例
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Date: Wed, 08 Jul 2015 03:28:11 GMT
Request-ID: d8752367-38e8-45e4-b4c7-e53be3137ce5
{
"code": 0,
"msg": "Success"
}