From 58c0f943464852d7f88c6a766e981c7563d13b7f Mon Sep 17 00:00:00 2001 From: Magic_yuan <317617749@qq.com> Date: Tue, 10 Dec 2024 14:13:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(lightrag):=20=E4=BF=AE=E5=A4=8D=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E5=AE=9E=E4=BD=93=E6=B2=A1=E6=9C=89=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E7=9A=84chunk=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=20-=20?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=AE=9E=E4=BD=93=E6=B2=A1=E6=9C=89=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E6=97=B6=EF=BC=8C=E7=BB=A7=E7=BB=AD=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E7=9B=B4=E6=8E=A5return=20?= =?UTF-8?q?-=20=E5=BD=93=E5=8F=AA=E6=9C=89=E5=AE=9E=E4=BD=93=E8=80=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=85=B3=E7=B3=BB=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=9C=A8=E9=AB=98=E9=98=B6=E6=9F=A5=E8=AF=A2=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E8=BF=94=E5=9B=9E=E7=A9=BA=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E9=87=8C=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=85=B3=E7=B3=BB=E6=97=B6=E9=99=8D=E7=BA=A7?= =?UTF-8?q?=E4=B8=BAlocal=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lightrag/operate.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lightrag/operate.py b/lightrag/operate.py index 468f4b2f..ec55694d 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -412,15 +412,17 @@ async def extract_entities( ): all_relationships_data.append(await result) - if not len(all_entities_data): - logger.warning("Didn't extract any entities, maybe your LLM is not working") - return None - if not len(all_relationships_data): + if not len(all_entities_data) and not len(all_relationships_data): logger.warning( - "Didn't extract any relationships, maybe your LLM is not working" + "Didn't extract any entities or relationships, maybe your LLM is not working" ) return None + if not len(all_entities_data): + logger.warning("Didn't extract any entities") + if not len(all_relationships_data): + logger.warning("Didn't extract any relationships") + if entity_vdb is not None: data_for_vdb = { compute_mdhash_id(dp["entity_name"], prefix="ent-"): { @@ -630,6 +632,13 @@ async def _build_query_context( text_chunks_db, query_param, ) + if ( + hl_entities_context == "" + and hl_relations_context == "" + and hl_text_units_context == "" + ): + logger.warn("No high level context found. Switching to local mode.") + query_param.mode = "local" if query_param.mode == "hybrid": entities_context, relations_context, text_units_context = combine_contexts( [hl_entities_context, ll_entities_context], @@ -865,7 +874,7 @@ async def _get_edge_data( results = await relationships_vdb.query(keywords, top_k=query_param.top_k) if not len(results): - return None + return "", "", "" edge_datas = await asyncio.gather( *[knowledge_graph_inst.get_edge(r["src_id"], r["tgt_id"]) for r in results]