dify icon indicating copy to clipboard operation
dify copied to clipboard

Calling the API for "adding a segment to a document" returns a success response, yet calling the API for "retrieving document segment details" returns an empty array.

Open jy02920793 opened this issue 2 months ago • 4 comments

Self Checks

  • [x] I have read the Contributing Guide and Language Policy.
  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report, otherwise it will be closed.
  • [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Call the "Add a segment to a document" API, and it returns the correct JSON data.
  2. After waiting for 30 seconds, call the "Retrieve document segment details" API, but the data field in the response is an empty array.

✔️ Expected Behavior

The expected behavior is that after calling the "Add a segment to a document" API, calling the "Retrieve document segment details" API again should allow retrieval of the added dataset.

❌ Actual Behavior

In version 1.9.1, when calling the API to add a parent segment of a document, the request returns a success status along with the corresponding JSON data. However, when calling the API to retrieve the parent segment afterward, no added parent segment data is returned.

Image Image

jy02920793 avatar Oct 22 '25 06:10 jy02920793

Hi @jy02920793! I'm Dosu and I’m helping the dify team.

This issue in Dify v1.9.1 is likely caused by a backend session management bug: segments added via the API may not be properly persisted or indexed due to SQLAlchemy objects losing their session binding during async or multi-threaded processing. This results in successful API responses but empty retrievals. The root cause and fix are documented in PR #26480, which ensures documents and segments are correctly bound to a session and their status is updated after chunking/indexing.

To resolve this, upgrade to a version that includes the fix from PR #26480. If upgrading is not possible, review your backend logs for errors like "Instance <Document> is not bound to a Session" and ensure all database operations (especially segment creation and status updates) are performed within an active session context. Avoid passing ORM objects between threads or async tasks—pass IDs and re-query objects inside a session instead. More details and workarounds are discussed here.

If you need to patch your current version, focus on the session management patterns in your segment indexing and retrieval code, following the changes in PR #26480.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Oct 22 '25 07:10 dosubot[bot]

Please verify whether you have merged these fixes. If not, maybe you can try to fix this and submit a PR for this :)

crazywoola avatar Oct 22 '25 07:10 crazywoola

+1

xiaoyesoso avatar Oct 25 '25 06:10 xiaoyesoso

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

Issue Summary:

  • You reported that adding a document segment via API in Dify v1.9.1 returned success but retrieving the segment showed an empty array.
  • The root cause was a backend session management bug where SQLAlchemy objects lost session binding during async processing.
  • This caused segments not to persist properly in the database.
  • The issue was fixed in PR #26480 by improving session management patterns.
  • Upgrading to a version including this fix or applying the patterns from the PR resolves the problem.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of Dify; if so, you can keep the discussion open by commenting here.
  • Otherwise, I will automatically close this issue in 15 days.

Thanks for your understanding and contribution!

dosubot[bot] avatar Dec 24 '25 16:12 dosubot[bot]