《五分钟上手指南:从零构建百宝箱智能知识库系统》

简介: 本文档为开发者提供知识库系统快速入门指南,涵盖API Token申请、5大核心接口调用及多语言SDK接入方法,助您快速构建和使用知识库。

概述

本文档旨在为开发者提供知识库系统的快速入门指南,涵盖从API token申请到完整知识库构建和使用的全流程。通过5个核心接口实现最短链路接入,并提供多语言SDK接入教程。

Token申请与认证  

申请步骤:

  1. 访问百宝箱开发平台百宝箱

  1. 添加令牌:在授权管理创建一个令牌

  1. 调用api:令牌创建好就可以调用下面的api了


知识库核心功能接口

序号

接口名称

功能描述

HTTP方法

path

参数示例

1

创建知识库

创建新的知识库实例

POST

/api/datasets/createDatasets

{"name":"test_knowledge","description":"这是openapi创建的一个知识库"}

3

上传文件

上传文档内容到指定文件

POST

/api/file/upload

2

创建知识库文件

在知识库中创建文件结构

POST

/api/datasets/createDatasetDocument

{"datasetId":"20250926asnT00509423","fileId":"20250926gatN15957444"}

4

查询构建进度

检查知识库构建状态

GET

/api/datasets/queryProgress

{"documentId": "20250926asnT00509423"}

5

知识库召回

从知识库中检索信息

POST

/api/datasets/retrieve

{"datasetId":"test_dataset_id","query":"什么是百宝箱?","limit":1}

调用示例

openapi

直接使用以下curl命令即可:

创建知识库

curl -X POST \
  https://api.tbox.cn/api/datasets/createDatasets \
  -H 'Authorization: your-authorization-token-here' \
  -H 'Content-Type: application/json' \
  -d '{"name" : "test_knowledge", "description": "这是openapi创建的一个知识库"}'

上传文件

curl -X POST \
  https://api.tbox.cn/api/file/upload \
  -H 'Authorization: your-authorization-token-here' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'file=@D:\下载\什么是百宝箱.txt'

创建知识库文件

curl -X POST \
  https://api.tbox.cn/api/datasets/createDatasetDocument \
  -H 'Authorization: your-authorization-token-here' \
  -H 'Content-Type: application/json' \
  -d '{"datasetId" : "20250926asnT00509423","fileId": "20250926gatN15957444"}'

查询知识库文件构建进度

curl -X GET \
  'https://api.tbox.cn/api/datasets/queryProgress?documentId=20250926a0ce2331328873' \
  -H 'Authorization: your-authorization-token-here' \
  -H 'Content-Type: application/json' \

知识库召回

curl -X POST \
  https://api.tbox.cn/api/datasets/retrieve \
  -H 'Authorization: your-authorization-token-here' \
  -H 'Content-Type: application/json' \
  -d '{"datasetId": "20250926asnT00509423","query": "什么是百宝箱?","limit": 1}'


Python SDK

sdk版本:

pip install tboxsdk==0.0.10

创建知识库

from tboxsdk.tbox import TboxClient
def create_datasets():
    """创建知识库请参考以下调用方式"""
    tbox = TboxClient(authorization="{your_token}")
    response = tbox.create_datasets(name="test_knowledge_1", description="这是openapi创建的一个知识库")
    print(f"--------------------------------------------------------")
    print(f"response: {response}")
    print(f"--------------------------------------------------------")
if __name__ == "__main__":
    create_datasets()

上传文件

from tboxsdk.tbox import TboxClient
def upload_file():
    tbox = TboxClient(authorization="{your_token}")
    response = tbox_client.upload_file(file_path="{file_path}")
    print(f"--------------------------------------------------------")
    print(f"response: {response}")
    print(f"--------------------------------------------------------")
    
    if response.get("errorCode") == "0":
        file_id = response.get("data", "")
        print(f"文件ID: {file_id}")
if __name__ == "__main__":
    upload_file()

创建知识库文件

from tboxsdk.tbox import TboxClient
def create_dataset_document():
    """创建知识库文件请参考以下调用方式"""
    tbox = TboxClient(authorization="{your_token}")
    response = tbox.create_dataset_document(dataset_id="2025092835ty00509709", file_id="20250928CyzT16083822")
    print(f"--------------------------------------------------------")
    print(f"response: {response}")
    print(f"--------------------------------------------------------")
if __name__ == "__main__":
    create_dataset_document()

查询知识库文件构建进度

from tboxsdk.tbox import TboxClient
def query_document_progress():
    """创建知识库请参考以下调用方式"""
    tbox = TboxClient(authorization="{your_token}")
    response = tbox.query_document_progress(document_id="202509282GnZ0931358743")
    print(f"--------------------------------------------------------")
    print(f"response: {response}")
    print(f"--------------------------------------------------------")
if __name__ == "__main__":
    query_document_progress()

知识库召回

from tboxsdk.tbox import TboxClient
def retrieve_dataset():
    """知识库召回请参考以下调用方式"""
    tbox = TboxClient(authorization="{your_token}")
    response = tbox.retrieve_dataset(query="什么是百宝箱?", dataset_id='2025092835ty00509709')
    print(f"--------------------------------------------------------")
    print(f"response: {response}")
    print(f"--------------------------------------------------------")
if __name__ == "__main__":
    retrieve_dataset()


Java SDK

sdk版本:

<dependency>
    <groupId>cn.tbox</groupId>
    <artifactId>tboxsdk</artifactId>
    <version>0.0.11</version>
</dependency>

创建知识库

import cn.tbox.sdk.TboxClient;
import cn.tbox.sdk.core.exception.TboxClientConfigException;
import cn.tbox.sdk.core.exception.TboxHttpResponseException;
import cn.tbox.sdk.model.request.CreateDatasetRequest;
import cn.tbox.sdk.model.response.TboxResponse;
public class Demo {
    private static final String YOUR_TOKEN = "{your_token}";
    public static void main(String[] args) throws TboxHttpResponseException {
        try {
            TboxClient client = new TboxClient(YOUR_TOKEN);
            CreateDatasetRequest chatRequest = new CreateDatasetRequest();
            chatRequest.setName("test_knowledge_java");
            chatRequest.setDescription("这是openapi创建的一个知识库");
            TboxResponse<String> result = client.createDataset(chatRequest);
            System.out.println(result);
        } catch (TboxClientConfigException e) {
            System.err.println("Configuration error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

上传文件

import java.util.Map;
import cn.tbox.sdk.TboxClient;
import cn.tbox.sdk.core.exception.TboxClientConfigException;
import cn.tbox.sdk.core.http.HttpClientConfig;
public class Demo {
    private static final String YOUR_TOKEN = "{your_token}";
    public static void main(String[] args) throws TboxClientConfigException {
        // 初始化客户端
        TboxClient client = new TboxClient(new HttpClientConfig(YOUR_TOKEN));
        TboxResponse<String> response = client.uploadFile("{filePath}");
            System.out.println(response.getData());
    }
}

创建知识库文件

import cn.tbox.sdk.TboxClient;
import cn.tbox.sdk.core.exception.TboxClientConfigException;
import cn.tbox.sdk.core.exception.TboxHttpResponseException;
import cn.tbox.sdk.model.request.CreateDatasetDocumentRequest;
import cn.tbox.sdk.model.response.TboxResponse;
public class Demo {
    private static final String YOUR_TOKEN = "{your_token}";
    public static void main(String[] args) throws TboxHttpResponseException {
        try {
            TboxClient client = new TboxClient(YOUR_TOKEN);
            CreateDatasetDocumentRequest chatRequest = new CreateDatasetDocumentRequest();
            chatRequest.setDatasetId("20250928clVY00509608");
            chatRequest.setFileId("20250928CyzT16083822");
            TboxResponse<String> result = client.createDatasetDocument(chatRequest);
            System.out.println(result);
        } catch (TboxClientConfigException e) {
            System.err.println("Configuration error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

查询知识库文件构建进度

import cn.tbox.sdk.TboxClient;
import cn.tbox.sdk.core.exception.TboxClientConfigException;
import cn.tbox.sdk.core.exception.TboxHttpResponseException;
import cn.tbox.sdk.model.response.DocumentProgressResponse;
import cn.tbox.sdk.model.response.TboxResponse;
public class Demo {
    private static final String YOUR_TOKEN = "{your_token}";
    public static void main(String[] args) throws TboxHttpResponseException {
        try {
            TboxClient client = new TboxClient(YOUR_TOKEN);
            TboxResponse<DocumentProgressResponse> result = client.queryDocumentProgress("20250928EeSR0831362774");
            System.out.println(result);
        } catch (TboxClientConfigException e) {
            System.err.println("Configuration error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

知识库召回

import cn.tbox.sdk.TboxClient;
import cn.tbox.sdk.core.exception.TboxClientConfigException;
import cn.tbox.sdk.core.exception.TboxHttpResponseException;
import cn.tbox.sdk.model.request.DatasetRetrieveRequest;
import cn.tbox.sdk.model.response.DatasetRetrieveResponse;
import cn.tbox.sdk.model.response.TboxResponse;
public class Demo {
    private static final String YOUR_TOKEN = "{your_token}";
    public static void main(String[] args) throws TboxHttpResponseException {
        try {
            TboxClient client = new TboxClient(YOUR_TOKEN);
            DatasetRetrieveRequest request = new DatasetRetrieveRequest();
            request.setQuery("什么是百宝箱?");
            request.setDatasetId("20250928clVY00509608");
            TboxResponse<DatasetRetrieveResponse> result = client.retrieveDataset(request);
            System.out.println(result);
        } catch (TboxClientConfigException e) {
            System.err.println("Configuration error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

Node.js SDK

创建知识库

import { TboxClient } from 'tbox-nodejs-sdk';
const client = new TboxClient({
  httpClientConfig: {
    authorization: 'TBox-7a630a0c6e6a4d4da24c07f14b795403',
  },
});
const response = await client.createDatasets({
  name: `test_dataset_${Date.now()}`,
  description: 'test dataset',
});
console.log('response', response);

上传文件

import { TboxClient } from 'tbox-nodejs-sdk';
import { readFileSync } from 'node:fs';
const client = new TboxClient({
  httpClientConfig: {
    authorization: 'your-authorization-token-here'
  }
});
const file = new Blob([readFileSync('local-file-path')]);
client.uploadFile(file, 'local-filename').then(response => {
  console.log(response);
});

创建知识库文件

import { TboxClient } from 'tbox-nodejs-sdk';
const client = new TboxClient({
  httpClientConfig: {
    authorization: 'TBox-7a630a0c6e6a4d4da24c07f14b795403',
  },
});
const response = await client.createDatasetDocument({
  datasetId: '20250918d5DU00506980',
  fileId: '20250917piHA13216855',
});
console.log('response', response);

查询知识库文件构建进度

import { TboxClient } from 'tbox-nodejs-sdk';
const client = new TboxClient({
  httpClientConfig: {
    authorization: 'TBox-7a630a0c6e6a4d4da24c07f14b795403',
  },
});
const response = await client.queryDocumentProgress({
  documentId: '20250918dm078031012985',
});
console.log('response', response);

知识库召回

import { TboxClient } from 'tbox-nodejs-sdk';
const client = new TboxClient({
  httpClientConfig: {
    authorization: 'TBox-7a630a0c6e6a4d4da24c07f14b795403',
  },
});
const response = await client.retrieveDataset({
  datasetId: '20250918d5DU00506980',
  query: 'test',
});
console.log('response', response);
相关文章
|
5月前
|
自然语言处理 JavaScript API
百宝箱开放平台 ✖️ 开发流程
本文介绍通过开放平台集成智能体能力的流程,包括创建发布应用、获取授权令牌及调用API/SDK三步。涵盖智能体调用、模型测评、文件操作等接口,并提供Java、Python、Node.js及Web SDK支持,助力开发者快速实现智能对话与内容生成功能集成。(239字)
434 0
百宝箱开放平台 ✖️ 开发流程
|
10月前
|
人工智能 自然语言处理 小程序
蚂蚁百宝箱 3 分钟上手 MCP:6 步轻松构建 Qwen3 智能体应用并发布小程序
本文介绍如何用6个步骤、3分钟快速构建一个基于Qwen3与蚂蚁百宝箱MCP的智能体应用,并发布为支付宝小程序。通过结合Qwen3强大的语言理解和生成能力,以及支付宝MCP提供的支付功能,开发者可轻松打造具备商业价值的“数字员工”。案例以“全球智能导游助手”为例,支持119种语言,不仅提供旅行建议,还能收取用户打赏。文章详细说明了从登录百宝箱、创建应用、添加插件到配置角色、发布上架及手机端体验的完整流程,同时提醒当前支付功能仅适用于测试环境。适合希望探索AI应用变现潜力的开发者尝试。
1365 14
|
人工智能 API 开发工具
蚂蚁百宝箱首届「插件开发大赛」,赛事持续至12月7日,最高赢取3W奖金!
首届「MCP插件开发大赛」由蚂蚁百宝箱联合通义灵码发起,聚焦企业场景,鼓励开发者基于AI Agent打造高效、创新的MCP插件。赛事持续至2025年12月7日,提供最高3万元现金奖励、免费AI工具支持及全程技术指导。参赛者可借助通义灵码开发,通过蚂蚁百宝箱发布部署,并在NeMo Agent Toolkit平台验证智能体效果。无论新手或专家,皆可实战练兵,推动AI技术落地,赢取丰厚回报。
369 0
|
人工智能 自然语言处理 供应链
网上管家婆客服部被AI“抢活”了!实测百宝箱智能体的提效魔法
网上管家婆联合蚂蚁百宝箱推出AI智能客服与语音转写智能体,实现售后咨询秒级响应、销售录音自动分析,大幅提升效率。智能体嵌入现有系统,零代码操作,助力客服摆脱重复劳动,聚焦高价值服务,真正实现人机协同提效。
195 0
|
5月前
|
API 开发工具 数据安全/隐私保护
蚂蚁开放平台 ✖️ 授权管理
为保障数据安全,开放平台要求开发者调用能力时使用有效令牌(token)进行身份验证。请勿泄露或暴露令牌信息。开发者可登录平台添加、复制、删除或切换令牌状态,调用时需将token添加至请求头Authorization参数。每种类型令牌最多10个。
265 0
|
人工智能 机器人 API
深夜的“懂我”瞬间:我在杭州开元名都,体验了一把“AI+闪购”投喂黑科技
深夜酒店点外卖,杭州开元名都大酒店AI管家惊艳体验:自动识别房号、智能推荐菜品、无感下单、机器人无接触送餐。依托蚂蚁百宝箱与云选科技合作,整合淘宝闪购、云迹地址MCP等能力,打造“懂你”的数字管家,重塑智慧酒店服务新范式。(239字)
224 0
深夜的“懂我”瞬间:我在杭州开元名都,体验了一把“AI+闪购”投喂黑科技
|
人工智能 自然语言处理 数据可视化
告别高成本定制:友盟U-AgentBox上线,开发者可一键集成行业模板,3天打造专属企业Agent
12月29日,蚂蚁百宝箱与友盟联合推出面向开发者的智能体产品U-AgentBox,聚焦低门槛、高效率集成专属智能体。通过模板化构建、可视化编辑与轻量级部署,助力开发者快速实现业务智能化升级。
296 0
告别高成本定制:友盟U-AgentBox上线,开发者可一键集成行业模板,3天打造专属企业Agent
|
5月前
|
开发者
百宝箱开放平台中关于模型效果盲测的 常见问题
本文列举了使用模型效果盲测功能时可能遇到的9类问题及解决方案,涵盖token、接入点、模型配置等常见错误提示,帮助开发者快速排查和解决接口调用中的问题。
204 0
|
人工智能 安全 API
一年输送旅客数千万次,浦东国际机场的效率秘密藏在这个智能体里
秋冬旅游高峰,浦东机场迎百万客流挑战。蚂蚁百宝箱推出“浦东国际机场”智能体,集成航班查询、停车导航、交通路线、餐饮酒店等一站式服务,实现“出发—到港”全链路智慧出行,提升旅客体验与机场运营效率。
240 0
一年输送旅客数千万次,浦东国际机场的效率秘密藏在这个智能体里
|
5月前
|
自然语言处理 Java 开发工具
《零代码到智能体:蚂蚁百宝箱TBox Agent SDK实战指南》
蚂蚁百宝箱开放OpenAPI/SDK调用智能体,开发者每月享10亿免费token。本文教你如何创建智能体,并用Python、Java等代码快速集成调用,涵盖对话与内容生成应用的构建全流程。
672 0
《零代码到智能体:蚂蚁百宝箱TBox Agent SDK实战指南》