Knowledge base management

Updated at:

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.com

Authentication

All Data API operations are authenticated by a workspace-level API key. Use one of the following methods:

Method

Header format

X-API-Key

X-API-Key: <YOUR_API_KEY>

Token

Authorization: Token <YOUR_API_KEY>

Bearer

Authorization: Bearer <YOUR_API_KEY>

Common conventions

  • The server supplies workspace_id and member_id from 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: knowledge base not found: xxx or document not found: xxx.

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 review_template_id and latest_graph_event_id.

UpdateDocumentMetadata

Overwrites the document-level custom metadata in full.

DeleteDocument

Deletes a document asynchronously by setting deleting and dispatching deletion.

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_bases

Request parameters

Name

Type

Required

Description

Example

name

string

Yes

The knowledge base name. Unique within the workspace; silently truncated to 255 characters.

Product documentation base

description

string

No

The knowledge base description

Stores product technical documents

chunk_size

integer

No

Chunk size. Default: 512. Valid range: [100, 2048]. Out-of-range values return HTTP 400.

512

chunk_overlap

integer

No

Chunk overlap. Default: 76. Must be below 30% of chunk_size; for chunk_size=512, the maximum is 152. Invalid values return HTTP 400.

76

graph_enabled

boolean

No

Specifies whether to enable the knowledge graph. Default value: true

true

review_enabled

boolean

No

Specifies whether to enable ingestion review. Default value: false

false

Response parameters

Name

Type

Description

Example

id

string

The knowledge base ID

kb-001

workspace_id

string

The workspace ID

ws-001

owner_member_id

string

The member ID of the owner

member-001

name

string

The knowledge base name

Product documentation base

description

string

Description

Stores product technical documents

status

string

The status

active

graph_enabled

boolean

Indicates whether the knowledge graph is enabled

true

review_enabled

boolean

Indicates whether review is enabled

false

created_at

string

The creation time

2026-06-01T00:00:00Z

updated_at

string

The update time

2026-06-01T00:00:00Z

Note

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_bases

Request 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.

3

Elements of the knowledge_bases array:

Name

Type

Description

Example

id

string

The knowledge base ID

kb-001

workspace_id

string

The workspace ID

ws-001

owner_member_id

string

The member ID of the owner

member-001

name

string

The knowledge base name

Product documentation base

description

string

Description

Stores product technical documents

status

string

The status

active

graph_enabled

boolean

Indicates whether the knowledge graph is enabled

true

review_enabled

boolean

Indicates whether review is enabled

false

key_entities

array

Up to five key entity names.

["ContextDB","RDS"]

created_at

string

The creation time

2026-06-01T00:00:00Z

updated_at

string

The update time

2026-06-01T10:00:00Z

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/detail

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name. Specify either this parameter or the ID

Product documentation base

Note

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_bases

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

Yes

The knowledge base ID (query parameter)

kb-001

knowledge_base_name

string

No

The new name in the request body.

New documentation base

description

string

No

The new description in the request body.

Updated description

graph_enabled

boolean

No

Whether to enable the graph, specified in the body.

true

review_enabled

boolean

No

Whether to enable review, specified in the body.

true

Note

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_bases

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name. Specify either this parameter or the ID

Product documentation base

Response parameters

Name

Type

Description

Example

deleted

boolean

Indicates whether the memory is deleted

true

knowledge_base_id

string

The knowledge base ID

kb-001

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/documents

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

name

string

Yes

The document name, silently truncated to 255 characters.

troubleshooting-guide.md

text

string

Yes

The document text. Blank content returns HTTP 400.

# Troubleshooting ...

mime_type

string

No

The MIME type. Default: text/plain. Also accepts the alias mimeType.

text/markdown

file_path

string

No

The file path, stored as metadata and included in the logical document key.

/docs/troubleshoot.md

source_type

string

No

The source type. Defaults to text when omitted.

text

review_enabled

boolean

No

Specifies whether to review the document. If it is not specified, the knowledge base setting applies

true

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.

tpl-001

metadata

object

No

Document metadata as a flat map of scalars or scalar lists, used by metadata_condition filters. See validation rules below.

{"version":"v1.2","tags":["ml","prod"]}

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

source_type, content_hash, snapshot_id, and toc_path are prohibited.

Value type

Scalars (string, number, or boolean) or lists of scalars only.

Clearing values

null or an empty object leaves metadata unset or clears it.

Response parameters

Returns the document object:

Name

Type

Description

Example

id

string

The document ID

doc-001

workspace_id

string

The workspace ID

ws-001

knowledge_base_id

string

The knowledge base ID

kb-001

name

string

The document name

troubleshooting-guide.md

file_path

string

The file path. If no value exists, the value is an empty string

/docs/troubleshoot.md

source_type

string

The source type

manual

mime_type

string

The MIME type

text/markdown

ingest_status

string

Ingestion status: pending, uploading, processing, ai_reviewing, pending_review, succeeded, failed, deleting, or deleted.

processing

latest_ingest_event_id

string

The ID of the most recent ingestion event

evt-ing-001

review_template_id

string

The document-level review rewrite template ID, or null if unspecified.

null

ingest_error_message

string

The ingestion failure reason. If no failure exists, the value is null

null

chunk_count

integer

The number of chunks

12

token_count

integer

The number of tokens

4096

graph_status

string

Graph build status: pending, queued, processing, succeeded, failed, or skipped.

succeeded

latest_graph_event_id

string

The latest graph build event ID, or null if unavailable.

null

graph_version

integer

The graph version

1

pending_chunk_change_count

integer

The number of chunk changes pending graph synchronization

0

metadata

object

The document-level custom metadata. If it is not set, the value is an empty object

{"version":"v1.2"}

size_bytes

integer

The document size in bytes

20480

created_at

string

The creation time

2026-06-01T00:00:00Z

updated_at

string

The update time

2026-06-01T00:05:00Z

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; or

  • Specify 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/documents

Request parameters

Name

Type

Required

Description

Example

document_id

string

No*

The document ID, mutually exclusive with logical-key fields.

doc-001

knowledge_base_id

string

No*

The KB ID for logical-key lookup, as an alternative to the KB name.

kb-001

knowledge_base_name

string

No*

The KB name for logical-key lookup.

Product documentation base

name

string

No*

The document name for logical-key lookup. Required if document_id is omitted.

troubleshooting-guide.md

file_path

string

No

The file path for logical-key lookup.

/docs/troubleshoot.md

text

string

Yes

The new document text. Blank content returns HTTP 400.

# Troubleshooting ...

mime_type

string

No

The MIME type, inherited from the old document if omitted.

text/markdown

source_type

string

No

The source type, inherited from the old document if omitted.

text

review_enabled

boolean

No

Specifies whether to review the document. If it is not specified, the knowledge base setting applies

true

review_template_id

string

No

The document-level review template ID. Omission inherits it; an empty value clears it.

tpl-001

metadata

object

No

Document metadata. Omission inherits it; an empty object clears it. Validation matches CreateDocument.

{"version":"v2"}

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)

Note

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/files

Request 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

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

name

string

No

The document name. If it is not specified, the file name is used

design-doc.pdf

file_path

string

No

The file path, stored as metadata and included in the logical document key.

/uploads/design.pdf

review_enabled

boolean

No

Specifies whether to review the document. If it is not specified, the knowledge base setting applies

false

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.

tpl-001

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 metadata parameter of CreateDocument

{"version":"v1.2"}

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/files

Request 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.

doc-001

knowledge_base_id

string

No*

The KB ID for logical-key lookup, as an alternative to the KB name.

kb-001

knowledge_base_name

string

No*

The KB name for logical-key lookup.

Product documentation base

name

string

No*

The document name for logical-key lookup. Defaults to the filename when document_id is omitted.

design-doc.pdf

file_path

string

No

The file path for logical-key lookup.

/uploads/design.pdf

review_enabled

boolean

No

Specifies whether to review the document. If it is not specified, the knowledge base setting applies

false

review_template_id

string

No

The document-level review template ID, inherited if omitted.

tpl-001

metadata

string

No

Document metadata as a JSON object string. Omission inherits it; an empty object clears it.

{"version":"v2"}

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-upload

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

Yes

The knowledge base ID (query parameter)

kb-001

file_name

string

Yes

The original filename for extension validation and size classification.

training-video.mp4

name

string

No

The document name. Defaults to file_name.

Training video

file_path

string

No

The file path, included in the logical document key.

/media/train.mp4

mime_type

string

No

The MIME type. Default: application/octet-stream.

video/mp4

metadata

string

No

Document metadata as a JSON object string. Validation matches CreateDocument metadata.

{"version":"v1"}

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.

tpl-001

Response parameters

Name

Type

Description

Example

document_id

string

The new document ID.

doc-001

knowledge_base_id

string

The knowledge base ID

kb-001

upload_ticket

string

The upload ticket, valid for one hour.

eyJ0eXAi...

chunk_size

integer

The recommended part size in bytes, corresponding to 10 MB.

10485760

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-upload

Request parameters

Name

Type

Required

Description

Example

document_id

string

No*

The document ID as a query parameter, mutually exclusive with KB locator fields.

doc-001

knowledge_base_id

string

No*

The KB ID for logical-key lookup.

kb-001

file_name

string

Yes

The original filename for extension validation and size classification.

training-video.mp4

name

string

No*

The document name for logical-key lookup. Required if document_id is omitted.

Training video

file_path

string

No

The file path for logical-key lookup.

/media/train.mp4

mime_type

string

No

The MIME type, inherited from the old document if omitted.

video/mp4

metadata

string

No

Document metadata as a JSON object string, inherited if omitted.

{"version":"v2"}

review_template_id

string

No

The document-level review template ID, inherited if omitted.

tpl-001

Response parameters

Name

Type

Description

Example

document_id

string

The placeholder document ID for this upload.

doc-002

knowledge_base_id

string

The knowledge base ID

kb-001

upload_ticket

string

The upload ticket, valid for one hour.

eyJ0eXAi...

chunk_size

integer

The recommended part size in bytes, corresponding to 10 MB.

10485760

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/chunks

Request parameters

Name

Type

Required

Description

Example

X-Upload-Ticket

string

Yes

The upload ticket in the request header. Workspace mismatches return HTTP 403.

eyJ0eXAi...

part_number

integer

Yes

The part number as a form field. Must be at least 1, or returns HTTP 400.

1

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.

1

etag

string

The part ETag to pass back when completing the upload.

"9BB58F26192E4BA00F01E2E7B136BBD8"

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/complete

Request parameters

Name

Type

Required

Description

Example

X-Upload-Ticket

string

Yes

The upload ticket in the request header. Workspace mismatches return HTTP 403.

eyJ0eXAi...

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.

1

etag

string

Yes

The ETag returned by part upload.

"9BB58F26192E4BA00F01E2E7B136BBD8"

Response parameters

Name

Type

Description

Example

document_id

string

The document ID, or the reused old document ID after deduplication.

doc-001

knowledge_base_id

string

The knowledge base ID

kb-001

status

string

The document status: processing for parsing, or succeeded when deduplication reuses the old document.

processing

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/abort

Request parameters

Name

Type

Required

Description

Example

X-Upload-Ticket

string

Yes

The upload ticket in the request header. Workspace mismatches return HTTP 403.

eyJ0eXAi...

Response parameters (in the data field)

Name

Type

Description

Example

document_id

string

The document ID

doc-001

status

string

Fixed to aborted.

aborted

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/documents

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

page

integer

No

The page number. Default: 1. Values below 1 become 1.

1

page_size

integer

No

Items per page. Default: 50. Maximum: 100. Out-of-range values are clamped.

20

sort_by

string

No

Sort field. Default: created_at. Supports name, created_at, updated_at, chunk_count, token_count, ingest_status, graph_status, and pending_chunk_change_count. Invalid values return HTTP 400.

updated_at

sort_order

string

No

Sort direction: asc or desc. Default: desc. Invalid values return HTTP 400.

desc

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.

42

page

integer

The current page number. This field is returned only when pagination parameters are specified

1

page_size

integer

The number of entries per page. This field is returned only when pagination parameters are specified

20

Additional recall statistics in documents elements:

Name

Type

Description

Example

recall_count

integer

The total number of recalls

5

recall_count_7d

integer

Recalls in the last seven days.

2

recall_count_30d

integer

Recalls in the last 30 days.

4

last_recalled_at

string

The time of the most recent recall. If the memory has never been recalled, the value is null

2026-06-01T10:00:00Z

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/detail

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

document_id

string

Yes

The document ID

doc-001

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/metadata

Request parameters

Name

Type

Required

Description

Example

document_id

string

Yes

The document ID

doc-001

metadata

object

No

The new document-level metadata, which overwrites the existing metadata in full. A null or empty object clears the metadata. The validation rules are the same as those of the metadata parameter of CreateDocument

{"version":"v2"}

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/documents

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

document_id

string

Yes

The document ID

doc-001

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

evt-del-001

document_id

string

The document ID

doc-001

status

string

The document status, which is fixed as deleting

deleting

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/batch

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

ids

array

Yes

Up to 50 document IDs. An empty list returns HTTP 400.

["doc-001","doc-002"]

Response parameters (in the data field)

Name

Type

Description

Example

total

integer

The number of documents processed.

2

succeeded

integer

The number of successful records

1

failed

integer

The number of failed records

1

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

doc-001

success

boolean

Whether this item succeeded.

true

error

string

The failure reason, omitted on success.

document cannot be deleted while ingest is in progress (status: processing)

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/chunks

Request parameters

Name

Type

Required

Description

Example

knowledge_base_id

string

No*

The knowledge base ID. Specify either this parameter or name

kb-001

knowledge_base_name

string

No*

The knowledge base name

Product documentation base

document_id

string

Yes

The document ID

doc-001

offset

integer

No

The start offset. Default value: 0

0

limit

integer

No

The number of entries to return. Default value: 20

10

with_recall_count

boolean

No

Whether to include recall statistics. Default: false.

true

Response parameters

Name

Type

Description

Example

document_id

string

The document ID

doc-001

total

integer

The document's total chunk count, independent of offset/limit.

12

chunks

array

The list of chunks. For the fields of each element, see the following table

See the following table

review_status

string

Returns pending only while the document is under review; chunks is then empty and total is 0.

pending

Elements of the chunks array:

Name

Type

Description

Example

chunk_id

string

The chunk ID

chunk-001

chunk_index

integer

The chunk index

0

toc_path

string

The table-of-contents path. If no value exists, the value is an empty string

Chapter 1 > Overview

content

string

The chunk content without the toc_path prefix

Database connection pool configuration...

recall_count

integer

Lifetime recall count, returned only with with_recall_count=true.

5

recall_count_7d

integer

Recalls in the last seven days, returned only with with_recall_count=true.

2

recall_count_30d

integer

Recalls in the last 30 days, returned only with with_recall_count=true.

4

last_recalled_at

string

The latest recall time, returned only with with_recall_count=true. null if never recalled.

2026-06-01T10:00:00Z

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/query

Request parameters

Name

Type

Required

Description

Example

question

string

Yes

The query question. Empty input returns HTTP 400.

How to configure a database connection pool

knowledge_base_ids

array

No

The list of knowledge base IDs. The alias dataset_ids is compatible but deprecated. Use knowledge_base_ids instead

["kb-001","kb-002"]

knowledge_base_names

array

No

KB names, combined with IDs as a union. An empty resolved set returns HTTP 400.

["Product documentation base"]

document_ids

array

No

Limits the document scope

["doc-001"]

top_k

integer

No

Result count. Default: 6. Maximum: 64, with higher values clamped. Nonpositive values return HTTP 400.

10

similarity_threshold

float

No

Similarity threshold. Default: 0.6.

0.6

vector_weight

float

No

Vector weight. Default: 0.7. Nonpositive values force the effective threshold to 0. The alias vector_similarity_weight is deprecated; use vector_weight.

0.7

rerank

boolean

No

Specifies whether to enable reranking. Default value: true

true

query_rewrite

boolean

No

Specifies whether to enable query rewriting. Default value: false

false

metadata_condition

object

No

The document-level metadata filter condition. Both the flat form and the structured form are supported (see below)

{"version":"v1.2"}

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: and or or. Default: and. Invalid values return HTTP 400.

and

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.

version

comparison_operator

string

Yes

Operator: is, is not, contains, not contains, empty, not empty, >, <, >=, or <=. Unsupported values return HTTP 400.

is

value

any

No*

The comparison value. Not required for empty or not empty; required for other operators, or HTTP 400 is returned.

v1.2

Note

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.

Chapter 1 > Overview

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.

operations-manual.md

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

operations-manual.md

doc_id

string

The document ID

doc-001

count

integer

The number of chunks hit in the document

3

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/entities

Request parameters

Name

Type

Required

Description

Example

kb_id

string

No

The KB ID. If omitted, queries all accessible KBs.

kb-001

document_id

string

No

The filter by document ID

doc-001

size

integer

No

Entities per KB. Default: 500. No range clamping.

100

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 size.

120

Elements of the entities array:

Name

Type

Description

Example

entity_id

string

The unique identifier of the entity

entity-001

entity_name

string

The entity name

ContextDB

entity_type

string

The entity type

product

pagerank

float

The PageRank score, which is the sort basis

0.023

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-relations

Request parameters

Name

Type

Required

Description

Example

kb_id

string

No

The KB ID. If omitted, queries all accessible KBs.

kb-001

document_id

string

No

The filter by document ID

doc-001

entity_ids

string

No

Comma-separated entity IDs. If provided, anchor selection by max_nodes is skipped.

entity-001,entity-002

max_nodes

integer

No

Anchor limit. Default: 2000. Valid range: [50, 8000]. Out-of-range values are clamped.

500

max_edges

integer

No

Relationship limit. Default: 5000. Valid range: [100, 20000]. Out-of-range values are clamped.

1000

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

50

Elements of the relations array:

Name

Type

Description

Example

source_entity_id

string

The source entity ID

entity-001

target_entity_id

string

The destination entity ID

entity-002

relation_type

string

The relation type

depends_on

weight

float

The relation weight

0.8