Knowledge base management
This topic describes RDS ContextDB knowledge base management APIs for document management, multipart uploads, semantic retrieval, and knowledge graph queries.
Common information
Endpoint
https://context-database.aliyuncs.comAuthentication
All Data API operations are authenticated by a workspace-level API key. Use one of the following methods:
Method | Header format |
X-API-Key |
|
Token |
|
Bearer |
|
Common conventions
The server supplies
workspace_idandmember_idfrom the API key. Callers must not provide them; they are not request parameters.Fields marked No* are conditionally required. Supply one of the alternative fields in the group; omitting all returns HTTP 400.
UpdateDocumentMetadata, BatchDeleteDocuments, UploadKnowledgeFileChunk, and AbortKnowledgeFileUpload use an envelope with business fields in
data. Other operations return business objects directly.
Common HTTP error codes:
Status code | Meaning | Typical scenario |
400 | Invalid request parameters | Missing required fields, unsupported values, out-of-range numbers, or invalid metadata. Missing knowledge bases or documents also return HTTP 400, not 404: |
403 | Access denied | The API key lacks target knowledge base permissions, or the upload ticket belongs to another workspace. |
409 | Resource conflict | An existing document has the same name, the logical document is being uploaded or updated, or the update target is ambiguous. |
413 | Request too large | The file exceeds the 500 MB direct-upload limit. Use multipart upload if it remains within its file-type limit. |
Data API overview
The following table lists the operations covered in this topic.
API | Description |
CreateKnowledgeBase | Creates a knowledge base. |
ListKnowledgeBases | Lists workspace knowledge bases by created_at descending, newest first. |
GetKnowledgeBaseDetail | Queries the details of a single knowledge base. |
UpdateKnowledgeBase | Partially updates knowledge base settings. |
DeleteKnowledgeBase | Deletes an empty knowledge base. |
CreateDocument | Creates a text document for asynchronous parsing and ingestion. |
UpdateDocument | Updates a text document with new content. |
UploadFile | Directly uploads multipart/form-data and creates a knowledge document. |
UpdateFile | Updates a knowledge document with a file. |
InitializeKnowledgeFileUpload | Initializes multipart upload for files exceeding the 500 MB direct-upload limit. |
InitializeKnowledgeFileUpdate | Initializes a multipart update to replace an existing document with a large file. |
UploadKnowledgeFileChunk | Uploads one part and returns a unified envelope. |
CompleteKnowledgeFileUpload | Completes multipart upload by merging parts and checking the object's actual size. |
AbortKnowledgeFileUpload | Cancels multipart upload, releases the object-storage upload, and marks the placeholder document failed. |
ListDocuments | Lists documents by knowledge base, pagination, and sorting. |
GetDocumentDetail | Retrieves document details, including nullable |
UpdateDocumentMetadata | Overwrites the document-level custom metadata in full. |
DeleteDocument | Deletes a document asynchronously by setting |
BatchDeleteDocuments | Deletes documents asynchronously in a batch using DeleteDocument rules. |
ListDocumentChunks | Lists document chunks. |
CreateKnowledgeEvent | Manually dispatches asynchronous processing to reingest a document or rebuild its graph. |
QueryKnowledge | Performs semantic retrieval combining vector and keyword search with optional reranking. |
ListKnowledgeEntities | Lists knowledge base entities. |
ListKnowledgeEntityRelations | Lists knowledge base relationships. |
Knowledge API
CreateKnowledgeBase
Description
Creates a knowledge base. Names must be unique within a workspace; duplicates return HTTP 400. Names longer than 255 characters are silently truncated.
Request syntax
POST /v1/knowledge/knowledge_basesRequest parameters
Name | Type | Required | Description | Example |
name | string | Yes | The knowledge base name. Unique within the workspace; silently truncated to 255 characters. |
|
description | string | No | The knowledge base description |
|
chunk_size | integer | No | Chunk size. Default: |
|
chunk_overlap | integer | No | Chunk overlap. Default: |
|
graph_enabled | boolean | No | Specifies whether to enable the knowledge graph. Default value: |
|
review_enabled | boolean | No | Specifies whether to enable ingestion review. Default value: |
|
Response parameters
Name | Type | Description | Example |
id | string | The knowledge base ID |
|
workspace_id | string | The workspace ID |
|
owner_member_id | string | The member ID of the owner |
|
name | string | The knowledge base name |
|
description | string | Description |
|
status | string | The status |
|
graph_enabled | boolean | Indicates whether the knowledge graph is enabled |
|
review_enabled | boolean | Indicates whether review is enabled |
|
created_at | string | The creation time |
|
updated_at | string | The update time |
|
This response excludes key_entities. Only ListKnowledgeBases and GetKnowledgeBaseDetail return key_entities.
ListKnowledgeBases
Description
Lists workspace knowledge bases by created_at descending, newest first. No pagination is used. total equals the number returned.
Request syntax
GET /v1/knowledge/knowledge_basesRequest parameters
None.
Response parameters
Returns a wrapper object:
Name | Type | Description | Example |
knowledge_bases | array | The knowledge base list. See the element fields below. | See below |
total | integer | The number of knowledge bases returned. |
|
Elements of the knowledge_bases array:
Name | Type | Description | Example |
id | string | The knowledge base ID |
|
workspace_id | string | The workspace ID |
|
owner_member_id | string | The member ID of the owner |
|
name | string | The knowledge base name |
|
description | string | Description |
|
status | string | The status |
|
graph_enabled | boolean | Indicates whether the knowledge graph is enabled |
|
review_enabled | boolean | Indicates whether review is enabled |
|
key_entities | array | Up to five key entity names. |
|
created_at | string | The creation time |
|
updated_at | string | The update time |
|
Examples
Sample success response:
{
"knowledge_bases": [
{
"id": "kb-001",
"workspace_id": "ws-001",
"owner_member_id": "member-001",
"name": "Product documentation base",
"description": "Stores product technical documents",
"status": "active",
"graph_enabled": true,
"review_enabled": false,
"key_entities": [
"ContextDB",
"RDS"
],
"created_at": "2026-06-01T00:00:00Z",
"updated_at": "2026-06-01T10:00:00Z"
}
],
"total": 1
}GetKnowledgeBaseDetail
Description
Queries the details of a single knowledge base.
Request syntax
GET /v1/knowledge/knowledge_bases/detailRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name. Specify either this parameter or the ID |
|
Omitting both fields or supplying inconsistent values returns HTTP 400.
Response parameters
The fields are the same as those of the elements of the knowledge_bases array of ListKnowledgeBases, including key_entities.
UpdateKnowledgeBase
Description
Partially updates knowledge base settings. Omitted fields remain unchanged. A new name matching another knowledge base in the workspace returns HTTP 400.
Request syntax
PUT /v1/knowledge/knowledge_basesRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | Yes | The knowledge base ID (query parameter) |
|
knowledge_base_name | string | No | The new name in the request body. |
|
description | string | No | The new description in the request body. |
|
graph_enabled | boolean | No | Whether to enable the graph, specified in the body. |
|
review_enabled | boolean | No | Whether to enable review, specified in the body. |
|
knowledge_base_id is a required query parameter; other fields belong in the body. A missing body returns HTTP 400. Updating chunk_size or chunk_overlap is unsupported.
Response parameters
The updated knowledge base object uses CreateKnowledgeBase response fields and excludes key_entities.
DeleteKnowledgeBase
Description
Deletes an empty knowledge base. If documents remain, returns HTTP 400, such as knowledge base still has N document(s), delete them first. Documents are not cascade-deleted. First remove them with DeleteDocument or BatchDeleteDocuments.
Request syntax
DELETE /v1/knowledge/knowledge_basesRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name. Specify either this parameter or the ID |
|
Response parameters
Name | Type | Description | Example |
deleted | boolean | Indicates whether the memory is deleted |
|
knowledge_base_id | string | The knowledge base ID |
|
CreateDocument
Description
Creates a text document for asynchronous parsing and ingestion. Creation only: an active document with the same case-insensitive logical key (knowledge base + file_path + name) returns HTTP 409. Use UpdateDocument instead. An upload for the same logical document also causes HTTP 409. Optional review_template_id must identify an active template in the same KB, or HTTP 400 is returned. Invalidated templates fall back to the KB default.
ingest_status values: pending, uploading, processing, ai_reviewing, pending_review, succeeded, failed, deleting, and deleted. Text documents start as pending and become processing after successful event dispatch.
graph_status values: pending, queued, processing, succeeded, failed, and skipped. Initially skipped if the KB graph is disabled, otherwise pending.
Request syntax
POST /v1/knowledge/documentsRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
name | string | Yes | The document name, silently truncated to 255 characters. |
|
text | string | Yes | The document text. Blank content returns HTTP 400. |
|
mime_type | string | No | The MIME type. Default: |
|
file_path | string | No | The file path, stored as metadata and included in the logical document key. |
|
source_type | string | No | The source type. Defaults to |
|
review_enabled | boolean | No | Specifies whether to review the document. If it is not specified, the knowledge base setting applies |
|
review_template_id | string | No | The document-level review rewrite template ID. Must be an active template in the same KB, or returns HTTP 400. |
|
metadata | object | No | Document metadata as a flat map of scalars or scalar lists, used by |
|
metadata validation rules. Violations return HTTP 400:
Rule | Constraint |
Number of keys | At most 32. |
Key length | Each key must be nonblank and at most 64 characters. |
Reserved keys |
|
Value type | Scalars (string, number, or boolean) or lists of scalars only. |
Clearing values |
|
Response parameters
Returns the document object:
Name | Type | Description | Example |
id | string | The document ID |
|
workspace_id | string | The workspace ID |
|
knowledge_base_id | string | The knowledge base ID |
|
name | string | The document name |
|
file_path | string | The file path. If no value exists, the value is an empty string |
|
source_type | string | The source type |
|
mime_type | string | The MIME type |
|
ingest_status | string | Ingestion status: |
|
latest_ingest_event_id | string | The ID of the most recent ingestion event |
|
review_template_id | string | The document-level review rewrite template ID, or null if unspecified. |
|
ingest_error_message | string | The ingestion failure reason. If no failure exists, the value is null |
|
chunk_count | integer | The number of chunks |
|
token_count | integer | The number of tokens |
|
graph_status | string | Graph build status: |
|
latest_graph_event_id | string | The latest graph build event ID, or null if unavailable. |
|
graph_version | integer | The graph version |
|
pending_chunk_change_count | integer | The number of chunk changes pending graph synchronization |
|
metadata | object | The document-level custom metadata. If it is not set, the value is an empty object |
|
size_bytes | integer | The document size in bytes |
|
created_at | string | The creation time |
|
updated_at | string | The update time |
|
UpdateDocument
Description
Updates a text document with new content. A separate document, snapshot, and ingestion event process the update asynchronously. The old document is deleted only after successful parsing. Renaming, moving paths, and switching knowledge bases are unsupported.
Mutually exclusive target locators:
Specify only
document_id; orSpecify the logical key: knowledge base locator +
name+file_path.
Mixing document_id with logical-key fields returns HTTP 400: document_id and knowledge_base/name/file_path locators are mutually exclusive. Omitting both also returns HTTP 400.
Content deduplication: an identical SHA-256 returns the old document without parsing or applying the supplied metadata or review_template_id. Use UpdateDocumentMetadata for metadata-only changes.
Inheritance: when content changes, omitted metadata, review_template_id, mime_type, and source_type inherit old values. An empty metadata object or empty review_template_id clears that field.
HTTP 409 conflicts: the target is uploading, pending, processing, ai_reviewing, or pending_review; the logical document is being updated; or multiple stable matches make the target ambiguous.
Request syntax
PUT /v1/knowledge/documentsRequest parameters
Name | Type | Required | Description | Example |
document_id | string | No* | The document ID, mutually exclusive with logical-key fields. |
|
knowledge_base_id | string | No* | The KB ID for logical-key lookup, as an alternative to the KB name. |
|
knowledge_base_name | string | No* | The KB name for logical-key lookup. |
|
name | string | No* | The document name for logical-key lookup. Required if |
|
file_path | string | No | The file path for logical-key lookup. |
|
text | string | Yes | The new document text. Blank content returns HTTP 400. |
|
mime_type | string | No | The MIME type, inherited from the old document if omitted. |
|
source_type | string | No | The source type, inherited from the old document if omitted. |
|
review_enabled | boolean | No | Specifies whether to review the document. If it is not specified, the knowledge base setting applies |
|
review_template_id | string | No | The document-level review template ID. Omission inherits it; an empty value clears it. |
|
metadata | object | No | Document metadata. Omission inherits it; an empty object clears it. Validation matches CreateDocument. |
|
Response parameters
Returns the new document, or the old one after deduplication, using CreateDocument response fields.
UploadFile
Description
Directly uploads multipart/form-data and creates a knowledge document. Creation only: an active logical-key match returns HTTP 409; use UpdateFile instead. source_type is fixed to file. mime_type uses the uploaded Content-Type, defaulting to application/octet-stream.
File size limits: direct upload is limited to 500 MB and the applicable file-type limit.
File category | Typical extensions | Limit |
Plain text and code | txt, md, csv, tsv, log, json, xml, yaml, yml, html, htm, and other code or configuration files | 20 MB |
Complex documents and images | pdf, doc, docx, ppt, pptx, xls, xlsx, epub, png, jpg, jpeg, gif, bmp, webp, tiff, tif, svg | 500 MB |
Audio | mp3, wav, flac, ogg, m4a, aac, wma | 10 MB |
Video | mp4, avi, mov, mkv, webm, flv, wmv, 3gp, mpeg, mpg | 2048 MB(2 GB) |
Exceeding the file-type limit returns HTTP 400. Exceeding only the 500 MB direct-upload limit returns 413 with KNOWLEDGE_DIRECT_UPLOAD_REQUIRES_CHUNK. Use multipart upload; videos larger than 500 MB require it.
Request syntax
POST /v1/knowledge/filesRequest parameters
Name | Type | Required | Description | Example |
file | file | Yes | The uploaded file as a multipart part. Empty input returns HTTP 400. | - |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
name | string | No | The document name. If it is not specified, the file name is used |
|
file_path | string | No | The file path, stored as metadata and included in the logical document key. |
|
review_enabled | boolean | No | Specifies whether to review the document. If it is not specified, the knowledge base setting applies |
|
review_template_id | string | No | The document-level review rewrite template ID. Must be an active template in the same KB, or returns HTTP 400. |
|
metadata | string | No | The document-level custom metadata as a JSON object string passed in a form field. The validation rules are the same as those of the |
|
Response parameters
Returns the document object. The fields are the same as the response parameters of CreateDocument.
UpdateFile
Description
Updates a knowledge document with a file. Lookup, SHA-256 deduplication, inheritance, and HTTP 409 behavior match UpdateDocument. File limits match UploadFile: HTTP 400 for type-limit violations, 413 for direct-upload violations only. Renaming, moving paths, and changing knowledge bases are unsupported.
Request syntax
PUT /v1/knowledge/filesRequest parameters
Name | Type | Required | Description | Example |
file | file | Yes | The new file as a multipart part. Empty input returns HTTP 400. | - |
document_id | string | No* | The document ID, mutually exclusive with logical-key fields. |
|
knowledge_base_id | string | No* | The KB ID for logical-key lookup, as an alternative to the KB name. |
|
knowledge_base_name | string | No* | The KB name for logical-key lookup. |
|
name | string | No* | The document name for logical-key lookup. Defaults to the filename when |
|
file_path | string | No | The file path for logical-key lookup. |
|
review_enabled | boolean | No | Specifies whether to review the document. If it is not specified, the knowledge base setting applies |
|
review_template_id | string | No | The document-level review template ID, inherited if omitted. |
|
metadata | string | No | Document metadata as a JSON object string. Omission inherits it; an empty object clears it. |
|
Response parameters
Returns the new document, or the old one after deduplication, using CreateDocument response fields.
InitializeKnowledgeFileUpload
Description
Initializes multipart upload for files exceeding the 500 MB direct-upload limit. Creates a document and source snapshot, starts object-storage multipart upload, and returns upload_ticket. Creation only: an active logical-key match returns HTTP 409.
upload_ticket is valid for one hour. Supply it in X-Upload-Ticket for UploadKnowledgeFileChunk, CompleteKnowledgeFileUpload, and AbortKnowledgeFileUpload. A workspace mismatch with the API key returns HTTP 403.
Initialization does not require file size. Validation uses cumulative part sizes and the final object's actual size. mime_type defaults to application/octet-stream.
Request syntax
POST /v1/knowledge/files/init-uploadRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | Yes | The knowledge base ID (query parameter) |
|
file_name | string | Yes | The original filename for extension validation and size classification. |
|
name | string | No | The document name. Defaults to |
|
file_path | string | No | The file path, included in the logical document key. |
|
mime_type | string | No | The MIME type. Default: |
|
metadata | string | No | Document metadata as a JSON object string. Validation matches CreateDocument |
|
review_template_id | string | No | The document-level review rewrite template ID. Must be an active template in the same KB, or returns HTTP 400. |
|
Response parameters
Name | Type | Description | Example |
document_id | string | The new document ID. |
|
knowledge_base_id | string | The knowledge base ID |
|
upload_ticket | string | The upload ticket, valid for one hour. |
|
chunk_size | integer | The recommended part size in bytes, corresponding to 10 MB. |
|
InitializeKnowledgeFileUpdate
Description
Initializes a multipart update to replace an existing document with a large file. Lookup and conflicts match UpdateFile. Omitted metadata, review_template_id, and mime_type inherit old values. The response matches InitializeKnowledgeFileUpload.
Mutually exclusive locators: specify document_id, or knowledge_base_id + name + file_path. Mixing them returns HTTP 400: document_id and knowledge_base_id/name/file_path locators are mutually exclusive. Omitting both returns HTTP 400: document_id or knowledge_base_id is required.
Request syntax
PUT /v1/knowledge/files/init-uploadRequest parameters
Name | Type | Required | Description | Example |
document_id | string | No* | The document ID as a query parameter, mutually exclusive with KB locator fields. |
|
knowledge_base_id | string | No* | The KB ID for logical-key lookup. |
|
file_name | string | Yes | The original filename for extension validation and size classification. |
|
name | string | No* | The document name for logical-key lookup. Required if |
|
file_path | string | No | The file path for logical-key lookup. |
|
mime_type | string | No | The MIME type, inherited from the old document if omitted. |
|
metadata | string | No | Document metadata as a JSON object string, inherited if omitted. |
|
review_template_id | string | No | The document-level review template ID, inherited if omitted. |
|
Response parameters
Name | Type | Description | Example |
document_id | string | The placeholder document ID for this upload. |
|
knowledge_base_id | string | The knowledge base ID |
|
upload_ticket | string | The upload ticket, valid for one hour. |
|
chunk_size | integer | The recommended part size in bytes, corresponding to 10 MB. |
|
UploadKnowledgeFileChunk
Description
Uploads one part and returns a unified envelope. The server accumulates uploaded bytes. If the total exceeds the file-type limit, the entire upload is canceled with HTTP 400. Initialize a new upload afterward.
Request syntax
POST /v1/knowledge/files/chunksRequest parameters
Name | Type | Required | Description | Example |
X-Upload-Ticket | string | Yes | The upload ticket in the request header. Workspace mismatches return HTTP 403. |
|
part_number | integer | Yes | The part number as a form field. Must be at least 1, or returns HTTP 400. |
|
data | file | Yes | The part data as a multipart part. Empty input returns HTTP 400. | - |
Response parameters (in the data field)
Name | Type | Description | Example |
part_number | integer | The part number. |
|
etag | string | The part ETag to pass back when completing the upload. |
|
CompleteKnowledgeFileUpload
Description
Completes multipart upload by merging parts and checking the object's actual size. If the type limit is exceeded, the merged object is deleted, the upload is canceled, and HTTP 400 is returned. Otherwise, dispatches ingestion and sets processing.
For an InitializeKnowledgeFileUpdate upload whose SHA-256 matches the old content, reuses the old document without parsing. document_id is the old ID and status is succeeded.
Request syntax
POST /v1/knowledge/files/completeRequest parameters
Name | Type | Required | Description | Example |
X-Upload-Ticket | string | Yes | The upload ticket in the request header. Workspace mismatches return HTTP 403. |
|
parts | array | Yes | The uploaded part list in the body. An empty list returns HTTP 400. | See the following table |
parts elements:
Name | Type | Required | Description | Example |
part_number | integer | Yes | The part number. |
|
etag | string | Yes | The ETag returned by part upload. |
|
Response parameters
Name | Type | Description | Example |
document_id | string | The document ID, or the reused old document ID after deduplication. |
|
knowledge_base_id | string | The knowledge base ID |
|
status | string | The document status: |
|
AbortKnowledgeFileUpload
Description
Cancels multipart upload, releases the object-storage upload, and marks the placeholder document failed. Returns a unified envelope.
Request syntax
POST /v1/knowledge/files/abortRequest parameters
Name | Type | Required | Description | Example |
X-Upload-Ticket | string | Yes | The upload ticket in the request header. Workspace mismatches return HTTP 403. |
|
Response parameters (in the data field)
Name | Type | Description | Example |
document_id | string | The document ID |
|
status | string | Fixed to |
|
ListDocuments
Description
Lists documents by knowledge base, pagination, and sorting. Documents with ingest_status = deleted are excluded.
Pagination: if both page and page_size are omitted, returns all documents without page or page_size; total is the returned count. With pagination, total counts all matching documents. Values below page 1 become 1. page_size defaults to 50, with a maximum of 100; out-of-range values are clamped to [1, 100] without HTTP 400.
Sorting: invalid sort_by or sort_order returns HTTP 400. Sorting applies with or without pagination.
Request syntax
GET /v1/knowledge/documentsRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
page | integer | No | The page number. Default: |
|
page_size | integer | No | Items per page. Default: |
|
sort_by | string | No | Sort field. Default: |
|
sort_order | string | No | Sort direction: |
|
Response parameters
Name | Type | Description | Example |
documents | array | Documents using CreateDocument response fields, plus the recall statistics below. | See the following table |
total | integer | The total matching count with pagination, otherwise the returned count. |
|
page | integer | The current page number. This field is returned only when pagination parameters are specified |
|
page_size | integer | The number of entries per page. This field is returned only when pagination parameters are specified |
|
Additional recall statistics in documents elements:
Name | Type | Description | Example |
recall_count | integer | The total number of recalls |
|
recall_count_7d | integer | Recalls in the last seven days. |
|
recall_count_30d | integer | Recalls in the last 30 days. |
|
last_recalled_at | string | The time of the most recent recall. If the memory has never been recalled, the value is |
|
GetDocumentDetail
Description
Retrieves document details, including nullable review_template_id and latest_graph_event_id. ingest_status and graph_status use the CreateDocument values.
Request syntax
GET /v1/knowledge/documents/detailRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
document_id | string | Yes | The document ID |
|
Response parameters
Returns the document object. The fields are the same as the response parameters of CreateDocument.
UpdateDocumentMetadata
Description
Overwrites the document-level custom metadata in full. A null or empty object for metadata clears the metadata. The update is synchronized to the search index, and subsequent metadata_condition filtering takes effect based on the new values. The response uses the unified envelope structure.
Returns HTTP 400 for documents in deleting or deleted. Cannot change the document name or path.
Request syntax
PUT /v1/knowledge/documents/metadataRequest parameters
Name | Type | Required | Description | Example |
document_id | string | Yes | The document ID |
|
metadata | object | No | The new document-level metadata, which overwrites the existing metadata in full. A |
|
Response parameters (in the data field)
Returns the complete updated document object. The fields are the same as the response parameters of CreateDocument.
DeleteDocument
Description
Deletes a document asynchronously by setting deleting and dispatching deletion. graph_status does not block deletion; an ongoing graph build is allowed to finish before deletion executes.
Required state: ingest_status must be succeeded or failed. Other in-progress states return HTTP 400, such as document cannot be deleted while ingest is in progress (status: processing). Already deleting is an idempotent success without event_id. Already deleted returns HTTP 400: document not found.
Request syntax
DELETE /v1/knowledge/documentsRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
document_id | string | Yes | The document ID |
|
Response parameters
Name | Type | Description | Example |
event_id | string | The asynchronous deletion event ID. If the document is already being deleted, this field is not returned |
|
document_id | string | The document ID |
|
status | string | The document status, which is fixed as |
|
BatchDeleteDocuments
Description
Deletes documents asynchronously in a batch using DeleteDocument rules. Individual failures do not stop the batch; their error appears in the corresponding result. Returns a unified envelope.
Empty ids or more than 50 IDs returns HTTP 400.
Request syntax
DELETE /v1/knowledge/documents/batchRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
ids | array | Yes | Up to 50 document IDs. An empty list returns HTTP 400. |
|
Response parameters (in the data field)
Name | Type | Description | Example |
total | integer | The number of documents processed. |
|
succeeded | integer | The number of successful records |
|
failed | integer | The number of failed records |
|
results | array | Per-item results. See fields below. | See the following table |
Elements of the results array:
Name | Type | Description | Example |
id | string | The document ID |
|
success | boolean | Whether this item succeeded. |
|
error | string | The failure reason, omitted on success. |
|
ListDocumentChunks
Description
Lists document chunks. total is the document's total chunk count, independent of offset and limit.
If ingest_status is ai_reviewing or pending_review and chunk review is pending, returns review_status as pending, an empty chunks array, and total of 0.
Request syntax
GET /v1/knowledge/documents/chunksRequest parameters
Name | Type | Required | Description | Example |
knowledge_base_id | string | No* | The knowledge base ID. Specify either this parameter or name |
|
knowledge_base_name | string | No* | The knowledge base name |
|
document_id | string | Yes | The document ID |
|
offset | integer | No | The start offset. Default value: |
|
limit | integer | No | The number of entries to return. Default value: |
|
with_recall_count | boolean | No | Whether to include recall statistics. Default: |
|
Response parameters
Name | Type | Description | Example |
document_id | string | The document ID |
|
total | integer | The document's total chunk count, independent of offset/limit. |
|
chunks | array | The list of chunks. For the fields of each element, see the following table | See the following table |
review_status | string | Returns |
|
Elements of the chunks array:
Name | Type | Description | Example |
chunk_id | string | The chunk ID |
|
chunk_index | integer | The chunk index |
|
toc_path | string | The table-of-contents path. If no value exists, the value is an empty string |
|
content | string | The chunk content without the toc_path prefix |
|
recall_count | integer | Lifetime recall count, returned only with |
|
recall_count_7d | integer | Recalls in the last seven days, returned only with |
|
recall_count_30d | integer | Recalls in the last 30 days, returned only with |
|
last_recalled_at | string | The latest recall time, returned only with |
|
QueryKnowledge
Description
Performs semantic retrieval combining vector and keyword search with optional reranking. For top_k >= 3, attempts to include GraphRAG synthetic chunks. Unavailable graph indexes or graph retrieval errors fall back to ordinary chunks. Responses use page 1 and page_size=64. Real chunks may include temporary download URLs, media attachments, page numbers, and document metadata.
Request syntax
POST /v1/knowledge/queryRequest parameters
Name | Type | Required | Description | Example |
question | string | Yes | The query question. Empty input returns HTTP 400. |
|
knowledge_base_ids | array | No | The list of knowledge base IDs. The alias |
|
knowledge_base_names | array | No | KB names, combined with IDs as a union. An empty resolved set returns HTTP 400. |
|
document_ids | array | No | Limits the document scope |
|
top_k | integer | No | Result count. Default: |
|
similarity_threshold | float | No | Similarity threshold. Default: |
|
vector_weight | float | No | Vector weight. Default: |
|
rerank | boolean | No | Specifies whether to enable reranking. Default value: |
|
query_rewrite | boolean | No | Specifies whether to enable query rewriting. Default value: |
|
metadata_condition | object | No | The document-level metadata filter condition. Both the flat form and the structured form are supported (see below) |
|
Description of metadata_condition: Filters the documents that participate in recall by document-level custom metadata. Two forms are supported:
Flat form:
{"key": value}. All keys are matched by equality with AND logic. If value is a list, the condition matches when any element matches.Structured form:
{
"logic": "and",
"conditions": [
{
"name": "version",
"comparison_operator": "is",
"value": "v1.2"
},
{
"name": "year",
"comparison_operator": ">",
"value": 2023
}
]
}Structured form fields:
Name | Type | Required | Description | Example |
logic | string | No | Condition logic: |
|
conditions | array | Yes | The condition list. See fields below. | See the following table |
conditions elements:
Name | Type | Required | Description | Example |
name | string | Yes | The metadata key. |
|
comparison_operator | string | Yes | Operator: |
|
value | any | No* | The comparison value. Not required for |
|
Substring and numeric comparisons evaluate metadata first, then filter by document IDs. More than 60,000 matching documents returns HTTP 400: metadata_condition matched too many documents (N), please narrow the condition.
Response parameters
Name | Type | Description | Example |
chunks | array | Returned chunks. Real and optional GraphRAG synthetic chunks combined do not exceed top_k. | See below |
total | integer | The real document chunk count in this response, excluding GraphRAG chunks. Limited by top_k and graph quotas, not the total recall match count. | 1 |
doc_aggs | array | Aggregations of returned real chunks, with doc_name, doc_id, and count. | See the example |
Elements of the chunks array:
Name | Type | Description | Example |
chunk_id | string | The chunk ID. For a GraphRAG chunk, a UUID generated for this response. | chunk-001 |
content_with_weight | string | The chunk text. | For database connection pools, set the maximum number of connections to... |
toc_path | string | The table-of-contents path. Empty when unavailable for real chunks; omitted for GraphRAG chunks. |
|
doc_id | string | The source document ID. Empty for GraphRAG chunks. | doc-001 |
docnm_kwd | string | The source document name. Fixed to Related content in Knowledge Graph for GraphRAG chunks. |
|
kb_id | string | array | The KB ID for real chunks, or the searched KB ID list for GraphRAG chunks. | kb-001 |
tag_kwd | array | An empty array for real chunks; [graphrag] for GraphRAG chunks. | [] |
important_kwd | array | Compatibility field, currently an empty array. | [] |
similarity | number | The combined score used for sorting and threshold filtering, rounded to two decimal places. | 0.89 |
vector_similarity | number | The vector component, rounded to two decimal places. | 0.91 |
term_similarity | number | The keyword component, rounded to two decimal places. | 0.85 |
rerank_score | number | null | The reranking score. Null if reranking is skipped, no result is assigned to the candidate, or reranking fails. | 0.93 |
doc_metadata | object | Optional document metadata, omitted if unset. | {version: v1.2} |
page_start | integer | Optional inclusive starting page of a PDF-VLM semantic chunk, numbered from 1. | 2 |
page_end | integer | Optional inclusive ending page of a PDF-VLM semantic chunk, numbered from 1. | 3 |
download_url | string | Optional presigned URL, valid for 60 seconds. Returned when download URLs are enabled and the source snapshot is valid. | https://... |
attachments | array | Optional image, audio, or video attachments. Unavailable assets/snapshots and signing failures cause the affected attachment to be omitted. | See the following description. |
attachments fields:
Field | Type | Required | Applicability and description |
type | string | Yes | Attachment type: image, video, or audio. |
description | string | No | A visual description for images, or a segment transcript/description for audio and video. |
download_url | string | Yes | The presigned attachment URL, valid for 24 hours. If URL generation fails, the entire attachment is omitted. |
asset_id | string | No | Images only: the knowledge document asset ID. |
page_no | integer | null | No | Images only: the page number, starting at 1, for page-image sources. |
source | string | No | Images only: the source, such as markdown_inline, pdf_page, or upload. |
start_ms | integer | No | Audio/video only: the segment start in milliseconds relative to the media start. May be null. |
end_ms | integer | null | No | Audio/video only: the segment end in milliseconds. May be null. |
GraphRAG synthetic chunks contain graph narratives and common scoring fields only. They reference no real document or snapshot, so they omit document paths, metadata, pages, download URLs, and attachments.
Name | Type | Description | Example |
doc_id | string | Always an empty string; synthetic chunks have no real source document. | "" |
docnm_kwd | string | Fixed to Related content in Knowledge Graph. | Related content in Knowledge Graph |
kb_id | array | The searched KB ID list. | [kb-001] |
tag_kwd | array | Fixed to [graphrag] to identify synthetic chunks. | [graphrag] |
Elements of the doc_aggs array:
Name | Type | Description | Example |
doc_name | string | The document name |
|
doc_id | string | The document ID |
|
count | integer | The number of chunks hit in the document |
|
Examples
Request body:
{
"question": "How to configure a database connection pool",
"knowledge_base_ids": [
"kb-001"
],
"top_k": 5
}Sample success response:
{
"chunks": [
{
"chunk_id": "chunk-001",
"content_with_weight": "For database connection pools, set the maximum number of connections to...",
"toc_path": "",
"doc_id": "doc-001",
"docnm_kwd": "operations-manual.md",
"kb_id": "kb-001",
"tag_kwd": [],
"important_kwd": [],
"similarity": 0.89,
"vector_similarity": 0.91,
"term_similarity": 0.85,
"rerank_score": 0.93,
"doc_metadata": {
"version": "v1.2"
},
"page_start": 2,
"page_end": 3,
"download_url": "<presigned-download-url>",
"attachments": [
{
"type": "image",
"description": "Database connection pool parameters diagram",
"asset_id": "asset-001",
"page_no": 2,
"source": "pdf_page",
"download_url": "<presigned-media-url>"
}
]
}
],
"total": 1,
"doc_aggs": [
{
"doc_name": "operations-manual.md",
"doc_id": "doc-001",
"count": 1
}
],
"page": 1,
"page_size": 64
}ListKnowledgeEntities
Description
Lists knowledge base entities. size applies separately to each accessible KB. Without kb_id, returns up to size entities from every accessible KB and concatenates them, so total can exceed size.
Sorting: PageRank descending within each KB; no global PageRank order is guaranteed after concatenation.
Request syntax
GET /v1/knowledge/entitiesRequest parameters
Name | Type | Required | Description | Example |
kb_id | string | No | The KB ID. If omitted, queries all accessible KBs. |
|
document_id | string | No | The filter by document ID |
|
size | integer | No | Entities per KB. Default: |
|
Response parameters
Name | Type | Description | Example |
entities | array | Entities sorted by PageRank descending within each KB. See fields below. | See the following table |
total | integer | The returned entity count across all KBs, which can exceed |
|
Elements of the entities array:
Name | Type | Description | Example |
entity_id | string | The unique identifier of the entity |
|
entity_name | string | The entity name |
|
entity_type | string | The entity type |
|
pagerank | float | The PageRank score, which is the sort basis |
|
ListKnowledgeEntityRelations
Description
Lists knowledge base relationships. Without entity_ids, uses the top max_nodes PageRank entities as anchors before querying edges. With entity_ids, directly queries edges for those IDs.
As with ListKnowledgeEntities, max_nodes and max_edges apply separately to each accessible KB. Without kb_id, concatenated results can have total greater than max_edges.
Out-of-range values: max_nodes and max_edges are silently clamped to boundaries, without HTTP 400.
Request syntax
GET /v1/knowledge/entity-relationsRequest parameters
Name | Type | Required | Description | Example |
kb_id | string | No | The KB ID. If omitted, queries all accessible KBs. |
|
document_id | string | No | The filter by document ID |
|
entity_ids | string | No | Comma-separated entity IDs. If provided, anchor selection by |
|
max_nodes | integer | No | Anchor limit. Default: |
|
max_edges | integer | No | Relationship limit. Default: |
|
Response parameters
Name | Type | Description | Example |
relations | array | The list of relations. For the fields of each element, see the following table | See the following table |
total | integer | The number of relations returned by this request |
|
Elements of the relations array:
Name | Type | Description | Example |
source_entity_id | string | The source entity ID |
|
target_entity_id | string | The destination entity ID |
|
relation_type | string | The relation type |
|
weight | float | The relation weight |
|