diff --git a/en/SUMMARY.md b/en/SUMMARY.md index deb621bdf..b368dc6f0 100644 --- a/en/SUMMARY.md +++ b/en/SUMMARY.md @@ -114,6 +114,7 @@ * [Annotation](guides/annotation/README.md) * [Logs and Annotation](guides/annotation/logs.md) * [Annotation Reply](guides/annotation/annotation-reply.md) + * [Maintain Annotation via API](guides/annotation/maintain-annotation-via-api.md) * [Monitoring](guides/monitoring/README.md) * [Data Analysis](guides/monitoring/analysis.md) * [Integrate External Ops Tools](guides/monitoring/integrate-external-ops-tools/README.md) diff --git a/en/guides/annotation/maintain-annotation-via-api.md b/en/guides/annotation/maintain-annotation-via-api.md new file mode 100644 index 000000000..c80805563 --- /dev/null +++ b/en/guides/annotation/maintain-annotation-via-api.md @@ -0,0 +1,147 @@ +# Maintain Annotations via API + +> Authentication and invocation methods are consistent with the App Service API. + +Maintaining annotations via API allows for operations such as adding, deleting, updating, and querying annotations. This provides more comprehensive third-party system integration capabilities. + +## How to Use + +Enter the workspace, go to the application, and click on Access API on the left side. Click on API Key in the upper right corner, then click Create Key. This will give you a key specific to this application. The API interface will recognize the application based on this key. + +## API Call Examples + +### Get Annotation List + +```bash +curl --location --request GET 'https://api.dify.ai/v1/apps/annotations?page=1&limit=20' \ +--header 'Authorization: Bearer {api_key}' +``` + +Output Example: + +```json +{ + "data": [ + { + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 + } + ], + "has_more": false, + "limit": 20, + "total": 1, + "page": 1 +} +``` + +### Create Annotation + +```bash +curl --location --request POST 'https://api.dify.ai/v1/apps/annotations' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "question": "What is your name?", + "answer": "I am Dify." +}' +``` + +Output Example: + +```json +{ + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 +} +``` + +### Update Annotation + +```bash +curl --location --request PUT 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "question": "What is your name?", + "answer": "I am Dify." +}' +``` + +Output Example: + +```json +{ + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 +} +``` + +### Delete Annotation + +```bash +curl --location --request DELETE 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +Output Example: + +```json +{"result": "success"} +``` + +### Initial Annotation Reply Settings + +```bash +curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "score_threshold": 0.9, + "embedding_provider_name": "zhipu", + "embedding_model_name": "embedding_3" +}' +``` + +Parameter Description: +- `action`: Can only be `enable` or `disable` +- `embedding_model_provider`: Specified embedding model provider, must be set up in the system first, corresponding to the provider field +- `embedding_model`: Specified embedding model, corresponding to the model field +- `score_threshold`: The similarity threshold for matching annotated replies. Only annotations with scores above this threshold will be recalled. + +The provider and model name of the embedding model can be obtained through the following interface: `v1/workspaces/current/models/model-types/text-embedding`. For specific instructions, see: [Maintain Knowledge Base via API](guides/knowledge-base/maintain-dataset-via-api.md). The Authorization used is the Dataset API Token. + +Output Example: + +```json +{ + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", + "job_status": "waiting" +} +``` +This interface is executed asynchronously, so it will return a job_id. You can get the final execution result by querying the job status interface. + +### Query Initial Annotation Reply Settings Task Status + +```bash +curl --location --request GET 'https://api.dify.ai/v1/apps/annotation-reply/{action}/status/{job_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +Output Example: + +```json +{ + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", + "job_status": "waiting", + "error_msg": "" +} +``` \ No newline at end of file diff --git a/en/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md b/en/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md index a40f744b3..63f84962b 100644 --- a/en/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md +++ b/en/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md @@ -27,7 +27,7 @@ This api is based on an existing Knowledge and creates a new document through te Request example: -```json +```bash curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_text' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ @@ -77,7 +77,7 @@ curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/doc --form 'file=@"/path/to/file"' ``` -```bash +```json { "document": { "id": "", @@ -114,8 +114,8 @@ This api is based on an existing Knowledge and creates a new document through a Request example: -```json -curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file' \ +```bash +curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{"indexing_technique":"high_quality","process_rule":{"rules":{"pre_processing_rules":[{"id":"remove_extra_spaces","enabled":true},{"id":"remove_urls_emails","enabled":true}],"segmentation":{"separator":"###","max_tokens":500}},"mode":"custom"}}";type=text/plain' \ --form 'file=@"/path/to/file"' @@ -208,41 +208,203 @@ Response example: { "data": [ { - "id": "", - "name": "name", - "description": "desc", + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", "permission": "only_me", - "data_source_type": "upload_file", - "indexing_technique": "", - "app_count": 2, - "document_count": 10, - "word_count": 1200, - "created_by": "", - "created_at": "", - "updated_by": "", - "updated_at": "" - }, - ... + "data_source_type": null, + "indexing_technique": null, + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735620612, + "embedding_model": null, + "embedding_model_provider": null, + "embedding_available": true, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + } + } ], - "has_more": true, + "has_more": false, "limit": 20, - "total": 50, + "total": 1, "page": 1 } ``` -### Delete a Knowledge Base +### **View Knowledge Base** +Get knowledge base details by knowledge base ID -Request example: +```bash +curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +Response example: + +输出示例: ```json +{ + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", + "permission": "only_me", + "data_source_type": null, + "indexing_technique": null, + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735620612, + "embedding_model": null, + "embedding_model_provider": null, + "embedding_available": true, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + } +} +``` + +### **Update Knowledge Base** +Update a knowledge base by knowledge base ID + +```bash +curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{"name": "Test Knowledge Base", "indexing_technique": "high_quality", "permission": "only_me",\ + "embedding_model_provider": "zhipuai", "embedding_model": "embedding-3", "retrieval_model": "", "partial_member_list": []}' +``` + +Parameters: +- indexing_technique: high_quality, economy, None +- permission: only_me, all_team_members, partial_members (this partial_members option specifies team members) +- embedding_model_provider: specified embedding model provider, must be set up in the system first, corresponding to the provider field +- embedding_model: specified embedding model, corresponding to the model field +- retrieval_model: specified retrieval model, corresponding to the model field + +The provider and model name of the embedding model can be obtained through the following interface: +v1/workspaces/current/models/model-types/text-embedding. For specific instructions, see the following text. +The Authorization used is the Dataset API Token. + +Response example: + +```json +{ + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", + "permission": "only_me", + "data_source_type": null, + "indexing_technique": "high_quality", + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735622679, + "embedding_model": "embedding-3", + "embedding_model_provider": "zhipuai", + "embedding_available": null, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + }, + "partial_member_list": [] +} +``` + +### Delete a knowledge base + +Request example: + +```bash curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}' \ --header 'Authorization: Bearer {api_key}' ``` Response example: -```json +``` 204 No Content ``` @@ -414,7 +576,7 @@ Response example: "disabled_at": null, "disabled_by": null, "archived": false - }, + } ], "has_more": false, "limit": 20, @@ -655,7 +817,6 @@ Response example: } ``` - ### Add Metadata Fields to the Knowledge Base Request example: @@ -714,7 +875,7 @@ curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/m Response example: -```json +``` 200 success ``` @@ -729,7 +890,7 @@ curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/m Response example: -```json +``` 200 success ``` @@ -759,7 +920,7 @@ curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/metadata Response example: -```json +``` 200 success ``` @@ -800,6 +961,88 @@ Response example: } ``` +### Get available embedding models + +```bash +curl --location --request GET 'http://localhost:5001/v1/workspaces/current/models/model-types/text-embedding' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' +``` + +```json +{ + "data": [ + { + "provider": "zhipuai", + "label": { + "zh_Hans": "智谱 AI", + "en_US": "ZHIPU AI" + }, + "icon_small": { + "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/zh_Hans", + "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/en_US" + }, + "icon_large": { + "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/zh_Hans", + "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/en_US" + }, + "status": "active", + "models": [ + { + "model": "embedding-3", + "label": { + "zh_Hans": "embedding-3", + "en_US": "embedding-3" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 8192 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + }, + { + "model": "embedding-2", + "label": { + "zh_Hans": "embedding-2", + "en_US": "embedding-2" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 8192 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + }, + { + "model": "text_embedding", + "label": { + "zh_Hans": "text_embedding", + "en_US": "text_embedding" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 512 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + } + ] + } + ] +} +``` + + ### Error message Response example: diff --git a/zh_CN/SUMMARY.md b/zh_CN/SUMMARY.md index 024b8ba26..3bb456fb2 100644 --- a/zh_CN/SUMMARY.md +++ b/zh_CN/SUMMARY.md @@ -114,6 +114,7 @@ * [标注](guides/annotation/README.md) * [日志与标注](guides/annotation/logs.md) * [标注回复](guides/annotation/annotation-reply.md) + * [通过 API 维护标注](guides/annotation/maintain-annotation-via-api.md) * [监测](guides/monitoring/README.md) * [集成外部 Ops 工具](guides/monitoring/integrate-external-ops-tools/README.md) * [集成 LangSmith](guides/monitoring/integrate-external-ops-tools/integrate-langsmith.md) diff --git a/zh_CN/guides/annotation/maintain-annotation-via-api.md b/zh_CN/guides/annotation/maintain-annotation-via-api.md new file mode 100644 index 000000000..7102ea5a4 --- /dev/null +++ b/zh_CN/guides/annotation/maintain-annotation-via-api.md @@ -0,0 +1,149 @@ +# 通过 API 维护标注 + +> 鉴权、调用方式与App Service API 保持一致。 + +通过 API 维护标注,可以实现标注的增、删、改、查等操作。提供更加完整的第三方系统集成能力。 + +## 如何使用 + +进入工作室,进入应用,在左侧点击访问API。在右上角点击API密钥,然后点击创建密钥。即可获得这个应用专用的密钥。API接口会根据该密钥识别应用。 + +## API调用示例 + +### 获取标注列表 + +```bash +curl --location --request GET 'https://api.dify.ai/v1/apps/annotations?page=1&limit=20' \ +--header 'Authorization: Bearer {api_key}' +``` + +输出示例: + +```json +{ + "data": [ + { + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 + } + ], + "has_more": false, + "limit": 20, + "total": 1, + "page": 1 +} +``` + +### 创建标注 + +```bash +curl --location --request POST 'https://api.dify.ai/v1/apps/annotations' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "question": "What is your name?", + "answer": "I am Dify." +}' +``` + +输出示例: + +```json +{ + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 +} +``` + +### 更新标注 + +```bash +curl --location --request PUT 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "question": "What is your name?", + "answer": "I am Dify." +}' +``` + +输出示例: + +```json +{ + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", + "question": "What is your name?", + "answer": "I am Dify.", + "hit_count": 0, + "created_at": 1735625869 +} +``` + +### 删除标注 + +```bash +curl --location --request DELETE 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +输出示例: + +```json +{"result": "success"} +``` + +### 标注回复初始设置 + +```bash +curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "score_threshold": 0.9, + "embedding_provider_name": "zhipu", + "embedding_model_name": "embedding_3" +}' +``` + +入参说明: +- `action`: 只能是enable或者disable +- `embedding_model_provider`: 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段 +- `embedding_model`: 指定的嵌入模型,对应的是model字段 +- `score_threshold`: 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复 + +嵌入模型的提供商和模型名称可以通过以下接口获取:`v1/workspaces/current/models/model-types/text-embedding`, +具体见:[通过 API 维护知识库](guides/knowledge-base/maintain-dataset-via-api.md)。 +使用的Authorization是Dataset的API Token + +输出示例: + +```json +{ + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", + "job_status": "waiting" +} +``` +该接口是异步执行,所以会返回一个job_id,通过查询job状态接口可以获取到最终的执行结果。 + +### 查询标注回复初始设置任务状态 + +```bash +curl --location --request GET 'https://api.dify.ai/v1/apps/annotation-reply/{action}/status/{job_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +输出示例: + +```json +{ + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", + "job_status": "waiting", + "error_msg": "" +} +``` \ No newline at end of file diff --git a/zh_CN/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md b/zh_CN/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md index 4832bab7a..0a8ac6c2c 100644 --- a/zh_CN/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md +++ b/zh_CN/guides/knowledge-base/knowledge-and-documents-maintenance/maintain-dataset-via-api.md @@ -27,7 +27,7 @@ 输入示例: -```json +```bash curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-text' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ @@ -72,8 +72,8 @@ curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/doc 输入示例: -```json -curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file' \ +```bash +curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{"indexing_technique":"high_quality","process_rule":{"rules":{"pre_processing_rules":[{"id":"remove_extra_spaces","enabled":true},{"id":"remove_urls_emails","enabled":true}],"segmentation":{"separator":"###","max_tokens":500}},"mode":"custom"}}";type=text/plain' \ --form 'file=@"/path/to/file"' @@ -166,41 +166,201 @@ curl --location --request GET 'https://api.dify.ai/v1/datasets?page=1&limit=20' { "data": [ { - "id": "", - "name": "知识库名称", - "description": "描述信息", + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", "permission": "only_me", - "data_source_type": "upload_file", - "indexing_technique": "", - "app_count": 2, - "document_count": 10, - "word_count": 1200, - "created_by": "", - "created_at": "", - "updated_by": "", - "updated_at": "" - }, - ... + "data_source_type": null, + "indexing_technique": null, + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735620612, + "embedding_model": null, + "embedding_model_provider": null, + "embedding_available": true, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + } + } ], - "has_more": true, + "has_more": false, "limit": 20, - "total": 50, + "total": 1, "page": 1 } ``` +### **获取知识库详情** +通过知识库ID查看知识库详情 + +```bash +curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}' \ +--header 'Authorization: Bearer {api_key}' +``` + +输出示例: + +```json +{ + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", + "permission": "only_me", + "data_source_type": null, + "indexing_technique": null, + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735620612, + "embedding_model": null, + "embedding_model_provider": null, + "embedding_available": true, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + } +} +``` + +### **修改知识库** +通过知识库ID修改知识库信息 + +```bash +curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' \ +--data-raw '{"name": "Test Knowledge Base", "indexing_technique": "high_quality", "permission": "only_me",\ + "embedding_model_provider": "zhipuai", "embedding_model": "embedding-3", "retrieval_model": "", "partial_member_list": []}' +``` + +入参选项: +- `indexing_technique`: high_quality, economy, None +- `permission`: only_me, all_team_members, partial_members (此partial_members选项是指定团队成员) +- `embedding_model_provider`: 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段 +- `embedding_model`: 指定的嵌入模型,对应的是model字段 +- `retrieval_model`: 指定的检索模型,对应的是model字段 + +嵌入模型的提供商和模型名称可以通过以下接口获取:`v1/workspaces/current/models/model-types/text-embedding`,具体说明见后文。 +使用的Authorization是Dataset的API Token + +输出示例 +: +```json +{ + "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f", + "name": "Test Knowledge Base", + "description": "", + "provider": "vendor", + "permission": "only_me", + "data_source_type": null, + "indexing_technique": "high_quality", + "app_count": 0, + "document_count": 0, + "word_count": 0, + "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "created_at": 1735620612, + "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6", + "updated_at": 1735622679, + "embedding_model": "embedding-3", + "embedding_model_provider": "zhipuai", + "embedding_available": null, + "retrieval_model_dict": { + "search_method": "semantic_search", + "reranking_enable": false, + "reranking_mode": null, + "reranking_model": { + "reranking_provider_name": "", + "reranking_model_name": "" + }, + "weights": null, + "top_k": 2, + "score_threshold_enabled": false, + "score_threshold": null + }, + "tags": [], + "doc_form": null, + "external_knowledge_info": { + "external_knowledge_id": null, + "external_knowledge_api_id": null, + "external_knowledge_api_name": null, + "external_knowledge_api_endpoint": null + }, + "external_retrieval_model": { + "top_k": 2, + "score_threshold": 0.0, + "score_threshold_enabled": null + }, + "partial_member_list": [] +} +``` + + ### 删除知识库 输入示例: -```json +```bash curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}' \ --header 'Authorization: Bearer {api_key}' ``` 输出示例: -```json +``` 204 No Content ``` @@ -374,7 +534,7 @@ curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/docu "disabled_at": null, "disabled_by": null, "archived": false - }, + } ], "has_more": false, "limit": 20, @@ -557,6 +717,8 @@ curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/ret }' ``` +输出示例: + ```bash { "query": { @@ -668,7 +830,7 @@ curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/m 输出示例: -```bash +``` 200 success ``` @@ -683,7 +845,7 @@ curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/m 输出示例: -```json +``` 200 success ``` @@ -708,12 +870,12 @@ curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/metadata ] } ] -}' +} ``` 输出示例: -```json +``` 200 success ``` @@ -754,6 +916,90 @@ curl --location 'https://api.dify.ai/v1/datasets/{dataset_id}/metadata' \ } ``` + +### 获取嵌入模型列表 + +```bash +curl --location --request GET 'http://localhost:5001/v1/workspaces/current/models/model-types/text-embedding' \ +--header 'Authorization: Bearer {api_key}' \ +--header 'Content-Type: application/json' +``` + +输出示例: + +```json +{ + "data": [ + { + "provider": "zhipuai", + "label": { + "zh_Hans": "智谱 AI", + "en_US": "ZHIPU AI" + }, + "icon_small": { + "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/zh_Hans", + "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/en_US" + }, + "icon_large": { + "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/zh_Hans", + "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/en_US" + }, + "status": "active", + "models": [ + { + "model": "embedding-3", + "label": { + "zh_Hans": "embedding-3", + "en_US": "embedding-3" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 8192 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + }, + { + "model": "embedding-2", + "label": { + "zh_Hans": "embedding-2", + "en_US": "embedding-2" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 8192 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + }, + { + "model": "text_embedding", + "label": { + "zh_Hans": "text_embedding", + "en_US": "text_embedding" + }, + "model_type": "text-embedding", + "features": null, + "fetch_from": "predefined-model", + "model_properties": { + "context_size": 512 + }, + "deprecated": false, + "status": "active", + "load_balancing_enabled": false + } + ] + } + ] +} +``` + ### 错误信息 示例: