Magicyuan commited on
Commit
374889a
·
1 Parent(s): 51012ad

fix(lightrag): 修复只有实体没有关系的chunk处理逻辑

Browse files

- 只有实体没有关系时,继续处理,而不是直接return
- 当只有实体而没有关系的图片在高阶查询关系时会返回空,这里优化返回,当没有关系时降级为local查询

Files changed (1) hide show
  1. lightrag/operate.py +15 -6
lightrag/operate.py CHANGED
@@ -412,15 +412,17 @@ async def extract_entities(
412
  ):
413
  all_relationships_data.append(await result)
414
 
415
- if not len(all_entities_data):
416
- logger.warning("Didn't extract any entities, maybe your LLM is not working")
417
- return None
418
- if not len(all_relationships_data):
419
  logger.warning(
420
- "Didn't extract any relationships, maybe your LLM is not working"
421
  )
422
  return None
423
 
 
 
 
 
 
424
  if entity_vdb is not None:
425
  data_for_vdb = {
426
  compute_mdhash_id(dp["entity_name"], prefix="ent-"): {
@@ -630,6 +632,13 @@ async def _build_query_context(
630
  text_chunks_db,
631
  query_param,
632
  )
 
 
 
 
 
 
 
633
  if query_param.mode == "hybrid":
634
  entities_context, relations_context, text_units_context = combine_contexts(
635
  [hl_entities_context, ll_entities_context],
@@ -865,7 +874,7 @@ async def _get_edge_data(
865
  results = await relationships_vdb.query(keywords, top_k=query_param.top_k)
866
 
867
  if not len(results):
868
- return None
869
 
870
  edge_datas = await asyncio.gather(
871
  *[knowledge_graph_inst.get_edge(r["src_id"], r["tgt_id"]) for r in results]
 
412
  ):
413
  all_relationships_data.append(await result)
414
 
415
+ if not len(all_entities_data) and not len(all_relationships_data):
 
 
 
416
  logger.warning(
417
+ "Didn't extract any entities or relationships, maybe your LLM is not working"
418
  )
419
  return None
420
 
421
+ if not len(all_entities_data):
422
+ logger.warning("Didn't extract any entities")
423
+ if not len(all_relationships_data):
424
+ logger.warning("Didn't extract any relationships")
425
+
426
  if entity_vdb is not None:
427
  data_for_vdb = {
428
  compute_mdhash_id(dp["entity_name"], prefix="ent-"): {
 
632
  text_chunks_db,
633
  query_param,
634
  )
635
+ if (
636
+ hl_entities_context == ""
637
+ and hl_relations_context == ""
638
+ and hl_text_units_context == ""
639
+ ):
640
+ logger.warn("No high level context found. Switching to local mode.")
641
+ query_param.mode = "local"
642
  if query_param.mode == "hybrid":
643
  entities_context, relations_context, text_units_context = combine_contexts(
644
  [hl_entities_context, ll_entities_context],
 
874
  results = await relationships_vdb.query(keywords, top_k=query_param.top_k)
875
 
876
  if not len(results):
877
+ return "", "", ""
878
 
879
  edge_datas = await asyncio.gather(
880
  *[knowledge_graph_inst.get_edge(r["src_id"], r["tgt_id"]) for r in results]