dify 是否支持API方式创建知识库且创建文档向量化存储呢 ? #3985

Closed
opened 2026-02-21 18:04:15 -05:00 by yindo · 1 comment
Owner

Originally created by @wangyao123456a on GitHub (Jun 5, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.3.21

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

1

✔️ Expected Behavior

1

Actual Behavior

1

Originally created by @wangyao123456a on GitHub (Jun 5, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.3.21 ### Cloud or Self Hosted Cloud, Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce 1 ### ✔️ Expected Behavior 1 ### ❌ Actual Behavior 1
yindo closed this issue 2026-02-21 18:04:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 5, 2024):

是的,Dify 版本 0.3.21 支持通过 API 创建知识库并进行文档向量化存储。

以下是相关的 API 代码示例:

  1. 通过 API 创建知识库(数据集)

    curl --location --request POST 'https://api.dify.ai/v1/datasets' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{"name": "name"}'
    
  2. 文档向量化和存储

    • 通过文本创建文档

      curl --location --request POST 'https://api.dify.ai/v1/datasets/<uuid:dataset_id>/document/create_by_text>' \
      --header 'Authorization: Bearer {api_key}' \
      --header 'Content-Type: application/json' \
      --data-raw '{
          "name": "Dify",
          "text": "Dify means Do it for you...",
          "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"
          }
      }'
      
    • 通过文件创建文档

      curl --location POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \
      --header 'Authorization: Bearer {api_key}' \
      --form 'data="{
          "name": "Dify",
          "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"'
      
    • 获取文档嵌入状态

      curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{batch}/indexing-status' \
      --header 'Authorization: Bearer {api_key}'
      
    • 删除文档

      curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}' \
      --header 'Authorization: Bearer {api_key}'
      
    • 获取文档列表

      curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents' \
      --header 'Authorization: Bearer {api_key}'
      
    • 添加新段落

      curl 'https://api.dify.ai/v1/datasets/aac47674-31a8-4f12-aab2-9603964c4789/documents/2034e0c1-1b75-4532-849e-24e72666595b/segment' \
        --header 'Authorization: Bearer {api_key}' \
        --header 'Content-Type: application/json' \
        --data-raw $'"segments":[
        {"content":"Dify means Do it for you",
        "keywords":["Dify","Do"]
        }
        ]'
        --compressed
      

这些 API 端点允许创建数据集和添加文档,并进行向量化和存储。

更多详细信息可以参考 Dify 文档 [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 5, 2024): <!-- Answer --> 是的,Dify 版本 0.3.21 支持通过 API 创建知识库并进行文档向量化存储。 以下是相关的 API 代码示例: 1. **通过 API 创建知识库(数据集)**: ```bash curl --location --request POST 'https://api.dify.ai/v1/datasets' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw '{"name": "name"}' ``` 2. **文档向量化和存储**: - **通过文本创建文档**: ```bash curl --location --request POST 'https://api.dify.ai/v1/datasets/<uuid:dataset_id>/document/create_by_text>' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "Dify", "text": "Dify means Do it for you...", "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" } }' ``` - **通过文件创建文档**: ```bash curl --location POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{ "name": "Dify", "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"' ``` - **获取文档嵌入状态**: ```bash curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{batch}/indexing-status' \ --header 'Authorization: Bearer {api_key}' ``` - **删除文档**: ```bash curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}' \ --header 'Authorization: Bearer {api_key}' ``` - **获取文档列表**: ```bash curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents' \ --header 'Authorization: Bearer {api_key}' ``` - **添加新段落**: ```bash curl 'https://api.dify.ai/v1/datasets/aac47674-31a8-4f12-aab2-9603964c4789/documents/2034e0c1-1b75-4532-849e-24e72666595b/segment' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw $'"segments":[ {"content":"Dify means Do it for you", "keywords":["Dify","Do"] } ]' --compressed ``` 这些 API 端点允许创建数据集和添加文档,并进行向量化和存储。 更多详细信息可以参考 [Dify 文档](https://docs.dify.ai) <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/knowledge-base/maintain-dataset-via-api.md)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/features/datasets/maintain-dataset-via-api.md)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/knowledge-base/knowledge_and_documents_maintenance.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/knowledge-base/create_knowledge_and_upload_documents.md)</sup><sup>[[5]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/features/datasets/maintain-dataset-via-api.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#3985