Knowledge API: Document from Text doesn't create chunks #12946

Closed
opened 2026-02-21 19:09:48 -05:00 by yindo · 2 comments
Owner

Originally created by @Nobsyde on GitHub (Apr 15, 2025).

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).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.2.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a Knowedge
  2. Through API, create a document from text, using hierarchical_model
  3. check the frontend - you will see the text correctly uploaded but with no chunks
curl --location --request POST 'http://localhost/v1/datasets/b2563053-d365-49d3-bfe7-25fa17276266/document/create-by-text' \
--header 'Authorization: Bearer {myKey}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "UN NOME",
  "text": "MOCK DATA\\n\\n\\n\\nMOCK DATA",
  "indexing_technique": "high_quality",
  "doc_form": "hierarchical_model",
  "process_rule": {
    "mode": "custom",
    "rules": {
      "pre_processing_rules": [
        {
          "id": "remove_extra_spaces",
          "enabled": true
        },
        {
          "id": "remove_urls_emails",
          "enabled": false
        }
      ],
      "segmentation": {
        "separator": "\\n\\n\\n\\n",
        "max_tokens": 1500,
        "parent_mode": "paragraph"
      },
      "subchunk_segmentation": {
        "separator": "\\n\\n",
        "max_tokens": 500
      }
    }
  },
  "retrieval_model": {
    "search_method": "hybrid_search",
    "reranking_enable": true,
    "top_k": 3,
    "score_threshold_enabled": false
  },
  "embedding_model": "text-embedding-3-small",
  "embedding_model_provider": "openai"
}'

✔️ Expected Behavior

The text chunks to be created as per my process_rule

Actual Behavior

chunks are not created.
Also, on a DB I initially created by crawling a website through firecrawl I get this error in dify_api container console when in chunking settings I try to click on the top right, to select my document:

2025-04-15 15:17:29 Traceback (most recent call last):
2025-04-15 15:17:29   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
2025-04-15 15:17:29     rv = self.dispatch_request()
2025-04-15 15:17:29          ^^^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
2025-04-15 15:17:29     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/init.py", line 489, in wrapper
2025-04-15 15:17:29     resp = resource(*args, **kwargs)
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
2025-04-15 15:17:29     return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/init.py", line 604, in dispatch_request
2025-04-15 15:17:29     resp = meth(*args, **kwargs)
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/controllers/console/wraps.py", line 198, in decorated
2025-04-15 15:17:29     return view(*args, **kwargs)
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/libs/login.py", line 94, in decorated_view
2025-04-15 15:17:29     return current_app.ensure_sync(func)(*args, **kwargs)
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/controllers/console/wraps.py", line 30, in decorated
2025-04-15 15:17:29     return view(*args, **kwargs)
2025-04-15 15:17:29            ^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29   File "/app/api/controllers/console/datasets/datasets.py", line 459, in post
2025-04-15 15:17:29     "only_main_content": website_info_list["only_main_content"],
2025-04-15 15:17:29                          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
2025-04-15 15:17:29 KeyError: 'only_main_content'

Note that this error doesn't appear from an empty database

Originally created by @Nobsyde on GitHub (Apr 15, 2025). ### 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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.2.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. Create a Knowedge 2. Through API, create a document from text, using hierarchical_model 3. check the frontend - you will see the text correctly uploaded but with no chunks ``` curl --location --request POST 'http://localhost/v1/datasets/b2563053-d365-49d3-bfe7-25fa17276266/document/create-by-text' \ --header 'Authorization: Bearer {myKey}' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "UN NOME", "text": "MOCK DATA\\n\\n\\n\\nMOCK DATA", "indexing_technique": "high_quality", "doc_form": "hierarchical_model", "process_rule": { "mode": "custom", "rules": { "pre_processing_rules": [ { "id": "remove_extra_spaces", "enabled": true }, { "id": "remove_urls_emails", "enabled": false } ], "segmentation": { "separator": "\\n\\n\\n\\n", "max_tokens": 1500, "parent_mode": "paragraph" }, "subchunk_segmentation": { "separator": "\\n\\n", "max_tokens": 500 } } }, "retrieval_model": { "search_method": "hybrid_search", "reranking_enable": true, "top_k": 3, "score_threshold_enabled": false }, "embedding_model": "text-embedding-3-small", "embedding_model_provider": "openai" }' ``` ### ✔️ Expected Behavior The text chunks to be created as per my process_rule ### ❌ Actual Behavior chunks are not created. Also, on a DB I initially created by crawling a website through firecrawl I get this error in dify_api container console when in chunking settings I try to click on the top right, to select my document: ``` 2025-04-15 15:17:29 Traceback (most recent call last): 2025-04-15 15:17:29 File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request 2025-04-15 15:17:29 rv = self.dispatch_request() 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request 2025-04-15 15:17:29 return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/init.py", line 489, in wrapper 2025-04-15 15:17:29 resp = resource(*args, **kwargs) 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view 2025-04-15 15:17:29 return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/init.py", line 604, in dispatch_request 2025-04-15 15:17:29 resp = meth(*args, **kwargs) 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/controllers/console/wraps.py", line 198, in decorated 2025-04-15 15:17:29 return view(*args, **kwargs) 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/libs/login.py", line 94, in decorated_view 2025-04-15 15:17:29 return current_app.ensure_sync(func)(*args, **kwargs) 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/controllers/console/wraps.py", line 30, in decorated 2025-04-15 15:17:29 return view(*args, **kwargs) 2025-04-15 15:17:29 ^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 File "/app/api/controllers/console/datasets/datasets.py", line 459, in post 2025-04-15 15:17:29 "only_main_content": website_info_list["only_main_content"], 2025-04-15 15:17:29 ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ 2025-04-15 15:17:29 KeyError: 'only_main_content' ``` Note that this error doesn't appear from an empty database
yindo added the 🐞 bug label 2026-02-21 19:09:48 -05:00
yindo closed this issue 2026-02-21 19:09:48 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 15, 2025):

Hello @Nobsyde! I'm Dosu, a bot here to help you solve bugs, answer your questions, and assist you on your journey as a contributor. I'm ready to help while you wait for a human maintainer. How can I assist you today?

To address the issue of chunks not being created when using the create-by-text API endpoint with the hierarchical_model, ensure that the process_rule.mode is set to "hierarchical" instead of "custom". The "custom" mode may not support hierarchical segmentation properly, which could lead to the issue of chunks not being created as expected [1][2].

Additionally, make sure that the parent_mode and subchunk_segmentation are correctly placed under the rules object within process_rule. This is crucial for the hierarchical segmentation to function correctly [1][2].

Regarding the KeyError: 'only_main_content', this error typically occurs when the key 'only_main_content' is missing from the website_info_list dictionary. This might be due to an incomplete or incorrect data structure being passed to the function. Ensure that the data structure includes all necessary keys and values, especially when dealing with data from crawled websites [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 15, 2025): <!-- Greeting --> Hello @Nobsyde! I'm [Dosu](https://dosu.dev), a bot here to help you solve bugs, answer your questions, and assist you on your journey as a contributor. I'm ready to help while you wait for a human maintainer. How can I assist you today? <!-- Answer --> To address the issue of chunks not being created when using the `create-by-text` API endpoint with the `hierarchical_model`, ensure that the `process_rule.mode` is set to "hierarchical" instead of "custom". The "custom" mode may not support hierarchical segmentation properly, which could lead to the issue of chunks not being created as expected <sup>[[1]](https://github.com/langgenius/dify/issues/15085)</sup><sup>[[2]](https://github.com/langgenius/dify/issues/12819)</sup>. Additionally, make sure that the `parent_mode` and `subchunk_segmentation` are correctly placed under the `rules` object within `process_rule`. This is crucial for the hierarchical segmentation to function correctly <sup>[[1]](https://github.com/langgenius/dify/issues/15085)</sup><sup>[[2]](https://github.com/langgenius/dify/issues/12819)</sup>. Regarding the `KeyError: 'only_main_content'`, this error typically occurs when the key `'only_main_content'` is missing from the `website_info_list` dictionary. This might be due to an incomplete or incorrect data structure being passed to the function. Ensure that the data structure includes all necessary keys and values, especially when dealing with data from crawled websites <sup>[[1]](https://github.com/langgenius/dify/issues/15085)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/51a5c33c-d789-4622-a0be-fffd557c7118?feedback_type=other)</sup>
Author
Owner

@Nobsyde commented on GitHub (Apr 15, 2025):

ok, by adding parent_mode and changing to mode: hierarchical the issue seems to be resolved, thank you!

@Nobsyde commented on GitHub (Apr 15, 2025): ok, by adding `parent_mode` and changing to `mode: hierarchical` the issue seems to be resolved, thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12946