From 9430cba037cf1120dcb45bd434dc75643256e40e Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Wed, 14 Jan 2026 21:03:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BALLM=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8Clightrag=20=E4=B8=AD=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=80=89=E6=8B=A9=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=EF=BC=88=E9=BB=98=E8=AE=A4=E4=BB=85=20chunk?= =?UTF-8?q?=EF=BC=89=20#437?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/knowledge/implementations/lightrag.py | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/knowledge/implementations/lightrag.py b/src/knowledge/implementations/lightrag.py index b1675cbf..cbfc9d59 100644 --- a/src/knowledge/implementations/lightrag.py +++ b/src/knowledge/implementations/lightrag.py @@ -454,7 +454,28 @@ class LightRagKB(KnowledgeBase): logger.debug(f"Query response: {str(response)[:1000]}...") if agent_call: - return response["data"]["chunks"] + scope = query_params.get("retrieval_content_scope", "chunks") + data = response.get("data", {}) or {} + + if scope == "chunks": + return data.get("chunks", []) + + result = {} + if scope in ["graph", "all"]: + # 过滤掉无关信息,保留实体和关系的核心内容 + exclude_keys = {"source_id", "file_path", "created_at"} + + ents = data.get("entities", []) + rels = data.get("relationships", []) + + result["entities"] = [{k: v for k, v in e.items() if k not in exclude_keys} for e in ents] + result["relationships"] = [{k: v for k, v in r.items() if k not in exclude_keys} for r in rels] + result["references"] = data.get("references", []) + + if scope == "all": + result["chunks"] = data.get("chunks", []) + + return result return response @@ -586,6 +607,17 @@ class LightRagKB(KnowledgeBase): "max": 100, "description": "返回的最大结果数量", }, + { + "key": "retrieval_content_scope", + "label": "传递给 LLM 的内容", + "type": "select", + "default": "chunks", + "options": [ + {"value": "chunks", "label": "仅 Chunks", "description": "仅返回文档片段"}, + {"value": "graph", "label": "仅 Entity/Relation", "description": "仅返回知识图谱信息"}, + {"value": "all", "label": "全部", "description": "返回文档片段和知识图谱信息"}, + ], + }, ] return {"type": "lightrag", "options": options}