Delete segment¶
Removes the specified segment from the current version of the source. It cannot be restored after deletion.
DELETE https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/sources/{source_row_id}/segments/{segment_id}
Preparation before calling¶
First query the document details, obtain the current segment version ID and index version as the baseline, and confirm the segment ID to be deleted. Prepare a personal access token and target workspace ID that has access to the target workspace.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: Target workspace ID, passed throughX-Workspace-IDHeader.$MODEL_ID: Knowledge Base ID.$SOURCE_ROW_ID: Source record ID.$SEGMENT_ID: Segment ID to delete.
Request example¶
curl -X DELETE "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/sources/$SOURCE_ROW_ID/segments/$SEGMENT_ID" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"base_segment_version_id": "<SEGMENT_VERSION_ID>",
"base_index_version": <INDEX_VERSION>
}'
Path parameters¶
Parameters |
Type |
Description |
|---|---|---|
|
integer |
Knowledge base ID. |
|
string |
Source record ID. |
|
string |
The segment ID to delete. |
Request body¶
Commit the current version baseline of the source to avoid deleting versions that have been modified by other callers.
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
The current segment version ID read before the call. |
|
integer |
Yes |
The current index version read before the call. |
Successful response¶
Returns 200 and the deleted source document snapshot on success.
{
"code": "OK",
"msg": "OK",
"data": {
"document": {
"source": {
"row_id": "src_01",
"model_id": 401
},
"segment_status": {
"available": true,
"total": 1
},
"segment_versions": [
{
"version_id": "ver_03",
"current": true,
"chunk_count": 1
}
],
"segments": [
{
"segment_id": "seg_02",
"enabled": true
}
]
}
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
object |
Snapshot of the source document after deletion. |
|
string |
Source record ID. |
|
integer |
The current number of segments after deletion. |
|
string |
The segment version ID generated or switched to after deletion. |
|
object[] |
The remaining segments of the current version. |
|
string |
Remaining segment ID. |
In field paths, [] means each item in an array. For example, data.document.segment_versions[].version_id is the version_id field of each item in data.document.segment_versions.
Error response¶
{
"code": "ErrConflict",
"msg": "segment version conflict",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
The path ID, request body, or staging version baseline is invalid. |
Submit using the current version information after re-reading the document. |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have permission to delete segments. |
Check workspace and object authorization. |
|
|
The knowledge base, source, or segment does not exist or is not visible to the current caller. |
Reread document confirmation ID. |
|
|
The current version has changed and the service refuses to delete it. |
Retry after reading the latest document. |
|
|
The service failed to delete the segment. |
Keep the desensitized response information and try again. |
Follow-up operations¶
Query document details Confirm that the segment has been deleted.