@@ -454,7 +454,28 @@ async def aquery(self, query_text: str, db_id: str, agent_call: bool = False, **
454454 logger .debug (f"Query response: { str (response )[:1000 ]} ..." )
455455
456456 if agent_call :
457- return response ["data" ]["chunks" ]
457+ scope = query_params .get ("retrieval_content_scope" , "chunks" )
458+ data = response .get ("data" , {}) or {}
459+
460+ if scope == "chunks" :
461+ return data .get ("chunks" , [])
462+
463+ result = {}
464+ if scope in ["graph" , "all" ]:
465+ # 过滤掉无关信息,保留实体和关系的核心内容
466+ exclude_keys = {"source_id" , "file_path" , "created_at" }
467+
468+ ents = data .get ("entities" , [])
469+ rels = data .get ("relationships" , [])
470+
471+ result ["entities" ] = [{k : v for k , v in e .items () if k not in exclude_keys } for e in ents ]
472+ result ["relationships" ] = [{k : v for k , v in r .items () if k not in exclude_keys } for r in rels ]
473+ result ["references" ] = data .get ("references" , [])
474+
475+ if scope == "all" :
476+ result ["chunks" ] = data .get ("chunks" , [])
477+
478+ return result
458479
459480 return response
460481
@@ -586,6 +607,17 @@ def get_query_params_config(self, db_id: str, **kwargs) -> dict:
586607 "max" : 100 ,
587608 "description" : "返回的最大结果数量" ,
588609 },
610+ {
611+ "key" : "retrieval_content_scope" ,
612+ "label" : "传递给 LLM 的内容" ,
613+ "type" : "select" ,
614+ "default" : "chunks" ,
615+ "options" : [
616+ {"value" : "chunks" , "label" : "仅 Chunks" , "description" : "仅返回文档片段" },
617+ {"value" : "graph" , "label" : "仅 Entity/Relation" , "description" : "仅返回知识图谱信息" },
618+ {"value" : "all" , "label" : "全部" , "description" : "返回文档片段和知识图谱信息" },
619+ ],
620+ },
589621 ]
590622
591623 return {"type" : "lightrag" , "options" : options }
0 commit comments