Fix: Fixed null value handling and ensure exceptions are avoided

This commit is contained in:
IcySugar000
2025-04-09 11:30:29 +08:00
parent 27d31ca29c
commit 8aa3cd799a
2 changed files with 4 additions and 0 deletions

View File

@@ -1363,6 +1363,7 @@ async def _find_most_related_text_unit_from_entities(
text_units = [ text_units = [
split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP]) split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
for dp in node_datas for dp in node_datas
if dp["source_id"] is not None
] ]
edges = await asyncio.gather( edges = await asyncio.gather(
*[knowledge_graph_inst.get_node_edges(dp["entity_name"]) for dp in node_datas] *[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(
node_datas = [ node_datas = [
{**n, "entity_name": k, "rank": d} {**n, "entity_name": k, "rank": d}
for k, n, d in zip(entity_names, node_datas, node_degrees) for k, n, d in zip(entity_names, node_datas, node_degrees)
if n is not None
] ]
len_node_datas = len(node_datas) len_node_datas = len(node_datas)
@@ -1681,6 +1683,7 @@ async def _find_related_text_unit_from_relationships(
text_units = [ text_units = [
split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP]) split_string_by_multi_markers(dp["source_id"], [GRAPH_FIELD_SEP])
for dp in edge_datas for dp in edge_datas
if dp["source_id"] is not None
] ]
all_text_units_lookup = {} all_text_units_lookup = {}

View File

@@ -334,6 +334,7 @@ def split_string_by_multi_markers(content: str, markers: list[str]) -> list[str]
"""Split a string by multiple markers""" """Split a string by multiple markers"""
if not markers: if not markers:
return [content] return [content]
content = content if content is not None else ""
results = re.split("|".join(re.escape(marker) for marker in markers), content) results = re.split("|".join(re.escape(marker) for marker in markers), content)
return [r.strip() for r in results if r.strip()] return [r.strip() for r in results if r.strip()]