索引表操作

本文档介绍Java、PythonGo语言的索引表操作相关SDK。

相关依赖

Java

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-sdk-ha3engine-vector</artifactId>
    <version>1.1.15</version>
</dependency>

python

# Requires: Python >=3.6
pip install alibabacloud_ha3engine_vector==1.1.15

Go

go get github.com/aliyun/alibabacloud-ha3-go-sdk@v1.1.15-vector

参数说明

Java、Python SDK中都需要配置如下4个必要参数(endpointinstance_id、access_user_name、access_pass_word):

  • endpoint:私网/公网域名

可在实例详情页中网络信息和API入口查看:

image

开启公网访问后可以在本地通过公网域名(包含public的域名)调用实例,可以参考添加白名单配置访问的白名单IP。

若有ECS机器,可通过配置相同的交换机通过API域名调用实例。

  • instance_id:实例ID

image

  • access_user_name:用户名

  • access_pass_word:密码

用户名和密码可以在实例详情页中API入口处进行查看:(密码是购买实例时设置的,可以修改)

image.png

索引表列表

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.ListTablesResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class ListTables {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 索引表列表
     * @throws Exception
     */
    @Test
    public void listTables() throws Exception {
        try {
            ListTablesResponse response = client.listTables();
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def list_tables():
    result = client.list_tables()
    print(result.body)

if __name__ == "__main__":
    list_tables()

Go

package main

import (
    "fmt"
    "github.com/alibabacloud-go/tea/tea"
    ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
    //创建请求客户端实例
    config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

    // 初始化一个client, 用以发送请求.
    client, _clientErr := ha3engine.NewClient(config)

    // 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
    if _clientErr != nil {
        fmt.Println(_clientErr)
        return
    }
    listTables(client)
}

func listTables(client *ha3engine.Client) {
    response, _requestErr := client.ListTables()

    //如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
    if _requestErr != nil {
        fmt.Println(_requestErr)
        return
    }

    //输出正常返回的 response 内容.
    fmt.Println(response.Body)
}

索引表详情

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.GetTableResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class GetTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 索引表详情
     * @throws Exception
     */
    @Test
    public void getTable() throws Exception {
        try {
            // 表名称
            String tableName = "test";
            GetTableResponse response = client.getTable(tableName);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def get_table(table_name: str):
    result = client.get_table(table_name)
    print(result.body)

if __name__ == "__main__":
    get_table("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	getTable(client)
}

func getTable(client *ha3engine.Client) {
	response, _requestErr := client.GetTable(tea.String("test_api"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

创建索引表

接口可通过OpenAPI 门户调用。

数据源类型:api

Java

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.CreateTableRequest;
import com.aliyun.ha3engine.vector.models.CreateTableResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.models.RuntimeOptions;

import org.junit.Before;
import org.junit.Test;

public class CreateTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");

        RuntimeOptions runtimeOptions = new RuntimeOptions();
        runtimeOptions.setConnectTimeout(10000);
        runtimeOptions.setReadTimeout(10000);
        config.setRuntimeOptions(runtimeOptions);

        client = new Client(config);
    }
    /**
     * 建表,默认数据源类型为API
     * @throws Exception
     */
    @Test
    public void createTable() throws Exception {
        try {
            // 请求参数
            CreateTableRequest request = new CreateTableRequest();
            // 表名
            request.setName("test_api");
            // 主键
            request.setPrimaryKey("id");
            // 数据分片数
            request.setPartitionCount(1);
            // 字段配置
            Map<String, String> fieldSchema = new HashMap<String, String>(){{
                put("id", "STRING");
                put("name", "STRING");
                put("vector", "MULTI_FLOAT");
            }};
            request.setFieldSchema(fieldSchema);

            // 向量索引配置
            CreateTableRequest.CreateTableRequestVectorIndex vectorIndex = new CreateTableRequest.CreateTableRequestVectorIndex();
            // 向量索引名称
            vectorIndex.setIndexName("vector");
            // 向量字段
            vectorIndex.setVectorField("vector");
            // 向量维度
            vectorIndex.setDimension("2");
            // 向量索引算法
            vectorIndex.setVectorIndexType("Qc");
            // 向量索引距离类型
            vectorIndex.setDistanceType("InnerProduct");
            request.setVectorIndex(Collections.singletonList(vectorIndex));

            // 是否仅校验
            request.setDryRun(false);
            CreateTableResponse response = client.createTable(request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, CreateTableRequest, CreateTableRequestVectorIndex

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def create_table():
    # 请求参数
    request = CreateTableRequest()
    # 表名
    request.name = "test_api"
    # 主键
    request.primary_key = "id"
    # 数据分片数
    request.partition_count = 1
    # 字段配置
    request.field_schema = {
        "id": "INT32",
        "vector": "MULTI_FLOAT",
        "name": "STRING"
    }

    # 向量索引配置
    vector_index = CreateTableRequestVectorIndex()
    # 向量索引名称
    vector_index.index_name = "vector"
    # 向量字段
    vector_index.vector_field = "vector"
    # 向量维度
    vector_index.dimension = 2
    # 向量索引算法
    vector_index.vector_index_type = "HNSW"
    # 向量索引距离类型
    vector_index.distance_type = "InnerProduct"
    request.vector_index = [vector_index]

    result = client.create_table(request)
    print(result.body)

if __name__ == "__main__":
    create_table()

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	createTable(client)
}

func createTable(client *ha3engine.Client) {
	// 请求参数
	request := &ha3engine.CreateTableRequest{
		// 表名
		Name: tea.String("test_api"),
		// 主键
		PrimaryKey: tea.String("id"),
		// 数据分片数
		PartitionCount: tea.Int32(1),
	}

	// 字段配置
	fieldSchema := map[string]*string{
		"id":     tea.String("STRING"),
		"name":   tea.String("STRING"),
		"vector": tea.String("MULTI_FLOAT"),
	}
	request.FieldSchema = fieldSchema

	// 向量索引配置
	vectorIndex := &ha3engine.CreateTableRequestVectorIndex{
		// 向量索引名称
		IndexName: tea.String("vector"),
		// 向量字段
		VectorField: tea.String("vector"),
		// 向量维度
		Dimension: tea.String("2"),
		// 向量索引算法
		VectorIndexType: tea.String("Qc"),
		// 向量索引距离类型
		DistanceType: tea.String("InnerProduct"),
	}
	request.VectorIndex = []*ha3engine.CreateTableRequestVectorIndex{vectorIndex}

	response, _requestErr := client.CreateTable(request)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

数据源类型:oss

Java

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.CreateTableRequest;
import com.aliyun.ha3engine.vector.models.CreateTableResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.models.RuntimeOptions;

import org.junit.Before;
import org.junit.Test;

public class CreateTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");

        RuntimeOptions runtimeOptions = new RuntimeOptions();
        runtimeOptions.setConnectTimeout(10000);
        runtimeOptions.setReadTimeout(10000);
        config.setRuntimeOptions(runtimeOptions);

        client = new Client(config);
    }
    /**
     * 建表,数据源类型为oss
     * @throws Exception
     */
    @Test
    public void createOssTable() throws Exception {
        try {
            // 请求参数
            CreateTableRequest request = new CreateTableRequest();
            // 表名
            request.setName("test_oss");
            // 主键
            request.setPrimaryKey("id");
            // 数据分片数
            request.setPartitionCount(1);
            // 字段配置
            Map<String, String> fieldSchema = new HashMap<String, String>(){{
                put("id", "STRING");
                put("name", "STRING");
                put("vector", "MULTI_FLOAT");
            }};
            request.setFieldSchema(fieldSchema);

            // 向量索引配置
            CreateTableRequest.CreateTableRequestVectorIndex vectorIndex = new CreateTableRequest.CreateTableRequestVectorIndex();
            // 向量索引名称
            vectorIndex.setIndexName("vector");
            // 向量字段
            vectorIndex.setVectorField("vector");
            // 向量维度
            vectorIndex.setDimension("2");
            // 向量索引算法
            vectorIndex.setVectorIndexType("Qc");
            // 向量索引距离类型
            vectorIndex.setDistanceType("InnerProduct");
            request.setVectorIndex(Collections.singletonList(vectorIndex));

            // 数据源配置
            CreateTableRequest.CreateTableRequestDataSource dataSource = new CreateTableRequest.CreateTableRequestDataSource();
            // 数据源类型
            dataSource.setType("oss");
            CreateTableRequest.CreateTableRequestDataSourceConfig config = new CreateTableRequest.CreateTableRequestDataSourceConfig();
            // oss路径
            config.setOssPath("<oss_path>");
            // oss bucket名称
            config.setBucket("<oss_bucket_name>");
            // endpoint:必须设置,validator会判断区域信息是否与当前区域相同
            config.setEndpoint("<endpoint>");
            dataSource.setConfig(config);
            request.setDataSource(dataSource);

            // 是否仅校验
            request.setDryRun(false);
            CreateTableResponse response = client.createTable(request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, CreateTableRequest, CreateTableRequestVectorIndex, CreateTableRequestDataSource, CreateTableRequestDataSourceConfig

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def create_oss_table():
    # 请求参数
    request = CreateTableRequest()
    # 表名
    request.name = "test_oss"
    # 主键
    request.primary_key = "id"
    # 数据分片数
    request.partition_count = 1
    # 字段配置
    request.field_schema = {
        "id": "INT32",
        "vector": "MULTI_FLOAT",
        "name": "STRING"
    }

    # 向量索引配置
    vector_index = CreateTableRequestVectorIndex()
    # 向量索引名称
    vector_index.index_name = "vector"
    # 向量字段
    vector_index.vector_field = "vector"
    # 向量维度
    vector_index.dimension = 2
    # 向量索引算法
    vector_index.vector_index_type = "HNSW"
    # 向量索引距离类型
    vector_index.distance_type = "InnerProduct"
    request.vector_index = [vector_index]

    # 数据源配置
    data_source = CreateTableRequestDataSource()
    # 数据源类型
    data_source.type = "oss"
    config = CreateTableRequestDataSourceConfig()
    # oss路径
    config.oss_path = "<oss_path>"
    # oss bucket名称
    config.bucket = "<oss_bucket>"
    # endpoint:必须设置,validator会判断区域信息是否与当前区域相同
    config.endpoint = "<oss_endpoint>"
    data_source.config = config
    request.data_source = data_source

    result = client.create_table(request)
    print(result.body)

if __name__ == "__main__":
    create_oss_table()

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	createOssTable(client)
}

func createOssTable(client *ha3engine.Client) {
	// 请求参数
	request := &ha3engine.CreateTableRequest{
		// 表名
		Name: tea.String("test_oss"),
		// 主键
		PrimaryKey: tea.String("id"),
		// 数据分片数
		PartitionCount: tea.Int32(1),
	}

	// 字段配置
	fieldSchema := map[string]*string{
		"id":     tea.String("STRING"),
		"name":   tea.String("STRING"),
		"vector": tea.String("MULTI_FLOAT"),
	}
	request.FieldSchema = fieldSchema

	// 向量索引配置
	vectorIndex := &ha3engine.CreateTableRequestVectorIndex{
		// 向量索引名称
		IndexName: tea.String("vector"),
		// 向量字段
		VectorField: tea.String("vector"),
		// 向量维度
		Dimension: tea.String("2"),
		// 向量索引算法
		VectorIndexType: tea.String("Qc"),
		// 向量索引距离类型
		DistanceType: tea.String("InnerProduct"),
	}
	request.VectorIndex = []*ha3engine.CreateTableRequestVectorIndex{vectorIndex}

	// 数据源配置config
	config := &ha3engine.CreateTableRequestDataSourceConfig{
		// oss路径
		OssPath: tea.String("<oss_path>"),
		// OSS Bucket 名称
		Bucket: tea.String("<oss_bucket_name>"),
		// endpoint:必须设置,validator会判断区域信息是否与当前区域相同
		Endpoint: tea.String("<endpoint>"),
	}
	// 数据源配置
	dataSource := &ha3engine.CreateTableRequestDataSource{
		// 数据源类型
		Type:   tea.String("oss"),
		Config: config,
	}
	request.DataSource = dataSource

	response, _requestErr := client.CreateTable(request)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

数据源类型:MaxCompute

Java

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.CreateTableRequest;
import com.aliyun.ha3engine.vector.models.CreateTableResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.models.RuntimeOptions;

import org.junit.Before;
import org.junit.Test;

public class CreateTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");

        RuntimeOptions runtimeOptions = new RuntimeOptions();
        runtimeOptions.setConnectTimeout(10000);
        runtimeOptions.setReadTimeout(10000);
        config.setRuntimeOptions(runtimeOptions);

        client = new Client(config);
    }
    /**
     * 建表,数据源类型为MaxCompute
     * @throws Exception
     */
    @Test
    public void createMaxComputeTable() throws Exception {
        try {
            // 请求参数
            CreateTableRequest request = new CreateTableRequest();
            // 表名
            request.setName("test_odps");
            // 主键
            request.setPrimaryKey("id");
            // 数据分片数
            request.setPartitionCount(1);
            // 字段配置
            Map<String, String> fieldSchema = new HashMap<String, String>(){{
                put("id", "STRING");
                put("name", "STRING");
                put("vector", "MULTI_FLOAT");
            }};
            request.setFieldSchema(fieldSchema);

            // 向量索引配置
            CreateTableRequest.CreateTableRequestVectorIndex vectorIndex = new CreateTableRequest.CreateTableRequestVectorIndex();
            // 向量索引名称
            vectorIndex.setIndexName("vector");
            // 向量字段
            vectorIndex.setVectorField("vector");
            // 向量维度
            vectorIndex.setDimension("2");
            // 向量索引算法
            vectorIndex.setVectorIndexType("Qc");
            // 向量索引距离类型
            vectorIndex.setDistanceType("InnerProduct");
            request.setVectorIndex(Collections.singletonList(vectorIndex));

            // 数据源配置
            CreateTableRequest.CreateTableRequestDataSource dataSource = new CreateTableRequest.CreateTableRequestDataSource();
            // 数据源类型
            dataSource.setType("odps");
            CreateTableRequest.CreateTableRequestDataSourceConfig config = new CreateTableRequest.CreateTableRequestDataSourceConfig();
            // AccessKey,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
            config.setAccessKey(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"));
            // AccessSecret,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
            config.setAccessSecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            // odps项目名
            config.setProject("<odps_project_name>");
            // odps表名
            config.setTable("<odps_table_name>");
            // odps表数据分区
            config.setPartition("<odps_partition>");
            dataSource.setConfig(config);
            request.setDataSource(dataSource);

            // 是否仅校验
            request.setDryRun(false);
            CreateTableResponse response = client.createTable(request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, CreateTableRequest, CreateTableRequestVectorIndex, CreateTableRequestDataSource, CreateTableRequestDataSourceConfig

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def create_odps_table():
    # 请求参数
    request = CreateTableRequest()
    # 表名
    request.name = "test_odps1"
    # 主键
    request.primary_key = "id"
    # 数据分片数
    request.partition_count = 1
    # 字段配置
    request.field_schema = {
        "id": "INT32",
        "vector": "MULTI_FLOAT",
        "name": "STRING"
    }

    # 向量索引配置
    vector_index = CreateTableRequestVectorIndex()
    # 向量索引名称
    vector_index.index_name = "vector"
    # 向量字段
    vector_index.vector_field = "vector"
    # 向量维度
    vector_index.dimension = 2
    # 向量索引算法
    vector_index.vector_index_type = "HNSW"
    # 向量索引距离类型
    vector_index.distance_type = "InnerProduct"
    request.vector_index = [vector_index]

    # 数据源配置
    data_source = CreateTableRequestDataSource()
    # 数据源类型
    data_source.type = "odps"
    config = CreateTableRequestDataSourceConfig()
    # AccessKey,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
    config.access_key = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
    # AccessSecret,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    config.access_secret = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    # odps项目名
    config.project = "<odps_project_name>"
    # odps表名
    config.table = "<odps_table_name>"
    # odps表数据分区
    config.partition = "<odps_partition>"
    data_source.config = config
    request.data_source = data_source

    result = client.create_table(request)
    print(result.body)

if __name__ == "__main__":
    create_odps_table()

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
    "os"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	createOdpsTable(client)
}

func createOdpsTable(client *ha3engine.Client) {
	// 请求参数
	request := &ha3engine.CreateTableRequest{
		// 表名
		Name: tea.String("test_odps"),
		// 主键
		PrimaryKey: tea.String("id"),
		// 数据分片数
		PartitionCount: tea.Int32(1),
	}

	// 字段配置
	fieldSchema := map[string]*string{
		"id":     tea.String("STRING"),
		"name":   tea.String("STRING"),
		"vector": tea.String("MULTI_FLOAT"),
	}
	request.FieldSchema = fieldSchema

	// 向量索引配置
	vectorIndex := &ha3engine.CreateTableRequestVectorIndex{
		// 向量索引名称
		IndexName: tea.String("vector"),
		// 向量字段
		VectorField: tea.String("vector"),
		// 向量维度
		Dimension: tea.String("2"),
		// 向量索引算法
		VectorIndexType: tea.String("Qc"),
		// 向量索引距离类型
		DistanceType: tea.String("InnerProduct"),
	}
	request.VectorIndex = []*ha3engine.CreateTableRequestVectorIndex{vectorIndex}

	// 数据源配置config
	config := &ha3engine.CreateTableRequestDataSourceConfig{
		// AccessKey,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
		AccessKey:    tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
		// AccessSecret,必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
		AccessSecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
		// odps项目名
		Project: tea.String("<odps_project>"),
		// odps表名
		Table: tea.String("<odps_table>"),
		// odps表数据分区
		Partition: tea.String("<odps_partition>"),
	}
	// 数据源配置
	dataSource := &ha3engine.CreateTableRequestDataSource{
		// 数据源类型
		Type:   tea.String("odps"),
		Config: config,
	}
	request.DataSource = dataSource

	response, _requestErr := client.CreateTable(request)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

编辑索引表

接口可通过OpenAPI 门户调用。

Java

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.*;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class ModifyTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 编辑表
     * @throws Exception
     */
    @Test
    public void modifyTable() throws Exception {
        try {
            // 请求参数
            ModifyTableRequest request = new ModifyTableRequest();
            // 主键
            request.setPrimaryKey("id");
            // 数据分片数
            request.setPartitionCount(1);
            // 字段配置
            Map<String, String> fieldSchema = new HashMap<String, String>(){{
                put("id", "STRING");
                put("name", "STRING");
                put("vector", "MULTI_FLOAT");
                put("age", "INT32");
            }};
            request.setFieldSchema(fieldSchema);

            // 向量索引配置
            ModifyTableRequest.ModifyTableRequestVectorIndex vectorIndex = new ModifyTableRequest.ModifyTableRequestVectorIndex();
            // 向量索引名称
            vectorIndex.setIndexName("vector");
            // 向量字段
            vectorIndex.setVectorField("vector");
            // 向量维度
            vectorIndex.setDimension("2");
            // 向量索引算法
            vectorIndex.setVectorIndexType("Qc");
            // 向量索引距离类型
            vectorIndex.setDistanceType("InnerProduct");
            request.setVectorIndex(Collections.singletonList(vectorIndex));

            ModifyTableResponse response = client.modifyTable("test_api", request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, ModifyTableRequest, ModifyTableRequestVectorIndex

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def modify_table():
    # 请求参数
    request = ModifyTableRequest()
    # request.dry_run = True
    # 主键
    request.primary_key = "id"
    # 数据分片数
    request.partition_count = 1
    # 字段配置
    request.field_schema = {
        "id": "INT32",
        "vector": "MULTI_FLOAT",
        "name": "STRING",
        "age": "INT32"
    }

    # 向量索引配置
    vector_index = ModifyTableRequestVectorIndex()
    # 向量索引名称
    vector_index.index_name = "vector"
    # 向量字段
    vector_index.vector_field = "vector"
    # 向量维度
    vector_index.dimension = 2
    # 向量索引算法
    vector_index.vector_index_type = "HNSW"
    # 向量索引距离类型
    vector_index.distance_type = "InnerProduct"
    request.vector_index = [vector_index]

    result = client.modify_table("test_api", request)
    print(result.body)

if __name__ == "__main__":
    modify_table()

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	modifyTable(client)
}

func modifyTable(client *ha3engine.Client) {
	// 请求参数
	request := &ha3engine.ModifyTableRequest{
		// 主键
		PrimaryKey: tea.String("id"),
		// 数据分片数
		PartitionCount: tea.Int32(1),
	}

	// 字段配置
	fieldSchema := map[string]*string{
		"id":     tea.String("STRING"),
		"name":   tea.String("STRING"),
		"vector": tea.String("MULTI_FLOAT"),
		"age":    tea.String("INT32"),
	}
	request.FieldSchema = fieldSchema

	// 向量索引配置
	vectorIndex := &ha3engine.ModifyTableRequestVectorIndex{
		// 向量索引名称
		IndexName: tea.String("vector"),
		// 向量字段
		VectorField: tea.String("vector"),
		// 向量维度
		Dimension: tea.String("2"),
		// 向量索引算法
		VectorIndexType: tea.String("Qc"),
		// 向量索引距离类型
		DistanceType: tea.String("InnerProduct"),
	}
	request.VectorIndex = []*ha3engine.ModifyTableRequestVectorIndex{vectorIndex}

	response, _requestErr := client.ModifyTable(tea.String("test_api"), request)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

索引重建

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.ReindexRequest;
import com.aliyun.ha3engine.vector.models.ReindexResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class ReIndex {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 索引重建
     * @throws Exception
     */
    @Test
    public void reindex() throws Exception {
        try {
            ReindexRequest request = new ReindexRequest();
            // 时间戳
            request.setDataTimeSec(1741231869);
            ReindexResponse response = client.reindex("test_api", request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, ReindexRequest

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def reindex(table_name: str):
    request = ReindexRequest()
    # 时间戳
    request.data_time_sec = 1741231869
    result = client.reindex(table_name, request)
    print(result.body)

if __name__ == "__main__":
    reindex("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	reindex(client)
}

func reindex(client *ha3engine.Client) {
	reindexRequest := &ha3engine.ReindexRequest{}
    // 时间戳
	reindexRequest.DataTimeSec = tea.Int32(1741231869)
	response, _requestErr := client.Reindex(tea.String("test_api"), reindexRequest)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

停止使用索引表

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.StopTableResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class StopTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 停止使用
     * @throws Exception
     */
    @Test
    public void stopTable() throws Exception {
        try {
            StopTableResponse response = client.stopTable("test_api");
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def stop_table(table_name: str):
    result = client.stop_table(table_name)
    print(result.body)

if __name__ == "__main__":
    stop_table("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	stopTable(client)
}

func stopTable(client *ha3engine.Client) {
	response, _requestErr := client.StopTable(tea.String("test_api"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

恢复使用索引表

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.StartTableResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class StartTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 恢复使用
     * @throws Exception
     */
    @Test
    public void startTable() throws Exception {
        try {
            StartTableResponse response = client.startTable("test_api");
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def start_table(table_name: str):
    result = client.start_table(table_name)
    print(result.body)

if __name__ == "__main__":
    start_table("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	startTable(client)
}

func startTable(client *ha3engine.Client) {
	response, _requestErr := client.StartTable(tea.String("test_api"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

删除索引表

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.DeleteTableResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class DeleteTable {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 删除表
     * @throws Exception
     */
    @Test
    public void deleteTable() throws Exception {
        try {
            DeleteTableResponse response = client.deleteTable("test_api");
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def delete_table(table_name: str):
    result = client.delete_table(table_name)
    print(result.body)

if __name__ == "__main__":
    delete_table("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	deleteTable(client)
}

func deleteTable(client *ha3engine.Client) {
	response, _requestErr := client.DeleteTable(tea.String("test_api"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

获取索引版本列表

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.ListTableGenerationsResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class ListTableGenerations {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 获取索引版本列表
     * @throws Exception
     */
    @Test
    public void listTableGenerations() throws Exception {
        try {
            ListTableGenerationsResponse response = client.listTableGenerations("test_api");
            System.out.println(response.getBody().getRequestId());
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def list_table_generations(table_name: str):
    result = client.list_table_generations(table_name)
    print(result.body)

if __name__ == "__main__":
    list_table_generations("test_api")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	listTableGenerations(client)
}

func listTableGenerations(client *ha3engine.Client) {
	response, _requestErr := client.ListTableGenerations(tea.String("test"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

根据generationId获取表索引版本状态

接口可通过OpenAPI 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.GetTableGenerationResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class GetTableGeneration {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 根据generationId获取表索引版本状态
     * @throws Exception
     */
    @Test
    public void getTableGeneration() throws Exception {
        try {
            GetTableGenerationResponse response = client.getTableGeneration("table_name", "1742520880");
            System.out.println(response.getBody().getRequestId());
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def get_table_generation(table_name: str, generation_id: str):
    result = client.get_table_generation(table_name, generation_id)
    print(result.body)

if __name__ == "__main__":
    get_table_generation("test_api", "1742453479")

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	getTableGeneration(client)
}

func getTableGeneration(client *ha3engine.Client) {
	response, _requestErr := client.GetTableGeneration(tea.String("test"), tea.String("1742349911"))

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}

获取变更历史

接口可通过OpenApi 门户调用。

Java

import com.aliyun.ha3engine.vector.Client;
import com.aliyun.ha3engine.vector.models.Config;
import com.aliyun.ha3engine.vector.models.ListTasksRequest;
import com.aliyun.ha3engine.vector.models.ListTasksResponse;
import com.aliyun.tea.TeaException;

import org.junit.Before;
import org.junit.Test;

public class ListTasks {

    /**
     * 问天引擎client
     */
    private static Client client;

    @Before
    public void initClient() throws Exception {
        Config config = new Config();
        // 用户名,可在实例详情页>API入口 查看
        config.setAccessUserName("username");
        // 密码,可在实例详情页>API入口 修改
        config.setAccessPassWord("password");
        // API域名,可在实例详情页>API入口 查看
        config.setEndpoint("http://ha-cn-i7*****605.public.ha.aliyuncs.com");
        client = new Client(config);
    }

    /**
     * 获取变更历史
     * @throws Exception
     */
    @Test
    public void startTable() throws Exception {
        try {
            // 请求参数
            ListTasksRequest request = new ListTasksRequest();
            // 开始时间戳
            request.setStart(1741331885L);
            // 结束时间戳
            request.setEnd(1742521261750L);
            ListTasksResponse response = client.listTasks(request);
            System.out.println(com.aliyun.teautil.Common.toJSONString(response.getBody()));
        } catch (TeaException e) {
            System.out.println(e.getCode());
            System.out.println(e.getMessage());
        }
    }
}

Python

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config, ListTasksRequest

config = Config(
    # API域名,可在实例详情页>API入口 查看
    endpoint="http://ha-cn-i7*****605.public.ha.aliyuncs.com",
    # 用户名,可在实例详情页>API入口 查看
    access_user_name="username",
    # 密码,可在实例详情页>API入口 修改
    access_pass_word="password")
client = Client(config)

def list_tasks():
    # 请求参数
    request = ListTasksRequest()
    # 开始时间戳
    request.start = 1741331885
    # 结束时间戳
    request.end = 1742521261750
    result = client.list_tasks(request)
    print(result.body)


if __name__ == "__main__":
    list_tasks()

Go

package main

import (
	"fmt"
	"github.com/alibabacloud-go/tea/tea"
	ha3engine "github.com/aliyun/alibabacloud-ha3-go-sdk/client"
)

func main() {
	//创建请求客户端实例
	config := &ha3engine.Config{
		// API域名,可在实例详情页>API入口 查看
		Endpoint: tea.String("http://ha-cn-i7*****605.public.ha.aliyuncs.com"),
		// 用户名,可在实例详情页>API入口 查看
		AccessUserName: tea.String("username"),
		// 密码,可在实例详情页>API入口 修改
		AccessPassWord: tea.String("password"),
	}

	// 初始化一个client, 用以发送请求.
	client, _clientErr := ha3engine.NewClient(config)

	// 如果 NewClient 过程中出现异常. 则 返回 _clientErr 且输出 错误信息.
	if _clientErr != nil {
		fmt.Println(_clientErr)
		return
	}
	listTasks(client)
}

func listTasks(client *ha3engine.Client) {
	request := &ha3engine.ListTasksRequest{}
    // 开始时间戳
	request.Start = tea.Int64(1741331885)
    // 结束时间戳
	request.End = tea.Int64(1742521261750)
	response, _requestErr := client.ListTasks(request)

	//如果 发送请求 过程中出现异常. 则 返回 _requestErr 且输出 错误信息.
	if _requestErr != nil {
		fmt.Println(_requestErr)
		return
	}

	//输出正常返回的 response 内容.
	fmt.Println(response.Body)
}