After you upload a document, the system splits it into chunks. Each chunk stores vector data and the original text as the smallest retrieval unit. Use the following APIs to view and update chunks.
View chunks
Call list_chunks to paginate through chunks of a specified document.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
The name of the knowledge base. Required. |
|
|
string |
The name of the subspace. Required if subspaces are enabled. |
|
|
string |
The document ID. Required if |
|
|
string |
The OSS path of the document. Required if |
|
|
int |
Maximum results to return. Default: 10. Maximum: 1,000. |
|
|
string |
The next token for pagination. |
Code example
resp = client.list_chunks({
"knowledgeBaseName": "product_docs_kb",
"docId": "fc6ed97f-...",
"maxResults": 5
})
for chunk in resp["data"]["chunkDetails"]:
print(f"[Chunk {chunk['chunkId']}] ({chunk['status']}) {chunk['content'][:80]}...")
Response fields
|
Parameter |
Type |
Description |
|
|
string |
Subspace of the chunk. |
|
|
int |
The ID of the chunk. |
|
|
string |
The content of the chunk. |
|
|
string |
The title of the chunk. |
|
|
string |
Chunk type, such as |
|
|
string |
Status: |
|
|
string |
ID of the document that contains the chunk. |
|
|
string |
OSS path of the document that contains the chunk. |
|
|
int |
The creation timestamp. |
|
|
int |
The update timestamp. |
|
|
string |
Pagination token. Empty if this is the last page. |
Update chunks
Call update_chunks to batch-update the title, content, or status of chunks.
Request parameters
|
Parameter |
Type |
Description |
|
|
string |
The name of the knowledge base. Required. |
|
|
string |
The name of the subspace. Required if subspaces are enabled. |
|
|
list<object> |
List of chunks to update. Required. Maximum: 10 per request. Note
To increase this limit, submit a ticket or join the Tablestore DingTalk support group (ID: 36165029092). |
|
|
string |
The document ID. Required if |
|
|
string |
The OSS path of the document. Required if |
|
|
int |
The ID of the chunk. Required. |
|
|
string |
New chunk title. |
|
|
string |
New chunk content. |
|
|
string |
New status: |
Code examples
Update the content of a chunk:
resp = client.update_chunks({
"knowledgeBaseName": "product_docs_kb",
"chunks": [
{
"docId": "fc6ed97f-...",
"chunkId": 1,
"title": "Updated title",
"content": "Updated content"
}
]
})
Set a chunk to inactive to block inaccurate content:
resp = client.update_chunks({
"knowledgeBaseName": "product_docs_kb",
"chunks": [
{
"docId": "fc6ed97f-...",
"chunkId": 0,
"status": "inactive"
}
]
})
Response fields
|
Parameter |
Type |
Description |
|
|
string |
The ID of the document. |
|
|
string |
The OSS path of the document. |
|
|
int |
The ID of the chunk. |
|
|
string |
Update result: |
|
|
string |
Failure reason. Returned only when the update status is |
Usage notes
-
Setting a chunk's
statustoinactiveremoves it from retrieval results. Use this to temporarily block inaccurate content without deleting the document.