Knowledge Storage API
Call Knowledge Storage directly through HTTP JSON APIs, covering knowledge base management, document management, retrieval, and chunk management. Use these APIs for custom integration without an SDK.
Knowledge base management
CreateKnowledgeBase
Create a knowledge base. Tablestore automatically creates the corresponding Document table, Chunk table, and index table.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required). Must start with a letter and contain only letters, digits, and underscores. Length: 1-64 characters. Must be unique |
|
|
string |
Knowledge base description. Maximum 4 KB |
|
|
boolean |
Whether to enable subspaces. Defaults to false. When enabled, all document operations and retrievals must specify the subspace field. Cannot be changed after creation |
|
|
list<string> |
Tag list. Total length cannot exceed 4 KB |
|
|
list<object> |
Metadata field definitions. See the following section for details |
|
|
object |
Embedding configuration. Cannot be changed after creation. If not specified, the system uses Alibaba Cloud Model Studio |
|
|
object |
Default retrieval configuration. Used when the Retrieve API is called without a configuration. Can be updated through UpdateKnowledgeBase after creation |
Metadata field definitions
Each element contains name (field name) and type (field type).
|
Item |
Description |
|
Supported types |
|
|
Field name |
Maximum 128 characters. Cannot contain |
|
Field count |
Maximum 200 fields |
|
Reserved fields |
|
Metadata field definitions cannot be added or removed after creation. Identify all dimensions that you may need for filtering retrieval results, and define them all at once when you create the knowledge base.
embeddingConfiguration
|
Parameter |
Type |
Description |
|
|
string |
Model provider. Defaults to |
|
|
string |
Model name. Defaults to |
|
|
int |
Vector dimension. Defaults to 1024 |
|
|
string |
Required only for |
|
|
string |
Required only for |
retrievalConfiguration
|
Parameter |
Type |
Description |
|
|
list<string> |
Retrieval types. Defaults to |
|
|
int |
Number of results from vector search. Defaults to 20 |
|
|
int |
Number of results from full-text search. Defaults to 20 |
|
|
string |
Reranking type: |
|
|
int |
Number of results after reranking. Defaults to 20 |
|
|
double |
Weight for vector search results. Defaults to 0.7 |
|
|
double |
Weight for full-text search results. Defaults to 0.3 |
|
|
double |
Weight for vector search in RRF mode. Defaults to 1.0 |
|
|
double |
Weight for full-text search in RRF mode. Defaults to 1.0 |
|
|
int |
RRF algorithm parameter. Defaults to 60. Must be greater than 0 |
|
|
string |
Reranking model provider. Defaults to |
|
|
string |
Reranking model name. Defaults to |
For the complete retrieval configuration reference, see Retrieve and rerank.
Request example
{
"knowledgeBaseName": "product_docs_kb",
"description": "Product documentation knowledge base",
"subspace": true,
"tags": ["Product", "Documentation"],
"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 example
{"code": "SUCCESS", "data": {}, "message": "succeed"}
UpdateKnowledgeBase
Update the description, tags, or retrieval configuration of a knowledge base. At least one of description, tags, or retrievalConfiguration must be specified.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Updated description. Maximum 4 KB |
|
|
list<string> |
Updated tags |
|
|
object |
Updated default retrieval configuration |
At least one of description, tags, or retrievalConfiguration must be specified. Otherwise, an error is returned.
Request example
{
"knowledgeBaseName": "product_docs_kb",
"description": "Updated description",
"tags": ["production"]
}
Response example
{"code": "SUCCESS", "data": {}, "message": "succeed"}
DescribeKnowledgeBase
Query the full configuration of a specified knowledge base.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
Response fields
|
Field |
Type |
Description |
|
|
string |
Knowledge base name |
|
|
string |
Knowledge base description |
|
|
list<string> |
Tag list |
|
|
boolean |
Whether subspaces are enabled |
|
|
int |
Creation timestamp in milliseconds |
|
|
int |
Last update timestamp in milliseconds |
|
|
list<object> |
Metadata field definitions |
|
|
object |
Embedding configuration |
|
|
object |
Retrieval configuration |
Response example
{
"code": "SUCCESS",
"data": {
"knowledgeBaseName": "product_docs_kb",
"description": "Product documentation knowledge base",
"tags": ["Product", "Documentation"],
"subspace": true,
"metadata": [{"name": "author", "type": "string"}],
"createdAt": 1774494642525,
"updatedAt": 1774494642525,
"embeddingConfiguration": {
"provider": "bailian",
"model": "text-embedding-v4",
"dimension": 1024
},
"retrievalConfiguration": {
"searchType": ["DENSE_VECTOR", "FULL_TEXT"],
"denseVectorSearchConfiguration": {"numberOfResults": 20},
"fullTextSearchConfiguration": {"numberOfResults": 20},
"rerankingConfiguration": {
"type": "WEIGHT",
"numberOfResults": 20,
"weightConfiguration": {
"denseVectorSearchWeight": 0.7,
"fullTextSearchWeight": 0.3
}
}
}
},
"message": "succeed"
}
ListKnowledgeBase
List all knowledge bases in the current project with pagination.
Request parameters
|
Parameter |
Type |
Description |
|
|
int |
Number of results to return. Defaults to 10. Maximum 100 |
|
|
string |
Pagination token. Do not specify for the first request |
Response fields
|
Field |
Type |
Description |
|
|
list<object> |
List of knowledge bases. Each item contains |
|
|
string |
Pagination token. Empty when no more pages remain |
Request example
{"maxResults": 10}
DeleteKnowledgeBase
Delete a specified knowledge base along with all its documents and chunks.
This operation is irreversible. Deleting a knowledge base permanently removes all documents and chunks within it.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
Request example
{"knowledgeBaseName": "product_docs_kb"}
Document management
AddDocuments
Import documents into a knowledge base. Tablestore automatically parses, chunks, vectorizes, and indexes the documents. Uploading a document with a duplicate ossKey overwrites the existing document.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Maximum 128 characters. Required when subspaces are enabled |
|
|
list<object> |
Document list (required). Maximum 10 documents per request |
|
|
string |
Local file path. Required for upload_documents |
|
|
string |
OSS file or directory path. Length: 1-256. Required for add_documents |
|
|
object |
Document metadata. Must match the metadata schema defined in the knowledge base |
|
|
list<string> |
Inclusion filters. Support leading and trailing |
|
|
list<string> |
Exclusion filters. Support leading and trailing |
Response fields
|
Field |
Type |
Description |
|
|
list<object> |
Processing result for each document |
|
|
string |
Document ID |
|
|
string |
Document OSS path |
|
|
string |
|
|
|
string |
Failure reason (only when status is failed) |
Request example
{
"knowledgeBaseName": "product_docs_kb",
"subspace": "default",
"documents": [
{
"ossKey": "oss://example-bucket/docs/manual.pdf",
"metadata": {"author": "Zhang San", "date": "2026-01-22 10:00:59"}
}
]
}
Response example
{
"code": "SUCCESS",
"data": {
"documentDetails": [
{"docId": "fc6ed97f-...", "status": "succeed", "ossKey": "oss://example-bucket/docs/manual.pdf"}
]
},
"message": "succeed"
}
An HTTP 200 response with code: SUCCESS does not mean all documents were processed successfully. Check the status field in each item of documentDetails. A status: "succeed" indicates the upload task was accepted, not that indexing is complete.
GetDocument
Query detailed information about a specified document.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Required when subspaces are enabled |
|
|
string |
Document ID. Specify either this or |
|
|
string |
OSS file path. Specify either this or |
Response fields
|
Field |
Type |
Description |
|
|
string |
Document ID |
|
|
string |
OSS path |
|
|
string |
Subspace |
|
|
int |
Number of chunks |
|
|
string |
Document status: |
|
|
int |
Creation timestamp |
|
|
int |
Last update timestamp |
|
|
string |
Document eTag |
|
|
string |
Failure reason (only when status is Failed) |
|
|
object |
Document metadata |
ListDocuments
List documents in a knowledge base with pagination.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
list<string> |
Subspace list. Maximum 10 entries. Required when subspaces are enabled |
|
|
int |
Number of results to return. Defaults to 10. Maximum 1000 |
|
|
string |
Pagination token |
UpdateDocument
Update the metadata of a specified document. Only documents with Completed status can be updated.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Required when subspaces are enabled |
|
|
string |
Document OSS path. Specify either this or |
|
|
string |
Document ID. Specify either this or |
|
|
map |
New metadata (required) |
Response fields
|
Field |
Type |
Description |
|
|
string |
Document ID |
|
|
string |
OSS path |
|
|
long |
Last update timestamp |
|
|
string |
|
Metadata updates are full replacements. The provided metadata completely replaces the existing values. To update a single field, include all fields in the request. Setting "metadata": null clears all metadata.
DeleteDocuments
Delete specified documents and all their chunks.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Required when subspaces are enabled |
|
|
list<object> |
List of documents to delete (required) |
|
|
string |
Document ID. Specify either this or |
|
|
string |
OSS path. Specify either this or |
Retrieval
Retrieve
Perform semantic retrieval in a knowledge base. Returns a list of chunks most relevant to the query text.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
list<string> |
Subspace list. Maximum 32 entries. Required when subspaces are enabled |
|
|
object |
Retrieval query (required) |
|
|
string |
Query type (required). Currently only |
|
|
string |
Query text (required). Maximum 128 characters |
|
|
object |
Retrieval configuration. If not specified, the knowledge base-level configuration or system defaults are used |
|
|
list<string> |
Retrieval types |
|
|
int |
Number of results from vector search. Maximum 100 |
|
|
int |
Number of results from full-text search. Maximum 100 |
|
|
object |
Reranking configuration |
|
|
object |
Metadata filter conditions |
Retrieval configuration priority
The effective retrieval configuration (retrievalConfiguration) is determined by the following priority order:
|
Priority |
Source |
Description |
|
1 (highest) |
Retrieve API parameters |
The |
|
2 |
Knowledge base-level configuration |
Set when the knowledge base is created. Can be updated through UpdateKnowledgeBase |
|
3 (lowest) |
System defaults |
Hybrid search with vector + full-text, WEIGHT fusion (vector 0.7 : full-text 0.3), returns 20 results |
The simplest retrieval request only requires knowledgeBaseName and retrievalQuery. All other parameters use the knowledge base configuration or defaults.
Supported filter operators
Comparison operators
|
Operator |
Symbol |
Description |
Applicable types |
|
|
= |
Equal to |
All types |
|
|
≠ |
Not equal to |
All types |
|
|
> |
Greater than |
long, double, date |
|
|
≥ |
Greater than or equal to |
long, double, date |
|
|
< |
Less than |
long, double, date |
|
|
≤ |
Less than or equal to |
long, double, date |
Set and match operators
|
Operator |
Description |
Applicable types |
|
|
Value is in the specified set |
All types |
|
|
Value is not in the specified set |
All types |
|
|
String prefix match |
string |
|
|
String contains match |
string |
|
|
List field contains the specified element |
list types |
Logical combination operators
|
Operator |
Description |
|
|
All conditions must be met |
|
|
At least one condition must be met |
|
|
None of the conditions are met |
andAll, orAll, and notAll support nesting, which allows you to build complex filter logic.
Response fields
|
Field |
Type |
Description |
|
|
list<object> |
Retrieval results sorted by relevance score in descending order |
|
|
string |
Parent document ID |
|
|
int |
Chunk ID |
|
|
string |
Parent document OSS path |
|
|
float |
Relevance score. Higher values indicate greater relevance |
|
|
string |
Chunk text content |
|
|
string |
Subspace that the chunk belongs to |
|
|
object |
Document metadata |
Request example
{
"knowledgeBaseName": "product_docs_kb",
"subspace": ["default"],
"retrievalQuery": {"type": "TEXT", "text": "What are the installation steps for the product"},
"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}
},
"filter": {
"andAll": [
{"greaterThanOrEquals": {"key": "score", "value": 60}}
]
}
}
}
Response example
{
"code": "SUCCESS",
"data": {
"retrievalResults": [
{
"ossKey": "oss://example-bucket/docs/manual.pdf",
"docId": "96fb386e-...",
"chunkId": 3,
"subspace": "default",
"score": 0.85,
"content": "Step 1: Download the installation package...",
"metadata": {"author": "Zhang San", "category": "Product documentation"}
}
]
},
"message": "succeed"
}
Chunk management
ListChunks
List chunks of a specified document with pagination.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Required when subspaces are enabled |
|
|
string |
Document ID. Specify either this or |
|
|
string |
OSS path. Specify either this or |
|
|
int |
Number of results to return. Defaults to 10. Maximum 1000 |
|
|
string |
Pagination token |
Response fields
|
Field |
Type |
Description |
|
|
string |
Subspace that the chunk belongs to |
|
|
int |
Chunk ID |
|
|
string |
Chunk content |
|
|
string |
Chunk title |
|
|
string |
Chunk type, such as |
|
|
string |
|
|
|
string |
Parent document ID |
|
|
string |
Parent document OSS path |
|
|
int |
Creation timestamp |
|
|
int |
Last update timestamp |
|
|
string |
Pagination token. Empty when no more pages remain |
UpdateChunks
Update the title, content, or status of chunks in batches.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
Knowledge base name (required) |
|
|
string |
Subspace name. Required when subspaces are enabled |
|
|
list<object> |
List of chunks to update (required). Maximum 10 chunks per request |
|
|
string |
Document ID. Specify either this or |
|
|
string |
OSS path. Specify either this or |
|
|
int |
Chunk ID (required) |
|
|
string |
Updated title. Maximum 100 tokens |
|
|
string |
Updated content. Maximum 320 tokens |
|
|
string |
Updated status: |
Response fields
|
Field |
Type |
Description |
|
|
string |
Document ID |
|
|
string |
OSS path |
|
|
int |
Chunk ID |
|
|
string |
|
|
|
string |
Failure reason (only when status is failed) |
Request example
{
"knowledgeBaseName": "product_docs_kb",
"subspace": "default",
"chunks": [
{"ossKey": "oss://example-bucket/docs/manual.pdf", "chunkId": 0, "status": "inactive"},
{"ossKey": "oss://example-bucket/docs/manual.pdf", "chunkId": 1, "title": "Updated title", "content": "Updated content"}
]
}
Common error codes
|
Error code |
Meaning |
Common causes |
|
|
Parameter validation failed |
Field type mismatch, length limit exceeded, or missing required fields |
|
|
Resource not found |
Knowledge base name is misspelled or the knowledge base has been deleted |
|
|
Invalid request format |
JSON format is invalid |
|
|
Business validation failed |
RRF k value is 0, or retrieval parameters are invalid |
For AddDocuments, DeleteDocuments, and UpdateChunks, an HTTP 200 response with code: SUCCESS does not mean all items were processed successfully. Each item has an independent status field that must be checked individually.