Create segments¶
Creates a segment in the current snapshot of the source. A new text, OCR, or image description segment can be provided by source content.
POST $CLOUDSIGMA_API_BASE/semantic-models/{model_id}/sources/{source_row_id}/segments
Before you call¶
Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region.
First query the knowledge base document details and obtain data.etag, which is used to check whether the document has changed during the modification period. Prepare a personal access token and target workspace ID that can access the target workspace.
The source must be a file source, which already has the knowledge base file ID kb_file_id, and is configured with an available vector index. Table sources do not support segmented writes.
Request body¶
Replace $MODEL_ID, $SOURCE_ROW_ID, $CLOUDSIGMA_API_KEY, $WORKSPACE_ID in the example with actual values.
curl -X POST "$CLOUDSIGMA_API_BASE/semantic-models/$MODEL_ID/sources/$SOURCE_ROW_ID/segments" \
-H "X-API-Key: $CLOUDSIGMA_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"if_match": "<DOCUMENT_ETAG>",
"level": "chunk",
"content": "<SEGMENT_CONTENT>"
}'
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
integer |
Yes |
Belonging knowledge base ID. |
|
string |
Yes |
Source record ID. |
Request body
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
|
|
string |
No |
Chunk level. Defaults to |
|
string or null |
No |
Text segment content. |
|
string or null |
No |
OCR recognized text. |
|
string or null |
No |
Image content description. |
|
null |
No |
Specifying image files through this request is currently not supported, so omit or fill in null. |
|
null |
No |
Currently, specifying page images through this request is not supported, so omit or fill in null. |
|
object |
No |
Boundary information of the segment in the original content. Supports JSON values such as objects and arrays. |
|
object |
No |
Segmented custom information. When omitted, it is generated by the service, and the system fields are subject to the values written by the service. |
The segment level uses chunk by default, and currently only chunk can be saved. When using doc or section, even if the pre-check passes, it will fail in the save phase after generating the embedding vector.
Successful response¶
{
"code": "OK",
"msg": "OK",
"data": {
"document": {
"source": {
"row_id": "src_01",
"source_type": "file",
"model_id": 401,
"resource_id": "",
"display_name": null,
"path": [],
"db_name": null,
"table_name": null,
"size_bytes": null,
"row_count": null,
"ingest_status": null,
"enabled": null,
"expires_at": null,
"expired": false,
"effective_enabled": false,
"force_enabled_after_expiry": false,
"updated_at": null,
"error": null
},
"preview": {
"available": false
},
"file_info": {
"tags": null,
"expires_at": null,
"enabled": null,
"expired": false,
"effective_enabled": false,
"force_enabled_after_expiry": false
},
"segment_status": {
"available": true,
"total": 3
},
"etag": "<NEW_DOCUMENT_ETAG>",
"segments": [
{
"segment_id": "seg_03",
"level": "chunk",
"content": "新增分段",
"word_count": 0,
"recall_count": 0,
"enabled": true
}
]
}
}
}
Field |
Type |
Description |
|---|---|---|
|
object |
A snapshot of the source document after writing. |
|
object |
Source. |
|
string |
Record ID. |
|
string |
Source ID. |
|
string |
Source type. Value: |
|
integer |
Model ID. |
|
string |
Resource ID. |
|
string |
Source resource ID. |
|
string |
knowledge base resource ID. |
|
string |
Source file ID. |
|
string |
knowledge base file ID. |
|
integer |
Source table ID. |
|
integer |
knowledge base table ID. |
|
string or null |
Display name. |
|
array of string |
path. |
|
string |
Source path. |
|
string or null |
Database name. |
|
string or null |
Table name. |
|
integer or null |
size in bytes. |
|
integer or null |
Number of rows. |
|
string or null |
Import status. Values: |
|
boolean or null |
Whether to enable. |
|
integer or null |
Expiration time. |
|
boolean |
Has it expired? |
|
boolean |
actual enabled status. |
|
boolean |
Whether to force activation after expiration. |
|
array of string |
tag list. |
|
string |
Creator. |
|
string |
Last updated by. |
|
integer or null |
Update time. |
|
string or null |
error message. |
|
string |
Management status. Value: |
|
string |
Old source information. Value: |
|
object |
Preview content. |
|
boolean |
is available. |
|
string |
Business content. |
|
string |
Reason. |
|
object |
File information. |
|
array of string or null |
tag list. |
|
integer or null |
Expiration time. |
|
boolean or null |
Whether to enable. |
|
boolean |
Has it expired? |
|
boolean |
actual enabled status. |
|
boolean |
Whether to force activation after expiration. |
|
object |
Segmentation status. |
|
boolean |
is available. |
|
string |
Reason. |
|
integer |
The number of records that match the current query conditions. |
|
string |
Next page cursor. |
|
string |
ETag of the current document snapshot. |
|
array of object |
Segmented list. |
|
string |
Segment ID. |
|
integer |
Starting millisecond position. |
|
integer |
End millisecond position. |
|
string |
level. Value: |
|
integer |
Content block sequence number. |
|
string |
Content block ID. |
|
string |
Business content. |
|
string |
OCR text. |
|
string |
Image description. |
|
string |
Image file ID. |
|
string |
Page image file ID. |
|
integer |
word count. |
|
integer |
Number of recalls. |
|
boolean |
Whether to enable. |
|
object |
Additional information for segments. |
|
integer |
Volume ID. |
Query the knowledge base document details to confirm that the new segment has taken effect. Use the ETag of the new snapshot when continuing modifications. When the old ETag is inconsistent with the current snapshot, 409 and ErrConflict are returned. The snapshot should be reread and the modifications should be confirmed.
Error response¶
Returns 400 and ErrParamInvalid when no valid ETag is provided. When the ETag is inconsistent with the current snapshot, 409 and ErrConflict are returned. An error description is returned in the requested language.
{
"code": "ErrParamInvalid",
"msg": "<ERROR_MESSAGE>",
"data": null
}
Field |
Type |
Description |
|---|---|---|
|
string |
error code. |
|
string |
Error description. |
|
null |
|