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)
This commit is contained in:
dong 2025-05-30 12:58:05 +08:00 committed by GitHub
parent f0879563d0
commit 62de535ac8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,6 +16,7 @@
from flask import request, jsonify from flask import request, jsonify
from api.db import LLMType 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.knowledgebase_service import KnowledgebaseService
from api.db.services.llm_service import LLMBundle from api.db.services.llm_service import LLMBundle
from api import settings from api import settings
@ -70,12 +71,13 @@ def retrieval(tenant_id):
records = [] records = []
for c in ranks["chunks"]: for c in ranks["chunks"]:
e, doc = DocumentService.get_by_id( c["doc_id"])
c.pop("vector", None) c.pop("vector", None)
records.append({ records.append({
"content": c["content_with_weight"], "content": c["content_with_weight"],
"score": c["similarity"], "score": c["similarity"],
"title": c["docnm_kwd"], "title": c["docnm_kwd"],
"metadata": {} "metadata": doc.meta_fields
}) })
return jsonify({"records": records}) return jsonify({"records": records})