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

向量数据库VikingDB

复制全文
下载 pdf
文档(Doc)
list_docs
复制全文
下载 pdf
list_docs
概述

list_docs 用于查询知识库上文档的列表,默认按照文档的上传时间倒序。

请求参数
参数子参数类型是否必选默认值参数说明
collectionName--String否--知识库名称

projectName

--

String

否

default

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

resourceId

--

String

否

--

知识库唯一 ID
可通过创建知识库接口的返回值或知识库列表接口获取
可选择直接传 resourceId,或同时传 collectionName 和 projectName 作为知识库的唯一标识

filter

Map<String, Object>

否

--

过滤条件
用于对返回结果进行过滤,支持使用 docId 过滤

docIdList

String[]

否

--

指定 docId 过滤条件
只返回列表中指定的文档信息

offset

--

Integer

否

0

查询起始位置
表示从结果的第几个文档后开始取,需要大于等于 0

limit

--

Integer

否

-1

查询文档数
不传或传入 -1 时均按默认值 100 处理;显式传值时取值范围为 [1, 1000]

docType--String否--文档类型筛选

returnTokenUsage

--

Boolean

否

false

是否返回文档向量化和文档摘要生成所消耗的 tokens

  • true:返回 token 用量信息;false:不返回 token 用量信息
响应消息
字段类型参数说明
codeInteger状态码
messageString返回信息
requestIdString标识每个请求的唯一标识符
dataListDocsResultListDocsResult

ListDocsResult

字段类型参数说明
docListList文档信息列表
countInteger本次查询返回的文档总数
totalNumInteger该知识库下的文档总数

DocInfo

字段类型参数说明
collectionNameString知识库名称
docNameString文档名称
docIdString文档 id
docHashString文档 hash
addTypeString导入方式
docTypeString文档类型
descriptionString文档描述(当前仅支持图片文档)
createTimeLong文档创建时间
addedByString添加人
updateTimeLong文档更新时间
urlString原始文档链接
tosPathStringtos 路径
pointNumInteger切片数量
statusDocStatusDocStatus
titleString文档标题
sourceString知识来源(url,tos 等)
totalTokensObjecttokens 统计
docSummaryTokensInteger摘要 tokens 统计
docPremiumStatusDocPremiumStatusDocPremiumStatus
docSummaryString文档摘要
briefSummaryString简要摘要
docSizeInteger文档大小
metaStringmeta 信息
labelsMap<String, String>标签信息
videoOutlineMap<String, Object>视频大纲
audioOutlineMap<String, Object>音频大纲
statisticsMap<String, Object>统计信息
projectString项目名
resourceIdString知识库唯一 id

DocStatus

字段类型参数说明
processStatusInteger处理状态
failedCodeInteger失败错误码
failedMsgString失败错误信息

DocPremiumStatus

字段类型参数说明
docSummaryStatusCodeInteger
状态码说明
状态码HTTP 状态码返回信息状态码说明
0200success成功
1000001401unauthorized鉴权失败
1000002403no permission权限不足
1000003400invalid request: %s非法参数
1000005400collection not existcollection 不存在
请求示例

首次使用知识库 SDK,可参考 使用说明
本示例演示了知识库 Java SDK 中 ListDocs 的基础使用方法,通过指定知识库信息实现文档列表查询,使用前需配置 API Key 鉴权参数(VIKING_API_KEY)。

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

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.request.ListDocsRequest;
import com.volcengine.vikingdb.runtime.knowledge.model.response.ListDocsResponse;
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 = "";

    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);
        KnowledgeService service = newKnowledgeService(auth);
        KnowledgeCollectionClient kc = service.collection(defaultCollectionMeta());

        ListDocsRequest req = ListDocsRequest.builder()
                .offset(0)
                .limit(10)
                .returnTokenUsage(true)
                .build();

        ListDocsResponse resp = kc.listDocs(req, new RequestAddition());
        printJson("list_docs", 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.09.08 20:33:19
这个页面对您有帮助吗?
有用
有用
无用
无用