The knowledge base provides open API interfaces for integrating with existing business systems, enabling automated operations and complex retrieval requirements.
This document applies only to document search knowledge bases.
Sub-accounts (not primary accounts) need the
All knowledge base APIs are REST-style, served through the bailian gateway, using AK/SK ACS3-V3 signing.
Knowledge base features are only available in the China (Beijing) region.
Prerequisites
Sub-accounts (not primary accounts) need the AliyunBailianDataFullAccess policy and must join a business space before they can operate knowledge bases via the Alibaba Cloud API.
Sub-accounts can only operate knowledge bases in business spaces they have joined; primary accounts can operate across all business spaces.
- Install the latest Alibaba Cloud Bailian SDK. If the SDK does not meet your needs, you can send signed HTTP requests to the knowledge base API.
- Obtain an AccessKey, AccessKey Secret, and business space ID, and configure them as environment variables:
- Prepare a sample document, Alibaba Cloud Bailian phone product introduction.docx.
API Overview
All knowledge base APIs are REST-style, served through the bailian gateway, using AK/SK ACS3-V3 signing.
- Server:
https://bailian.{regionId}.aliyuncs.com - Path style: REST resource paths with workspace prefix, e.g.
GET /{workspaceId}/promptTemplates - Authentication: ACS3-HMAC-SHA256 (V3) signing. Not Bearer token. See Flow Agent API Authentication for details.
- RAM policies:
AliyunBailianFullAccess/AliyunBailianReadOnlyAccess
Resource Summary
| Resource | Endpoints |
|---|---|
| Knowledge Bases | Create, List, Get, Update, Delete |
| Categories | Create, List, Get, Update, Delete |
| Files | Add, List, Get, Delete, Get Content |
| Chunks | List, Add, Update, Delete |
| Sessions | Create, List, Get, Delete |
Quick Start: Create a Knowledge Base
File Upload Flow
- ApplyFileUploadLease — Obtain an upload lease and pre-signed URL.
- Upload File — Upload the file to the pre-signed URL.
- AddFile — Register the file with the knowledge base and get a FileId.
Error Codes
| Code | Description |
|---|---|
DataCenter.FileTooLarge | File exceeds the size limit |
PromptTemplate.TemplateNotFound | Template not found |
InvalidAccessKeyId.NotFound | Access key not found |
NOT AUTHORIZED | Not authorized to the workspace |