Use the CreateKnowledgeBase API to create a new knowledge base in the current AgentStorage instance. After creation, the system automatically creates a Document table, a Chunk table, and an index table in the instance to store documents, chunks, and index data.
Prerequisites
-
An AgentStorage instance has been created and is in the
normalstate, and the instance endpoint and instance name have been obtained. -
An API Key has been created.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Name of the knowledge base (required). Must start with a letter and contain only letters, digits, and underscores. Length: 1-64 characters. Must be unique. |
|
|
string |
Description of the knowledge base. Maximum 4 KB. |
|
|
boolean |
Whether to enable subspaces. Defaults to |
|
|
list<string> |
List of tags. Total length must not exceed 4 KB. |
|
|
list<object> |
Metadata field definitions. See the description below. |
|
|
object |
Embedding configuration. Cannot be modified after creation. If not specified, defaults to Bailian |
|
|
object |
Default retrieval configuration. Used when |
### metadata field definitions
Each element contains name (field name) and type (field type). Metadata field definitions cannot be added or deleted after the knowledge base is created; plan all fields needed for filtering before creation. Subsequent metadata values provided when importing or updating documents must conform to this definition.
|
Definition item |
Description |
|
Supported types |
|
|
Field name |
Maximum 128 UTF-8 bytes, must not contain |
|
Number of fields |
Up to 200 |
|
Reserved fields |
|
### embeddingConfiguration
|
Parameter |
Type |
Description |
|
|
string |
Model provider. Defaults to |
|
|
string |
Model name. Defaults to |
|
|
int |
Vector dimension. Default: 1024. |
|
|
string |
Required only in |
|
|
string |
Required only in |
### retrievalConfiguration
|
Parameter |
Type |
Description |
|
|
list<string> |
Retrieval type. Defaults to |
|
|
int |
Number of results returned by vector retrieval. Default: 20. |
|
|
int |
Number of results returned by full-text search. Default: 20. |
|
|
string |
Rerank type: |
|
|
int |
Number of results returned after reranking. Default: 20. |
|
|
double |
Vector retrieval weight ratio. Default: 0.7. |
|
|
double |
Full-text search weight ratio. Default: 0.3. |
|
|
double |
Vector retrieval weight in RRF mode. Default: 1.0. |
|
|
double |
Full-text search weight in RRF mode. Default: 1.0. |
|
|
int |
RRF algorithm parameter. Default: 60. Must be greater than 0. |
|
|
string |
Rerank model provider. Defaults to |
|
|
string |
Rerank model name. Defaults to |
For complete retrieval configuration details, see Retrieve and sort.
Request example
When using API Key authentication, pass the instance name and API Key through the x-ots-instancename and x-ots-apikey request headers.
curl -X POST https://<endpoint>/CreateKnowledgeBase \
-H "x-ots-instancename: <instance-name>" \
-H "x-ots-apikey: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"knowledgeBaseName": "product_docs_kb",
"description": "产品文档知识库",
"subspace": true,
"tags": ["产品", "文档"],
"metadata": [
{"name": "author", "type": "string"},
{"name": "date", "type": "date"},
{"name": "score", "type": "double"}
],
"embeddingConfiguration": {
"provider": "bailian",
"model": "text-embedding-v4",
"dimension": 1024
},
"retrievalConfiguration": {
"searchType": ["DENSE_VECTOR", "FULL_TEXT"],
"denseVectorSearchConfiguration": {"numberOfResults": 10},
"fullTextSearchConfiguration": {"numberOfResults": 10},
"rerankingConfiguration": {
"type": "RRF",
"numberOfResults": 5,
"rrfConfiguration": {"denseVectorSearchWeight": 0.6, "fullTextSearchWeight": 0.4, "k": 60}
}
}
}'
Response
{"code": "SUCCESS", "data": {}, "message": "succeed"}