From 54ae5b4a2788a6e52d97f9112a494ae99102a6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=91=E5=8D=BF?= <121151546+shaoqing404@users.noreply.github.com> Date: Wed, 4 Mar 2026 13:23:37 +0800 Subject: [PATCH] Fix Dify external retrieval by providing metadata.document_id (#13337) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? ## Summary Dify’s external retrieval expects `records[].metadata.document_id` to be a non-empty string. RAGFlow currently only sets `metadata.doc_id`, which causes Dify validation to fail. This PR adds `metadata.document_id` (mapped from `doc_id`) in the Dify-compatible retrieval response. ## Changes - Add `meta["document_id"] = c["doc_id"]` in `api/apps/sdk/dify_retrieval.py` ## Testing - Not run (logic-only change). ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/dify_retrieval.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/apps/sdk/dify_retrieval.py b/api/apps/sdk/dify_retrieval.py index 881614e5d9..d1e0b2d8b3 100644 --- a/api/apps/sdk/dify_retrieval.py +++ b/api/apps/sdk/dify_retrieval.py @@ -166,6 +166,8 @@ async def retrieval(tenant_id): c.pop("vector", None) meta = getattr(doc, 'meta_fields', {}) meta["doc_id"] = c["doc_id"] + # Dify expects metadata.document_id for external retrieval sources. + meta["document_id"] = c["doc_id"] records.append({ "content": c["content_with_weight"], "score": c["similarity"],