how to get the segment_id by using "create-by-text" #7702

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

Originally created by @flyfrogzc on GitHub (Jan 13, 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

0.15.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I am currently using the interface to upload a knowledge base. Each knowledge base entry looks like {“name1”, “text1”, source: “[url1, url2…]”} , {“name1”, “text2”, source: “[url1, url2…]”}.

At the moment, I pass “name1” using the create-by-text endpoint, and I pass “name2” using the “/datasets/{DATASET_ID}/documents/{{document_id}}/segments” endpoint.

When retrieving data, I can obtain the id of name2 through its segment_id. How can I obtain the segment_id for name1?

In fact, I want to associate each {“name”, “text”} entry with a unique id and source. There is also a bug: when writing a segment, I must call sleep(2). Even though I obtain the document_id, if I don’t wait, the service still reports an error.

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @flyfrogzc on GitHub (Jan 13, 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 0.15.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I am currently using the interface to upload a knowledge base. Each knowledge base entry looks like {“name1”, “text1”, source: “[url1, url2…]”} , {“name1”, “text2”, source: “[url1, url2…]”}. At the moment, I pass “name1” using the create-by-text endpoint, and I pass “name2” using the “/datasets/{DATASET_ID}/documents/{{document_id}}/segments” endpoint. When retrieving data, I can obtain the id of name2 through its segment_id. How can I obtain the segment_id for name1? In fact, I want to associate each {“name”, “text”} entry with a unique id and source. There is also a bug: when writing a segment, I must call sleep(2). Even though I obtain the document_id, if I don’t wait, the service still reports an error. ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🙋‍♂️ question label 2026-02-21 18:21:57 -05:00
yindo closed this issue 2026-02-21 18:21:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 13, 2025):

Hey @flyfrogzc! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together!

To obtain the segment_id for a document created using the create-by-text endpoint in Dify, you would typically need to follow these steps:

  1. Create the Document: Use the create-by-text endpoint to create your document. This will give you a document_id.

  2. Retrieve Segments: After creating the document, you can retrieve the segments associated with it. This is usually done by querying the segments of the document using the /datasets/{DATASET_ID}/documents/{document_id}/segments endpoint. This endpoint will return the segments along with their segment_ids.

  3. Handle Delays: If you're experiencing delays or errors when trying to retrieve segments immediately after document creation, it might be due to asynchronous processing. As a workaround, you can implement a short delay (e.g., using sleep) before attempting to retrieve the segments. This allows the system time to process the document and create the segments.

Unfortunately, the specific method to directly obtain the segment_id for entries created with create-by-text isn't detailed in the available documentation. You might need to experiment with the API to see if the segments are automatically created and retrievable after the document creation, or if additional steps are required to generate them.

If you continue to face issues, consider checking the API's response for any status or error messages that might provide more insight into the processing state.

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Jan 13, 2025): <!-- Greeting --> Hey @flyfrogzc! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together! <!-- Answer --> To obtain the `segment_id` for a document created using the `create-by-text` endpoint in Dify, you would typically need to follow these steps: 1. **Create the Document**: Use the `create-by-text` endpoint to create your document. This will give you a `document_id`. 2. **Retrieve Segments**: After creating the document, you can retrieve the segments associated with it. This is usually done by querying the segments of the document using the `/datasets/{DATASET_ID}/documents/{document_id}/segments` endpoint. This endpoint will return the segments along with their `segment_id`s. 3. **Handle Delays**: If you're experiencing delays or errors when trying to retrieve segments immediately after document creation, it might be due to asynchronous processing. As a workaround, you can implement a short delay (e.g., using `sleep`) before attempting to retrieve the segments. This allows the system time to process the document and create the segments. Unfortunately, the specific method to directly obtain the `segment_id` for entries created with `create-by-text` isn't detailed in the available documentation. You might need to experiment with the API to see if the segments are automatically created and retrievable after the document creation, or if additional steps are required to generate them. If you continue to face issues, consider checking the API's response for any status or error messages that might provide more insight into the processing state. <!-- 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/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/6a656553-1b93-47d1-a05e-39b63d0746a8?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7702