Index 操作
更新时间:2025-01-14
创建索引
功能介绍
为指定数据表和指定字段新建索引,当前仅支持新建向量索引。
请求示例
Typescript
1import {
2 MochowClient,
3 IndexSchema,
4 IndexType,
5 MetricType,
6} from "@mochow/mochow-sdk-node";
7
8const mochowClient = new MochowClient({
9 credential: {
10 account: "root",
11 apiKey: "您的账户API密钥",
12 },
13 endpoint: "您的实例访问端点", // 例如:'http://127.0.0.1:5287'
14});
15
16let indexSchema: IndexSchema = {
17 indexName: "vector_idx",
18 field: "vector",
19 indexType: IndexType.HNSW,
20 metricType: MetricType.L2,
21 params: {
22 "M": 16,
23 "efConstruction": 200
24 }
25}
26let resp = await mochowClient.createIndex("db_test", "table_test", [indexSchema])
请求参数
参数 | 参数类型 | 是否必选 | 参数含义 |
---|---|---|---|
database | String | 是 | 库名。 |
table | String | 是 | 表名。 |
indexes | List |
是 | 索引定义。 |
删除索引
功能介绍
删除指定索引。
请求示例
Typescript
1import {
2 MochowClient,
3} from "@mochow/mochow-sdk-node";
4
5const mochowClient = new MochowClient({
6 credential: {
7 account: "root",
8 apiKey: "您的账户API密钥",
9 },
10 endpoint: "您的实例访问端点", // 例如:'http://127.0.0.1:5287'
11});
12
13let resp = await mochowClient.dropIndex("db_test", "table_test", "idx_test")
请求参数
参数 | 参数类型 | 是否必选 | 参数含义 |
---|---|---|---|
database | String | 是 | 库名。 |
table | String | 是 | 表名。 |
indexName | String | 是 | 索引名称。 |
重建索引
功能介绍
重建指定索引,当前仅支持重建向量索引。
请求示例
Typescript
1import {
2 MochowClient,
3} from "@mochow/mochow-sdk-node";
4
5const mochowClient = new MochowClient({
6 credential: {
7 account: "root",
8 apiKey: "您的账户API密钥",
9 },
10 endpoint: "您的实例访问端点", // 例如:'http://127.0.0.1:5287'
11});
12
13let resp = await mochowClient.rebuildIndex("db_test", "table_test", "idx_test")
请求参数
参数 | 参数类型 | 是否必选 | 参数含义 |
---|---|---|---|
database | String | 是 | 库名。 |
table | String | 是 | 表名。 |
indexName | String | 是 | 索引名称。 |
查询索引详情
功能介绍
查询指定索引的详情。
请求示例
Typescript
1import {
2 MochowClient,
3} from "@mochow/mochow-sdk-node";
4
5const mochowClient = new MochowClient({
6 credential: {
7 account: "root",
8 apiKey: "您的账户API密钥",
9 },
10 endpoint: "您的实例访问端点", // 例如:'http://127.0.0.1:5287'
11});
12
13let resp = await mochowClient.descIndex("db_test", "table_test", "idx_test")
请求参数
参数 | 参数类型 | 是否必选 | 参数含义 |
---|---|---|---|
database | String | 是 | 库名。 |
table | String | 是 | 表名。 |
indexName | String | 是 | 索引名称。 |
返回参数
参数 | 参数类型 | 参数含义 |
---|---|---|
index | IndexSchema | Index对象。 |
IndexSchema
参数名称 | 参数类型 | 描述 |
---|---|---|
indexName | String | 索引名称。 |
indexType | String | 索引类型。 |
metricType | String | 向量索引的距离度量算法。 |
params | VectorIndexParams | 向量构建索引所需参数。 1. m:表示每个节点在检索构图中可以连接多少个邻居节点。取值为[4, 128]; 2. efconstruction:搜索时,指定寻找节点邻居遍历的范围。数值越大构图效果越好,构图时间越长。取值为[8, 1024]。 1. coarseClusterCount:索引中粗聚类中心的个数; 2. fineClusterCount:每个粗聚类中心下细聚类中心个数。 1. m:表示每个节点在检索构图中可以连接多少个邻居节点。取值为[4, 128]; 2. efconstruction:搜索时,指定寻找节点邻居遍历的范围。数值越大构图效果越好,构图时间越长。取值为[8, 1024]; 3. NSQ:表示量化子空间个数,取值为[1, dim],并且要求NSQ | dim; 4. sampleRate:kmeans训练原始数据的抽样比率,取值为[0.0, 1.0],抽样总数 10000 + (rowCount - 10000)*sampleRate |
autoBuild | Boolean | 是否自动构建索引,默认为False。 |
autoBuildPolicy | AutoBuildPolicy | 自动构建索引策略,当前支持如下策略: |
field | String | 索引作用于的目标字段名称。 |
invertedIndexFields | List |
倒排索引作用于的目标字段名称。 |
invertedIndexFieldAttributes | List |
指定建立倒排索引的列是否需要分词(默认是会分词),参数顺序应与'fields'里列名一一对应。目前支持以下选项: |
filterIndexFields | List |
Filtering索引作用于的目标字段名称。 |
state | IndexState | 索引状态,返回值如下: |