From 62de535ac8c740a4f5d04fd2145565ed20784730 Mon Sep 17 00:00:00 2001 From: dong <385639827@qq.com> Date: Fri, 30 May 2025 12:58:05 +0800 Subject: [PATCH] Fix Bug: When performing the dify_retrieval, the metadata of the document was empty. (#7968) ### What problem does this PR solve? When performing the dify_retrieval, the metadata of the document was empty. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/dify_retrieval.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/apps/sdk/dify_retrieval.py b/api/apps/sdk/dify_retrieval.py index 5d6a8c896..f15eb2396 100644 --- a/api/apps/sdk/dify_retrieval.py +++ b/api/apps/sdk/dify_retrieval.py @@ -16,6 +16,7 @@ from flask import request, jsonify from api.db import LLMType +from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.llm_service import LLMBundle from api import settings @@ -70,12 +71,13 @@ def retrieval(tenant_id): records = [] for c in ranks["chunks"]: + e, doc = DocumentService.get_by_id( c["doc_id"]) c.pop("vector", None) records.append({ "content": c["content_with_weight"], "score": c["similarity"], "title": c["docnm_kwd"], - "metadata": {} + "metadata": doc.meta_fields }) return jsonify({"records": records})