# Query document details

Query the current segment version, index version, and segment content of a source document. Use this interface to save the current version and index version before editing a segment.

```text
GET https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/sources/{source_row_id}/document
```

## Preparation before calling

First [query the data source list](list-data-sources.md) to obtain the source record ID. 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 the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$MODEL_ID`: Knowledge Base ID.
- `$SOURCE_ROW_ID`: Source record ID.
- `$SEGMENT_VERSION_ID`: The segment version ID to be read; if not passed, the current version is read.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/sources/$SOURCE_ROW_ID/document?segment_version_id=$SEGMENT_VERSION_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameters | Type | Description |
| --- | --- | --- |
| `model_id` | integer | Knowledge base ID. |
| `source_row_id` | string | Source record ID. |

## Query parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `segment_version_id` | string | No | The segment version ID to be read; if not passed, the current version will be read. |

## Successful response

Returns `200` on success. `data` Returns a document preview, version list, and segmented content for the selected version.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "source": {
      "row_id": "src_01",
      "model_id": 401,
      "source_type": "file",
      "ingest_status": "ready"
    },
    "preview": {
      "available": true,
      "content": "产品说明"
    },
    "file_info": {
      "tags": ["product"],
      "enabled": true,
      "effective_enabled": true,
      "index_version": 2,
      "segment_version_id": "ver_02"
    },
    "segment_status": {
      "available": true,
      "total": 1
    },
    "current_segment_version_id": "ver_02",
    "current_index_version": 2,
    "segment_versions": [
      {
        "version_id": "ver_02",
        "current": true,
        "index_version": 2,
        "chunk_count": 1
      }
    ],
    "segments": [
      {
        "segment_id": "seg_01",
        "segment_type": "text",
        "level": "chunk",
        "content": "产品说明",
        "enabled": true
      }
    ]
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.source` | object | Source record. |
| `data.preview.available` | boolean | Whether preview content is available. |
| `data.preview.content` | string | Preview content when available. |
| `data.preview.reason` | string | Reason the preview is unavailable, when applicable. |
| `data.file_info` | object | File tags, expiration and activation information. |
| `data.file_info.effective_enabled` | boolean | Current actual effective status. |
| `data.segment_status.available` | boolean | Whether segments are available. |
| `data.segment_status.total` | integer | Number of segments. |
| `data.current_segment_version_id` | string | Current segment version ID. |
| `data.current_index_version` | integer | Current index version. |
| `data.segment_versions` | object[] | All available segment versions; may be omitted if the source has not completed parsing or no segment versions have been generated. |
| `data.segment_versions[].version_id` | string | Segment version ID. |
| `data.segment_versions[].current` | boolean | Whether this is the current segment version. |
| `data.segments` | object[] | Segments in the selected version. |
| `data.segments[].segment_id` | string | Segment ID. |
| `data.segments[].content` | string | Segment content. |
| `data.segments[].enabled` | boolean | Whether the segment is enabled. |

In field paths, `[]` means each item in an array. For example, `data.segment_versions[].version_id` is the `version_id` field of each item in `data.segment_versions`.

## Error response

```json
{
  "code": "ErrNotFound",
  "msg": "resource not found",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - `model_id` is invalid or `source_row_id` is empty.
  - Get the path ID from the source list.
* - `401`
  - `ErrUnauthorized`
  - The API Key is invalid or has expired.
  - Check API Key.
* - `403`
  - `ErrForbidden`
  - The caller does not have permission to read the source document.
  - Check workspace and object authorization.
* - `404`
  - `ErrNotFound`
  - The knowledge base or source does not exist or is not visible to the current caller.
  - Reconfirm the path ID.
* - `500`
  - `ErrServer`
  - The service failed to read the document or segment.
  - Keep the desensitized response information and try again.
```

## Follow-up operations

When you need to add content, [Create segments](create-segment.md); when modifying an existing segment, [Update segments](update-segment.md).
