You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
文档(Doc)
update_doc
复制全文
下载 pdf
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 和新文档名称实现文档名称修改,使用前需配置 API Key 鉴权参数(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.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 {
        String apiKey = getEnv("VIKING_API_KEY");
        if (apiKey.isEmpty()) {
            System.out.println("missing_auth: set VIKING_API_KEY");
            return;
        }
        Auth auth = new AuthWithApiKey(apiKey);
        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 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.04.10 18:03:32
这个页面对您有帮助吗?
有用
有用
无用
无用