Performance Issue with Batch Insert in /datasets/{dataset_id}/documents/{document_id}/segments API #6461

Closed
opened 2026-02-21 18:15:50 -05:00 by yindo · 4 comments
Owner

Originally created by @Angelxiaotao on GitHub (Oct 30, 2024).

Originally assigned to: @JohnJyong on GitHub.

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.10.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Use the /datasets/{dataset_id}/documents/{document_id}/segments API to insert a batch of segments.
Attempt to insert more than 200 segments in a single request.
Observe the performance slowdown as the segment count approaches or exceeds 1000 entries.

✔️ Expected Behavior

Could you provide guidance on optimizing this process, or consider implementing performance improvements for batch insert operations on this endpoint? Support for higher throughput or more efficient bulk operations would be highly beneficial for users with large datasets.

Actual Behavior

Inserting batches of more than 200 segments leads to slow performance, which becomes especially problematic when handling large datasets that require high-volume segment insertions.

Originally created by @Angelxiaotao on GitHub (Oct 30, 2024). Originally assigned to: @JohnJyong on GitHub. ### 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.10.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Use the /datasets/{dataset_id}/documents/{document_id}/segments API to insert a batch of segments. Attempt to insert more than 200 segments in a single request. Observe the performance slowdown as the segment count approaches or exceeds 1000 entries. ### ✔️ Expected Behavior Could you provide guidance on optimizing this process, or consider implementing performance improvements for batch insert operations on this endpoint? Support for higher throughput or more efficient bulk operations would be highly beneficial for users with large datasets. ### ❌ Actual Behavior Inserting batches of more than 200 segments leads to slow performance, which becomes especially problematic when handling large datasets that require high-volume segment insertions.
yindo added the 💪 enhancement label 2026-02-21 18:15:50 -05:00
yindo closed this issue 2026-02-21 18:15:50 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 30, 2024):

To address the performance issues with batch insert operations in the /datasets/{dataset_id}/documents/{document_id}/segments API, especially when dealing with large datasets, consider the following optimizations:

  1. Asynchronous Processing: The current implementation uses asynchronous processing with a task queue to handle batch inserts. This allows the API to return a response immediately without waiting for the entire batch to be processed. Ensure that this is properly configured and utilized to offload processing from the main application thread [1].

  2. Task Queue Configuration: The task queue is configured using Celery. You can adjust the concurrency level to allow more tasks to be processed simultaneously, which might improve throughput. For example, increasing the concurrency level from 1 to a higher number could help, depending on your system's resources [2].

  3. Database Indexes: The document_segments table has several indexes that could impact performance. While indexes are necessary for query performance, they can slow down insert operations. Review these indexes to ensure they are necessary and consider optimizing them if possible [3].

  4. Batch Size: If possible, try to insert segments in smaller batches. While the system is designed to handle large batches, breaking them into smaller chunks might reduce the load and improve performance.

  5. Monitoring and Logging: Implement detailed logging and monitoring to identify specific bottlenecks during the insert process. This can provide insights into where the performance issues are occurring and help in fine-tuning the system.

These strategies should help in optimizing the batch insert operations and improving the overall performance of the API.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 30, 2024): <!-- Answer --> To address the performance issues with batch insert operations in the `/datasets/{dataset_id}/documents/{document_id}/segments` API, especially when dealing with large datasets, consider the following optimizations: 1. **Asynchronous Processing**: The current implementation uses asynchronous processing with a task queue to handle batch inserts. This allows the API to return a response immediately without waiting for the entire batch to be processed. Ensure that this is properly configured and utilized to offload processing from the main application thread <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/controllers/console/datasets/datasets_segments.py)</sup>. 2. **Task Queue Configuration**: The task queue is configured using Celery. You can adjust the concurrency level to allow more tasks to be processed simultaneously, which might improve throughput. For example, increasing the concurrency level from 1 to a higher number could help, depending on your system's resources <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/README.md)</sup>. 3. **Database Indexes**: The `document_segments` table has several indexes that could impact performance. While indexes are necessary for query performance, they can slow down insert operations. Review these indexes to ensure they are necessary and consider optimizing them if possible <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/migrations/versions/64b051264f32_init.py)</sup>. 4. **Batch Size**: If possible, try to insert segments in smaller batches. While the system is designed to handle large batches, breaking them into smaller chunks might reduce the load and improve performance. 5. **Monitoring and Logging**: Implement detailed logging and monitoring to identify specific bottlenecks during the insert process. This can provide insights into where the performance issues are occurring and help in fine-tuning the system. These strategies should help in optimizing the batch insert operations and improving the overall performance of the API. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@JohnJyong commented on GitHub (Oct 31, 2024):

Please describe clearly what performance degradation refers to, whether it is database processing time, interface return time, or Embedding time.

@JohnJyong commented on GitHub (Oct 31, 2024): Please describe clearly what performance degradation refers to, whether it is database processing time, interface return time, or Embedding time.
Author
Owner

@Angelxiaotao commented on GitHub (Oct 31, 2024):

@JohnJyong We are currently experiencing a particularly slow response to requests from this interface. Our server is configured with a 4-core CPU, 30GB of memory, 500GB of hard drive, and 16GB of GPU with graphics memory. In this configuration, when inserting more than 200 segments in bulk, the interface response time is significantly prolonged, which affects the processing efficiency of large amounts of data. Do you have any optimization suggestions or further performance improvement plans?

@Angelxiaotao commented on GitHub (Oct 31, 2024): @JohnJyong We are currently experiencing a particularly slow response to requests from this interface. Our server is configured with a 4-core CPU, 30GB of memory, 500GB of hard drive, and 16GB of GPU with graphics memory. In this configuration, when inserting more than 200 segments in bulk, the interface response time is significantly prolonged, which affects the processing efficiency of large amounts of data. Do you have any optimization suggestions or further performance improvement plans?
Author
Owner

@dosubot[bot] commented on GitHub (Dec 1, 2024):

Hi, @Angelxiaotao. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • Performance issue with the /datasets/{dataset_id}/documents/{document_id}/segments API when inserting over 200 segments.
  • I suggested optimizations: asynchronous processing, task queue with Celery, database index review, batch size adjustments, and monitoring/logging.
  • JohnJyong asked for clarification on the performance degradation type.
  • You provided server configuration details and reported slow response times, seeking further optimization advice.

Next Steps

  • Please confirm if this issue is still relevant with the latest version of the Dify repository. If so, you can keep the discussion open by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 1, 2024): Hi, @Angelxiaotao. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary** - Performance issue with the `/datasets/{dataset_id}/documents/{document_id}/segments` API when inserting over 200 segments. - I suggested optimizations: asynchronous processing, task queue with Celery, database index review, batch size adjustments, and monitoring/logging. - JohnJyong asked for clarification on the performance degradation type. - You provided server configuration details and reported slow response times, seeking further optimization advice. **Next Steps** - Please confirm if this issue is still relevant with the latest version of the Dify repository. If so, you can keep the discussion open by commenting here. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6461