# Query knowledge base details

Query model definitions and source quantities by knowledge base ID. You should use this interface to confirm the current status before updating or deleting.

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

## Preparation before calling

First [query the knowledge base list](list-knowledge-bases.md) to obtain the knowledge base 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`: ID of the knowledge base to be queried.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_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. |

## Successful response

Returns `200` on success. `data` is the knowledge base definition and source number.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 401,
    "name": "product_docs",
    "description": "产品文档",
    "tables": [],
    "files": [],
    "source_counts": {
      "files": 2,
      "tables": 1,
      "total": 3
    },
    "created_at": 1735632000,
    "updated_at": 1735718400
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.id` | integer | Knowledge base ID. |
| `data.name` | string | Knowledge base name. |
| `data.description` | string | Knowledge base description; may be omitted if not set. |
| `data.tables` | JSON | Compatible legacy table source definition. |
| `data.files` | JSON | Compatible legacy file source definition; may be omitted if not set. |
| `data.source_counts` | object | The current number of sources. |
| `data.source_counts.files` | integer | Number of file sources. |
| `data.source_counts.tables` | integer | Number of table sources. |
| `data.source_counts.total` | integer | Total number of sources. |
| `data.created_at` | integer | Unix timestamp. |
| `data.updated_at` | integer | Unix timestamp. |

## 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 not a valid integer.
  - Use the knowledge base `id` in the response.
* - `401`
  - `ErrUnauthorized`
  - The API Key is invalid or has expired.
  - Check API Key.
* - `403`
  - `ErrForbidden`
  - The caller does not have permission to read the knowledge base.
  - Check workspace and object authorization.
* - `404`
  - `ErrNotFound`
  - The knowledge base does not exist or is not visible to the current caller.
  - Relist the knowledge base and confirm the ID.
* - `500`
  - `ErrServer`
  - The service failed to read the knowledge base.
  - Keep the desensitized response information and try again.
```

## Follow-up operations

When you need to modify attributes, [Update knowledge base](update-knowledge-base.md); when accessing data, [Add data source](add-data-sources.md).
