You need to enable JavaScript to run this app.
向量数据库VikingDB

向量数据库VikingDB

复制全文
文档(Doc)
update_doc
复制全文
update_doc

概述

update_doc 用于更新某个文档信息如文档标题,文档信息更新会自动触发索引中的数据更新。

请求参数

参数

子参数

类型

是否必选

默认值

参数说明

collectionName

--

String

--

知识库名称

projectName

--

String

default

知识库所属项目,获取方式参见文档API 接入与技术支持
若需要操作指定项目下的知识库,需正确配置该字段。

resourceId

--

String

--

知识库唯一 id
可选择直接传 ResourceID,或同时传 CollectionName 和 ProjectName 作为知识库的唯一标识

docId

--

String

--

待更新文档的 id

docName

--

String

--

更新后的文档名称

响应消息

字段

类型

参数说明

code

Integer

状态码

message

String

返回信息

requestId

String

标识每个请求的唯一标识符

状态码说明

状态码

http 状态码

返回信息

状态码说明

0

200

success

成功

1000001

401

unauthorized

鉴权失败

1000002

403

no permission

权限不足

1000003

400

invalid request:%s

非法参数

1000005

400

collection not exist

collection不存在

1001001

400

doc not exist

doc不存在

1000028

500

internal error

内部错误

请求示例

首次使用知识库 SDK ,可参考 使用说明
本示例演示了知识库 Java SDK 中 UpdateDoc 的基础使用方法,通过指定文档 ID 和新文档名称实现文档名称修改,使用前需配置鉴权参数(VOLC_AK/VOLC_SK 或 VIKING_API_KEY)。

package com.volcengine.vikingdb.runtime.knowledge.examples.doc_update;

import com.fasterxml.jackson.databind.ObjectWriter;
import com.volcengine.vikingdb.runtime.core.ApiClient;
import com.volcengine.vikingdb.runtime.core.RequestAddition;
import com.volcengine.vikingdb.runtime.core.auth.Auth;
import com.volcengine.vikingdb.runtime.core.auth.AuthWithAkSk;
import com.volcengine.vikingdb.runtime.core.auth.AuthWithApiKey;
import com.volcengine.vikingdb.runtime.enums.Scheme;
import com.volcengine.vikingdb.runtime.knowledge.model.CollectionMeta;
import com.volcengine.vikingdb.runtime.knowledge.model.response.BaseResponse;
import com.volcengine.vikingdb.runtime.knowledge.service.KnowledgeCollectionClient;
import com.volcengine.vikingdb.runtime.knowledge.service.KnowledgeService;

public class Main {
    private static final ObjectWriter PRETTY_JSON = ApiClient.objectMapper.writerWithDefaultPrettyPrinter();
    private static final Scheme SCHEME = Scheme.HTTPS;
    private static final String HOST = "api-knowledgebase.mlp.cn-beijing.volces.com";
    private static final String REGION = "cn-beijing";
    private static final String PROJECT = "default";
    private static final String COLLECTION_NAME = "your_collection_name";
    private static final String COLLECTION_RESOURCE_ID = "";
    private static final String DOC_ID = "your_doc_id";

    public static void main(String[] args) throws Exception {
        Auth auth = preferAuth();
        if (auth == null) {
            System.out.println("missing_auth: set VOLC_AK/VOLC_SK or VIKING_API_KEY");
            return;
        }
        String newDocName = "your_new_doc_name";

        KnowledgeService service = newKnowledgeService(auth);
        KnowledgeCollectionClient kc = service.collection(defaultCollectionMeta());

        BaseResponse resp = kc.updateDoc(DOC_ID, newDocName, new RequestAddition());
        printJson("update_doc", resp);
    }

    private static KnowledgeService newKnowledgeService(Auth auth) {
        return new KnowledgeService(SCHEME, HOST, REGION, auth);
    }

    private static Auth preferAuth() {
        String ak = getEnv("VOLC_AK");
        String sk = getEnv("VOLC_SK");
        if (!ak.isEmpty() && !sk.isEmpty()) {
            return new AuthWithAkSk(ak, sk);
        }
        String apiKey = getEnv("VIKING_API_KEY");
        if (!apiKey.isEmpty()) {
            return new AuthWithApiKey(apiKey);
        }
        return null;
    }

    private static CollectionMeta defaultCollectionMeta() {
        return CollectionMeta.builder()
                .collectionName(COLLECTION_NAME)
                .projectName(PROJECT)
                .resourceId(COLLECTION_RESOURCE_ID)
                .build();
    }

    private static String getEnv(String name) {
        String v = System.getenv(name);
        if (v == null) {
            return "";
        }
        v = v.trim();
        return v.isEmpty() ? "" : v;
    }

    private static void printJson(String name, Object obj) throws Exception {
        if (obj == null) {
            System.out.println(name + ": null");
            return;
        }
        System.out.println(name + ": " + PRETTY_JSON.writeValueAsString(obj));
    }
}
最近更新时间:2026.03.26 17:20:14
这个页面对您有帮助吗?
有用
有用
无用
无用