# 複製知識版本

此 API 用於**複製指定的 Fileset**，建立一份全新的副本。  
新 Fileset 會繼承原本的檔案清單與使用者自訂的 metadata，名稱為 `Copy of {原名稱}`，狀態為 `draft`。你可以針對新 Fileset 進行修改、補充檔案，或重新 Commit 建立新的知識版本。任何狀態的 Fileset 都可以複製。

```bash
curl -X 'POST' \
  'http://127.0.0.1:8000/v1/filesets/{fileset_id}/duplicate' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $PRIVAI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "a9d335d7-7c57-424d-9c55-b6c4c690d65e"
  }'
```

#### Request Headers

| Key | Value |
| --- | --- |
| Request Method | POST |
| accept | application/json |
| Authorization | `Bearer $PRIVAI_API_KEY` |
| Content-Type | application/json（有帶 Request Body 時） |

#### Path Parameters

| Field | Type | Note | Required |
| --- | --- | --- | --- |
| fileset_id | string | uuid，要複製的來源 Fileset | true |

#### Request Body

Request Body 為選填，可整個省略。

| Field | Type | Detail | Required |
| --- | --- | --- | --- |
| id | string (uuid) | 指定複製出的新 Fileset 要使用的 UUID；省略則自動產生。已存在時回傳 `FILESET_002` | false |

#### Response Body

**Status Code：201 Created**

```json
{
  "object": "fileset",
  "id": "a9d335d7-7c57-424d-9c55-b6c4c690d65e",
  "name": "Copy of Company Policy Files v1.0",
  "metadata": {
    "tag": ["policy", "operation"],
    "copy_from": "c7ea032b-eb16-4ccb-94a6-88af66db5d22",
    "embedding_model": null,
    "parsing_mode": null
  },
  "state": "draft",
  "created_at": "2025-07-01T00:00:00.000Z",
  "committed_at": null,
  "updated_at": "2025-07-01T00:00:00.000Z",
  "file_counts": {
    "draft": 1,
    "queued": 0,
    "processing": 0,
    "completed": 0,
    "failed": 0,
    "total": 1
  }
}
```

**Field Explanation**  
回傳「[知識版本物件](https://privstation-docs.apmic.ai/latest/privai-400/知識版本物件.md)」章節列表內容。

- 在複製 Fileset 時，系統會自動於 metadata 中加入 `copy_from` 欄位，記錄來源 Fileset 的 ID，方便後續追蹤來源關係與管理版本差異。若來源本身也是複製而來，`copy_from` 會被更新為本次的來源 ID。

- 新 Fileset 尚未 commit，因此 `metadata.embedding_model`、`metadata.parsing_mode` 為 null，所有檔案的 Fileset File State 皆為 `draft`。

#### 常見錯誤代碼

| Error Code | HTTP Status | 情境 |
| --- | --- | --- |
| FILESET_001 | 404 | 來源 Fileset 不存在 |
| FILESET_002 | 409 | 以 `id` 指定的 Fileset ID 已存在 |
| — | 422 | `id` 不是合法 uuid，或帶入未定義的欄位 |

身份驗證錯誤（`AUTH_001`～`AUTH_003`）詳見「錯誤代碼說明-身份驗證類」章節；知識版本相關錯誤碼完整說明請參考 [錯誤代碼說明-知識版本管理類](https://privstation-docs.apmic.ai/latest/privai-400/錯誤代碼說明-知識版本管理類.md)。
