Skip to content

知识库管理接口

约 1362 字大约 5 分钟

2025-06-13

注意1:baseurl为 https://c4ai.ccccltd.cn/api

获取token 请参考系统集成开发-第三方系统集成助手,获取access_token,在调用后续接口时,需要在header中加入: Fusion-Auth: <access_token>。

创建知识库

接口路径: /kb/add
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

{
  "name": "知识库名称", //必填
  "description": "知识库描述",
  "language": "Chinese", //默认值为Chinese
  "parserConfig": {
    "chunk_token_num": 256, //文档解析分块大小,默认值为256
    "delimiter": "/", //分隔符
  },
  "parserId": "general" //默认值为general,即一般分快方法,c4parser为交融解析器
}

响应参数

{
  "code": 8000000,
  "message": "SUCCESS",
  "data": {
    "id": 1932695581712027600,
    "createDate": null,
    "updateDate": null,
    "createBy": null,
    "updateBy": null,
    "kbId": "692bb3c4469211f0ad370242ac160002",
    "name": "hello",
    "description": "",
    "language": "Chinese",
    "parserId": "general",
    "parserConfig": "{\"chunk_token_num\":\"256\",\"layout_recognize\":\"true\"}",
    "status": 0,
    "userId": null,
    "countFile": 0
  }
}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/add \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '{
  "description": "",
  "language": "Chinese",
  "name": "hello",
  "parserConfig": {
    "chunk_token_num": 256,
    "layout_recognize": "DeepDOC",
  },
  "status": 1,
  "parserId": "general"
}'

修改知识库

接口路径: /kb/update
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

{
  "kbId": "e839178e469111f0ad370242ac160002", //必须
  "name": "知识库名称", //必传(修改后的名称,必须与原名不一致)
  "description": "好的",
  "language": "Chinese",
  "parserConfig": {
    "chunk_token_num": "256",
  },
  "parserId": "general", //默认值为general,即一般分快方法,c4parser为交融解析器
  "id": "1932694674987745281"
}

响应参数

{"code":8000000,"message":"SUCCESS","data":null}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/update \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '{
  "description": "好的",
  "language": "Chinese",
  "name": "hello",
  "parserConfig": {
    "chunk_token_num": "256",
    "layout_recognize": "DeepDOC",
  },
  "status": 1,
  "parserId": "general",
  "kbId": "e839178e469111f0ad370242ac160002",
  "id": "1932694674987745281"
}'

删除知识库

接口路径: /kb/delete
请求方式: GET
Content-Type: application/json;charset=UTF-8

请求参数

参数名类型必填说明
idString知识库ID

响应参数

{
    "code": 8000000,
    "message": "success",
    "data": null
}

调用示例

curl --request GET \
  --url 'http://localhost:8080/kb/delete?id=1929825565087756290' \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS'

## 分页获取知识库列表

接口路径: /kb/getList
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

{
    "pageNum": 1,              // 必填,页码
    "pageSize": 10,            // 必填,每页大小
    "name": "知识库名称",        // 选填,搜索条件,模糊匹配
}

响应参数

{
    "code": 8000000,
    "message": "SUCCESS",
    "data": {
        "pageSize": 9,
        "pageNum": 1,
        "total": 2,
        "list": [
            {
                "id": "1929779171958321154",
                "kbId": "7a596866403f11f0981a0242ac160002",
                "name": "1",
                "description": "11",
                "language": "Chinese",
                "parserId": "general",
                "parserConfig": "{\"chunk_token_num\":\"256\",\"layout_recognize\":\"true\"}",
                "status": 1,
                "userId": null,
                "countFile": 0,
                "createDate": "2025-06-03 13:56:23",
                "updateDate": "2025-06-11 11:32:27"
            },
            {
                "id": "1929825565087756290",
                "kbId": "3b233ac2405911f0981a0242ac160002",
                "name": "2",
                "description": "2",
                "language": "Chinese",
                "parserId": "general",
                "parserConfig": "{\"chunk_token_num\":\"256\",\"layout_recognize\":\"true\"}",
                "status": 1,
                "userId": null,
                "countFile": 1,
                "createDate": "2025-06-03 17:00:44",
                "updateDate": "2025-06-05 15:01:55"
            }
        ]
    }
}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/getList \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '{
  "pageNo": 1,
  "pageSize": 9,
  "name": ""
}'

获取单个知识库信息

接口路径: /kb/getDetail
请求方式: GET
Content-Type: application/json;charset=UTF-8

请求参数

参数名类型必填说明
idString知识库ID

响应参数

{
    "code": 8000000,
    "message": "SUCCESS",
    "data": {
        "id": "1932694674987745281",
        "kbId": "e839178e469111f0ad370242ac160002",
        "name": "hello",
        "description": "",
        "language": "Chinese",
        "parserId": "general",
        "parserConfig": "{\"chunk_token_num\":\"256\",\"layout_recognize\":\"true\"}",
        "status": 0,
        "userId": null,
        "countFile": 0,
        "createDate": "2025-06-11 15:01:33",
        "updateDate": "2025-06-11 15:01:33"
    }
}

调用示例

curl -X GET 'http://localhost:8080/kb/getDetail?id=1932694674987745281'

文件上传

接口路径: `/file/upload
请求方式: POST
Content-Type: multipart/form-data;

请求参数

------WebKitFormBoundary1LhsI75tsNzOvmlM
Content-Disposition: form-data; name="file"; filename="hello.txt"
Content-Type: text/plain


------WebKitFormBoundary1LhsI75tsNzOvmlM--

响应参数

{
    "code": 8000000,
    "message": "SUCCESS",
    "data": {
        "id": 1932722391734669314,
        "fileName": "hello.txt",
        "md5": "oPKjwdzVscrHG/DAPy/xvQ==",
        "fileToken": "091bf7397edcceca34cf817e081e09c4"
    }
}

调用示例

curl --request POST \
  --url http://localhost:8080/sys-storage/upload \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: text/plain; charset=utf-8' \
  --data '------WebKitFormBoundary1LhsI75tsNzOvmlM
Content-Disposition: form-data; name="file"; filename="hello.txt"
Content-Type: text/plain


------WebKitFormBoundary1LhsI75tsNzOvmlM--
'

知识库文件上传

接口路径: /kb/fileUp
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

{
  "id": 1932722391734669300,
  "fileName": "hello.txt",
  "md5": "oPKjwdzVscrHG/DAPy/xvQ==",
  "fileToken": "091bf7397edcceca34cf817e081e09c4",
  "kbId": "e839178e469111f0ad370242ac160002"
}

响应参数

{
    "code": 8000000,
    "message": "SUCCESS",
    "data": {
        "id": 1932722392577724418,
        "createDate": null,
        "updateDate": null,
        "createBy": null,
        "updateBy": null,
        "fileToken": "091bf7397edcceca34cf817e081e09c4",
        "fileType": null,
        "fileName": "hello.txt",
        "kbId": "e839178e469111f0ad370242ac160002",
        "blockNum": null,
        "fileStatus": 0,
        "fileParser": null,
        "fileProgress": null,
        "fileParserMsg": null,
        "docId": "4b208d8c46a111f0878f0242ac160002"
    }
}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/fileUp \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '{
  "id": 1932722391734669300,
  "fileName": "hello.txt",
  "md5": "oPKjwdzVscrHG/DAPy/xvQ==",
  "fileToken": "091bf7397edcceca34cf817e081e09c4",
  "kbId": "e839178e469111f0ad370242ac160002"
}'

知识库文件批量解析

接口路径: /kb/fileParser
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

[
  {
    "fileToken": "091bf7397edcceca34cf817e081e09c4",
    "kbId": "e839178e469111f0ad370242ac160002",
    "docId": "4b208d8c46a111f0878f0242ac160002"
  }
]

响应参数

{"code":8000000,"message":"SUCCESS","data":"true"}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/fileParser \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '[
  {
    "id": "1932722392577724418",
    "createDate": "2025-06-11 16:51:41",
    "updateDate": "2025-06-11 16:51:41",
    "createBy": "2025000559",
    "updateBy": "2025000559",
    "fileToken": "091bf7397edcceca34cf817e081e09c4",
    "fileType": null,
    "fileName": "hello.txt",
    "kbId": "e839178e469111f0ad370242ac160002",
    "blockNum": "",
    "fileStatus": 0,
    "fileParser": "",
    "fileProgress": null,
    "fileParserMsg": null,
    "docId": "4b208d8c46a111f0878f0242ac160002"
  }
]'

知识库文件批量删除

接口路径: /kb/fileDel
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

[
  {
    "id": "1932722392577724418", //必须
    "kbId": "e839178e469111f0ad370242ac160002" //必须
  }
]

响应参数

{"code":8000000,"message":"SUCCESS","data":null}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/fileDel \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '[
  {
    "id": "1932722392577724418",
    "kbId": "e839178e469111f0ad370242ac160002"
  }
]'

查询知识库文件列表

接口路径: /kb/fileList
请求方式: POST
Content-Type: application/json;charset=UTF-8

请求参数

{
  "kbId": "e839178e469111f0ad370242ac160002",//必须
  "pageNo": 1,//必须
  "pageSize": 8//必须
}

响应参数

{
    "code": 8000000,
    "message": "SUCCESS",
    "data": {
        "pageSize": 8,
        "pageNum": 1,
        "total": 1,
        "list": [
            {
                "id": "1932722392577724418",
                "createDate": "2025-06-11 16:51:41",
                "updateDate": "2025-06-11 16:51:41",
                "createBy": "2025000559",
                "updateBy": "2025000559",
                "fileToken": "091bf7397edcceca34cf817e081e09c4",
                "fileType": null,
                "fileName": "hello.txt",
                "kbId": "e839178e469111f0ad370242ac160002",
                "blockNum": null,
                "fileStatus": 0,
                "fileParser": null,
                "fileProgress": null,
                "fileParserMsg": null,
                "docId": "4b208d8c46a111f0878f0242ac160002"
            }
        ]
    }
}

调用示例

curl --request POST \
  --url http://localhost:8080/kb/fileList \
  --header 'Authorization: sk-59e4IduiX0CzCZUIOAaFyIUlfnoX8jzS' \
  --header 'Content-Type: application/json' \
  --data '{
  "kbId": "e839178e469111f0ad370242ac160002",
  "pageNo": 1,
  "pageSize": 8
}'

查询知识库文件单个信息

接口路径: /kb/fileDetail
请求方式: GET
Content-Type: application/json;charset=UTF-8

请求参数

参数名类型必填说明
idString文件ID

响应参数

{
    "code": 200,
    "message": "success",
    "data": {
        "id": "文件ID",
        "kbId": "知识库ID",
        "fileName": "文件名",
        "fileUrl": "文件URL",
        "fileType": "文件类型",
        "status": "状态",
        "createTime": "创建时间"
    }
}

调用示例

curl -X GET 'http://localhost:8080/kb/fileDetail?id=123'