全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

管理向量存储空间

最近更新时间:2026-11-05 15:15:23

创建向量存储空间

/**
 * 创建向量存储空间
 *
 * <p>桶名限制:3-63 个字符,仅支持小写字母、数字和连字符,且须以字母或数字开头和结尾。</p>
 */
public void createVectorBucket() {
    // 初始化向量客户端,详见“初始化”文档
    Ks3VectorsClient client = initVectorsClient();
    String bucketName = "my-vector-bucket";
    try {
        CreateVectorBucketResult result = client.createVectorBucket(
                new CreateVectorBucketRequest(bucketName));
        System.out.println("向量桶创建成功: " + bucketName);
        System.out.println("vectorBucketKrn: " + result.getVectorBucketKrn());
        System.out.println("requestId: " + result.getRequestId());
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException: " + e.getErrorMessage()
                + ", code=" + e.getErrorCode() + ", status=" + e.getStatusCode()
                + ", requestId=" + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException: " + e.getMessage());
    } finally {
        // 不再使用时,须关闭 client
        client.shutdown();
    }
}

查看向量存储空间

/**
 * 获取向量存储空间详细信息
 */
public void getVectorBucket() {
    // 初始化向量客户端,详见“初始化”文档
    Ks3VectorsClient client = initVectorsClient();
    String bucketName = "my-vector-bucket";
    try {
        GetVectorBucketResult result = client.getVectorBucket(
                new GetVectorBucketRequest(bucketName));
        VectorBucket bucket = result.getVectorBucket();
        if (bucket != null) {
            System.out.println("桶名: " + bucket.getVectorBucketName());
            System.out.println("KRN: " + bucket.getVectorBucketKrn());
            System.out.println("地域: " + bucket.getLocation());
            System.out.println("创建时间(ms): " + bucket.getCreationTime());
        }
    } catch (Ks3ServiceException e) {
        if (e.getStatusCode() == 404) {
            System.out.println("向量桶不存在");
        } else {
            System.out.println("Ks3ServiceException: " + e.getErrorMessage()
                    + ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
        }
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException: " + e.getMessage());
    } finally {
        // 不再使用时,须关闭 client
        client.shutdown();
    }
}

列举向量存储空间

/**
 * 列举当前账号下全部地域向量存储空间(串行分页)
 *
 * <p>服务级接口,{@code nextToken} 为空表示已到最后一页。{@code maxResults} 每页最大 500。</p>
 */
public void listVectorBuckets() {
    // 初始化向量客户端,详见“初始化”文档
    Ks3VectorsClient client = initVectorsClient();
    try {
        String nextToken = null;
        int pageIndex = 1;
        do {
            ListVectorBucketsResult result = client.listVectorBuckets(
                    new ListVectorBucketsRequest()
                            .withMaxResults(500)
                            .withNextToken(nextToken));
            List<VectorBucket> buckets = result.getVectorBuckets();
            System.out.println("第 " + pageIndex + " 页,本页数量: "
                    + (buckets == null ? 0 : buckets.size()));
            if (buckets != null) {
                for (VectorBucket b : buckets) {
                    System.out.println("  " + b.getVectorBucketName()
                            + " (krn=" + b.getVectorBucketKrn() + ")");
                }
            }
            nextToken = result.getNextToken();
            pageIndex++;
        } while (nextToken != null && !nextToken.isEmpty());
        System.out.println("列举完成");
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException: " + e.getErrorMessage()
                + ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException: " + e.getMessage());
    } finally {
        // 不再使用时,须关闭 client
        client.shutdown();
    }
}

删除向量存储空间

/**
 * 删除向量存储空间
 *
 * <p>前置条件:桶下所有索引须先删除,否则删除失败。</p>
 */
public void deleteVectorBucket() {
    // 初始化向量客户端,详见“初始化”文档
    Ks3VectorsClient client = initVectorsClient();
    String bucketName = "my-vector-bucket";
    try {
        Ks3Result result = client.deleteVectorBucket(
                new DeleteVectorBucketRequest(bucketName));
        System.out.println("向量桶删除成功: " + bucketName + ", requestId=" + result.getRequestId());
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException: " + e.getErrorMessage()
                + ", status=" + e.getStatusCode() + ", requestId=" + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException: " + e.getMessage());
    } finally {
        // 不再使用时,须关闭 client
        client.shutdown();
    }
}
文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈