document/content/docs/introduction/guide/knowledge_base/api_dataset.en.mdx
import { Alert } from '@/components/docs/Alert';
FastGPT supports local file imports, but in many cases users already have an existing document library. Re-importing files would create duplicate storage and complicate management. To address this, FastGPT offers an API File Library that connects to your existing document library through simple API endpoints, with flexible import options.
The API File Library lets you integrate your existing document library seamlessly. Implement a few endpoints that conform to FastGPT's API File Library specification, provide the service's baseURL and token when creating a knowledge base, and you can browse and selectively import files directly from the UI.
When creating a knowledge base, select the API File Library type and configure the key parameters: the baseURL of your file service and the request header for authentication. As long as your endpoints conform to FastGPT's specification, the system will automatically fetch and display the complete file list for selective import.
You need to provide three parameters:
Authorization: Bearer <token>Response format:
type ResponseType = {
success: boolean;
message: string;
data: any;
}
Data types:
// Single file item in the file list
type FileListItem = {
id: string;
parentId: string | null;
name: string;
type: 'file' | 'folder';
updateTime: Date;
createTime: Date;
hasChild?: boolean; // Optional, whether it has child nodes, defaults to true for folder type
}
<Tabs items={['Request Example','Response Example']}> <Tab value="Request Example" >
<Alert icon=" " context="success"> - parentId - Parent ID, optional. If not provided or null, the configured basePath will be used as the root directory - searchKey - Search keyword, optional </Alert>curl --location --request POST '{{baseURL}}/v1/file/list' \
--header 'Authorization: Bearer {{authorization}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"parentId": null,
"searchKey": ""
}'
{
"success": true,
"message": "",
"data": [
{
"id": "xxxx",
"parentId": "xxxx",
"type": "file",
"name":"test.json",
"updateTime":"2024-11-26T03:05:24.759Z",
"createTime":"2024-11-26T03:05:24.759Z",
"hasChild": false
}
]
}
<Tabs items={['Request Example','Response Example']}> <Tab value="Request Example" >
curl --location --request GET '{{baseURL}}/v1/file/content?id=xx' \
--header 'Authorization: Bearer {{authorization}}'
{
"success": true,
"message": "",
"data": {
"title": "Document Title",
"content": "FastGPT is an LLM-based knowledge base Q&A system with out-of-the-box data processing and model invocation capabilities. It also supports visual workflow orchestration via Flow for complex Q&A scenarios!\n"
}
}
previewUrl.Important Notes:
content or previewUrl must be returned, at least one is required, otherwise an error will occur.content and previewUrl are returned, content takes priority and the system will use the content directly.previewUrl is returned, the system will access the link to read and parse the document content, and will cache the parsing results to improve performance.<Tabs items={['Request Example','Response Example']}> <Tab value="Request Example" >
id is the file's ID.
curl --location --request GET '{{baseURL}}/v1/file/read?id=xx' \
--header 'Authorization: Bearer {{authorization}}'
{
"success": true,
"message": "",
"data": {
"url": "xxxx"
}
}
<Tabs items={['Request Example','Response Example']}> <Tab value="Request Example" >
id is the file's ID.
curl --location --request GET '{{baseURL}}/v1/file/detail?id=xx' \
--header 'Authorization: Bearer {{authorization}}'
{
"success": true,
"message": "",
"data": {
"id": "xxxx",
"name": "test.json",
"parentId": "xxxx",
"type": "file",
"updateTime": "2024-11-26T03:05:24.759Z",
"createTime": "2024-11-26T03:05:24.759Z"
}
}