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.

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

Shell
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

model_id

integer

Yes

Belonging knowledge base ID.

source_row_id

string

Yes

Source record ID.

Request body

Field

Type

Required

Description

if_match

string

No

data.etag read before calling. It can be omitted when using If-Match request header.

level

string

No

Chunk level. Defaults to chunk when omitted. Accepts doc, section, chunk, or an empty string; only chunk can currently be saved.

content

string or null

No

Text segment content.

ocr_text

string or null

No

OCR recognized text.

image_description

string or null

No

Image content description.

image_file_id

null

No

Specifying image files through this request is currently not supported, so omit or fill in null.

page_image_file_id

null

No

Currently, specifying page images through this request is not supported, so omit or fill in null.

bbox

object

No

Boundary information of the segment in the original content. Supports JSON values ​​such as objects and arrays.

metadata

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

JSON
{
  "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

data.document

object

A snapshot of the source document after writing.

data.document.source

object

Source.

data.document.source.row_id

string

Record ID.

data.document.source.source_id

string

Source ID.

data.document.source.source_type

string

Source type. Value: file, table.

data.document.source.model_id

integer

Model ID.

data.document.source.resource_id

string

Resource ID.

data.document.source.source_resource_id

string

Source resource ID.

data.document.source.kb_resource_id

string

knowledge base resource ID.

data.document.source.source_file_id

string

Source file ID.

data.document.source.kb_file_id

string

knowledge base file ID.

data.document.source.source_table_id

integer

Source table ID.

data.document.source.kb_table_id

integer

knowledge base table ID.

data.document.source.display_name

string or null

Display name.

data.document.source.path

array of string

path.

data.document.source.source_path

string

Source path.

data.document.source.db_name

string or null

Database name.

data.document.source.table_name

string or null

Table name.

data.document.source.size_bytes

integer or null

size in bytes.

data.document.source.row_count

integer or null

Number of rows.

data.document.source.ingest_status

string or null

Import status. Values: removed, pending, succeeded, failed.

data.document.source.enabled

boolean or null

Whether to enable.

data.document.source.expires_at

integer or null

Expiration time.

data.document.source.expired

boolean

Has it expired?

data.document.source.effective_enabled

boolean

actual enabled status.

data.document.source.force_enabled_after_expiry

boolean

Whether to force activation after expiration.

data.document.source.tags

array of string

tag list.

data.document.source.created_by

string

Creator.

data.document.source.updated_by

string

Last updated by.

data.document.source.updated_at

integer or null

Update time.

data.document.source.error

string or null

error message.

data.document.source.governance_status

string

Management status. Value: managed, legacy_unbound.

data.document.source.legacy_origin

string

Old source information. Value: semantic_model_explicit, lineage_register.

data.document.preview

object

Preview content.

data.document.preview.available

boolean

is available.

data.document.preview.content

string

Business content.

data.document.preview.reason

string

Reason.

data.document.file_info

object

File information.

data.document.file_info.tags

array of string or null

tag list.

data.document.file_info.expires_at

integer or null

Expiration time.

data.document.file_info.enabled

boolean or null

Whether to enable.

data.document.file_info.expired

boolean

Has it expired?

data.document.file_info.effective_enabled

boolean

actual enabled status.

data.document.file_info.force_enabled_after_expiry

boolean

Whether to force activation after expiration.

data.document.segment_status

object

Segmentation status.

data.document.segment_status.available

boolean

is available.

data.document.segment_status.reason

string

Reason.

data.document.segment_status.total

integer

The number of records that match the current query conditions.

data.document.segment_status.next_cursor

string

Next page cursor.

data.document.etag

string

ETag of the current document snapshot.

data.document.segments

array of object

Segmented list.

data.document.segments[].segment_id

string

Segment ID.

data.document.segments[].start_ms

integer

Starting millisecond position.

data.document.segments[].end_ms

integer

End millisecond position.

data.document.segments[].level

string

level. Value: chunk.

data.document.segments[].chunk_index

integer

Content block sequence number.

data.document.segments[].chunk_id

string

Content block ID.

data.document.segments[].content

string

Business content.

data.document.segments[].ocr_text

string

OCR text.

data.document.segments[].image_description

string

Image description.

data.document.segments[].image_file_id

string

Image file ID.

data.document.segments[].page_image_file_id

string

Page image file ID.

data.document.segments[].word_count

integer

word count.

data.document.segments[].recall_count

integer

Number of recalls.

data.document.segments[].enabled

boolean

Whether to enable.

data.document.segments[].metadata

object

Additional information for segments.

data.document.segments[].metadata.volume_id

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.

JSON
{
  "code": "ErrParamInvalid",
  "msg": "<ERROR_MESSAGE>",
  "data": null
}

Field

Type

Description

code

string

error code.

msg

string

Error description.

data

null

null on error.

Last updated on