diff --git a/en-us/user-guide/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.mdx b/en-us/user-guide/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.mdx index ea0471bf..b9174f36 100644 --- a/en-us/user-guide/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.mdx +++ b/en-us/user-guide/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.mdx @@ -684,3 +684,148 @@ Response example: | document\_already\_finished | 400 | The document has been processed. Please refresh the page or go to the document details. | | document\_indexing | 400 | The document is being processed and cannot be edited. | | invalid\_metadata | 400 | The metadata content is incorrect. Please check and verify. | + +#### Add Metadata Fields to the Knowledge Base + +Request example: + +```bash +curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/metadata' \ +--header 'Content-Type: application/json' \ +--header 'Authorization: Bearer {api_key}' \ +--data '{ + "type":"string", + "name":"test" +}' +``` + +Response example: + +```json +{ + "id": "9f63c91b-d60e-4142-bb0c-c81a54dc2db5", + "type": "string", + "name": "test" +} +``` + +#### Modify Metadata Fields in the Knowledge Base + +Request example: + +```bash +curl --location --request PATCH 'https://api.dify.ai/v1/datasets/{dataset_id}/metadata/{metadata_id}' \ +--header 'Content-Type: application/json' \ +--header 'Authorization: Bearer {api_key}' \ +--data '{ + "name":"test" +}' +``` + +Response example: + +```json +{ + "id": "9f63c91b-d60e-4142-bb0c-c81a54dc2db5", + "type": "string", + "name": "test" +} +``` + +#### Delete Metadata Fields in the Knowledge Base + +Request example: + +```bash +curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/document/metadata/{metadata_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +Response example: + +```json +200 success +``` + +#### Enable/Disable Built-in Fields in the Knowledge Base + +Request example: + +```bash +curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/document/metadata/built-in/{action}' \ +--header 'Authorization: Bearer {api_key}' +``` + +Response example: + +```json +200 success +``` + +#### Modify Metadata for a Single Document (Assignment) + +Request example: + +```bash +curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/metadata' \ +--header 'Content-Type: application/json' \ +--header 'Authorization: Bearer {api_key}' +--data '{ + "operation_data":[ + { + "document_id": "3e928bc4-65ea-4201-87c8-cbcc5871f525", + "metadata_list": [ + { + "id": "1887f5ec-966f-4c93-8c99-5ad386022f46", + "value": "dify", + "name": "test" + } + ] + } + ] +}' +``` + +Response example: + +```json +200 success +``` + +#### Metadata List of the Dataset + +Request example: + +```bash +curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/metadata' \ +--header 'Authorization: Bearer {api_key}' +``` + +Response example: + +```json +{ + "doc_metadata": [ + { + "id": "550e8400-e29b-41d4-a716-446655440000", + "type": "string", + "name": "title", + "use_count": 42 + }, + { + "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", + "type": "number", + "name": "price", + "use_count": 28 + }, + { + "id": "7ba7b810-9dad-11d1-80b4-00c04fd430c9", + "type": "time", + "name": "created_at", + "use_count": 35 + } + ], + "built_in_field_enabled": true +} +``` +