update_doc 用于更新某个文档信息如文档标题,文档信息更新会自动触发索引中的数据更新。
参数 | 子参数 | 类型 | 是否必选 | 默认值 | 参数说明 |
|---|---|---|---|---|---|
collectionName | -- | String | 否 | -- | 知识库名称 |
projectName | -- | String | 否 | default | 知识库所属项目,获取方式参见文档API 接入与技术支持 |
resourceId | -- | String | 否 | -- | 知识库唯一 id |
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)); } }