IcySugar000 commited on
Commit
7043483
·
1 Parent(s): 3ac8f1b

Fix: Fixed null value handling and ensure exceptions are avoided

Browse files
Files changed (2) hide show
  1. lightrag/operate.py +3 -0
  2. lightrag/utils.py +1 -0
lightrag/operate.py CHANGED
@@ -1363,6 +1363,7 @@ async def _find_most_related_text_unit_from_entities(
1363
  text_units = [
1364
  split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
1365
  for dp in node_datas
 
1366
  ]
1367
  edges = await asyncio.gather(
1368
  *[knowledge_graph_inst.get_node_edges(dp["entity_name"]) for dp in node_datas]
@@ -1657,6 +1658,7 @@ async def _find_most_related_entities_from_relationships(
1657
  node_datas = [
1658
  {**n, "entity_name": k, "rank": d}
1659
  for k, n, d in zip(entity_names, node_datas, node_degrees)
 
1660
  ]
1661
 
1662
  len_node_datas = len(node_datas)
@@ -1681,6 +1683,7 @@ async def _find_related_text_unit_from_relationships(
1681
  text_units = [
1682
  split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
1683
  for dp in edge_datas
 
1684
  ]
1685
  all_text_units_lookup = {}
1686
 
 
1363
  text_units = [
1364
  split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
1365
  for dp in node_datas
1366
+ if dp["source_id"] is not None
1367
  ]
1368
  edges = await asyncio.gather(
1369
  *[knowledge_graph_inst.get_node_edges(dp["entity_name"]) for dp in node_datas]
 
1658
  node_datas = [
1659
  {**n, "entity_name": k, "rank": d}
1660
  for k, n, d in zip(entity_names, node_datas, node_degrees)
1661
+ if n is not None
1662
  ]
1663
 
1664
  len_node_datas = len(node_datas)
 
1683
  text_units = [
1684
  split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
1685
  for dp in edge_datas
1686
+ if dp["source_id"] is not None
1687
  ]
1688
  all_text_units_lookup = {}
1689
 
lightrag/utils.py CHANGED
@@ -334,6 +334,7 @@ def split_string_by_multi_markers(content: str, markers: list[str]) -> list[str]
334
  """Split a string by multiple markers"""
335
  if not markers:
336
  return [content]
 
337
  results = re.split("|".join(re.escape(marker) for marker in markers), content)
338
  return [r.strip() for r in results if r.strip()]
339
 
 
334
  """Split a string by multiple markers"""
335
  if not markers:
336
  return [content]
337
+ content = content if content is not None else ""
338
  results = re.split("|".join(re.escape(marker) for marker in markers), content)
339
  return [r.strip() for r in results if r.strip()]
340