# Verify semantic entries

Verify whether the current knowledge base and its semantic entries comply with the server contract.

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

## 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`: Knowledge base ID to be verified.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/validate" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameters | Type | Description |
| --- | --- | --- |
| `model_id` | integer | The ID of the knowledge base to be verified. |

## Successful response

Returns `200` on success. HTTP is successful but `data.valid` is `false`, indicating that the model has not passed business verification; press `errors` to correct the entry or source and call again.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "valid": false,
    "errors": ["entry total_rows is invalid"]
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.valid` | boolean | Whether the current knowledge base passes the server-side verification. |
| `data.errors` | string[] | Error list when verification fails; may be omitted or empty when verification passes. |

`[]` after a type means an array. For example, `string[]` is an array of strings.

## 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.
  - Use the knowledge base ID from the response.
* - `401`
  - `ErrUnauthorized`
  - The API Key is invalid or has expired.
  - Check API Key.
* - `403`
  - `ErrForbidden`
  - The caller does not have permission to use the knowledge base.
  - Check workspace and object authorization.
* - `404`
  - `ErrNotFound`
  - The knowledge base does not exist or is not visible.
  - Reconfirm `model_id`.
* - `500`
  - `ErrServer`
  - The service failed to perform verification.
  - Keep the desensitized response information and try again.
```

## Follow-up operations

After pressing `errors` to correct it, [Query semantic entries](list-semantic-entries.md) confirms the entry definition, and then calls this interface again.
