cleaned code
Browse files- lightrag/operate.py +19 -21
lightrag/operate.py
CHANGED
|
@@ -240,31 +240,29 @@ async def _merge_edges_then_upsert(
|
|
| 240 |
if await knowledge_graph_inst.has_edge(src_id, tgt_id):
|
| 241 |
already_edge = await knowledge_graph_inst.get_edge(src_id, tgt_id)
|
| 242 |
# Handle the case where get_edge returns None or missing fields
|
| 243 |
-
if
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
already_edge["source_id"], [GRAPH_FIELD_SEP]
|
| 254 |
)
|
| 255 |
-
)
|
| 256 |
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 266 |
)
|
| 267 |
-
)
|
| 268 |
|
| 269 |
# Process edges_data with None checks
|
| 270 |
weight = sum([dp["weight"] for dp in edges_data] + already_weights)
|
|
|
|
| 240 |
if await knowledge_graph_inst.has_edge(src_id, tgt_id):
|
| 241 |
already_edge = await knowledge_graph_inst.get_edge(src_id, tgt_id)
|
| 242 |
# Handle the case where get_edge returns None or missing fields
|
| 243 |
+
if already_edge:
|
| 244 |
+
# Get weight with default 0.0 if missing
|
| 245 |
+
already_weights.append(already_edge.get("weight", 0.0))
|
| 246 |
+
|
| 247 |
+
# Get source_id with empty string default if missing or None
|
| 248 |
+
if already_edge.get("source_id") is not None:
|
| 249 |
+
already_source_ids.extend(
|
| 250 |
+
split_string_by_multi_markers(
|
| 251 |
+
already_edge["source_id"], [GRAPH_FIELD_SEP]
|
| 252 |
+
)
|
|
|
|
| 253 |
)
|
|
|
|
| 254 |
|
| 255 |
+
# Get description with empty string default if missing or None
|
| 256 |
+
if already_edge.get("description") is not None:
|
| 257 |
+
already_description.append(already_edge["description"])
|
| 258 |
|
| 259 |
+
# Get keywords with empty string default if missing or None
|
| 260 |
+
if already_edge.get("keywords") is not None:
|
| 261 |
+
already_keywords.extend(
|
| 262 |
+
split_string_by_multi_markers(
|
| 263 |
+
already_edge["keywords"], [GRAPH_FIELD_SEP]
|
| 264 |
+
)
|
| 265 |
)
|
|
|
|
| 266 |
|
| 267 |
# Process edges_data with None checks
|
| 268 |
weight = sum([dp["weight"] for dp in edges_data] + already_weights)
|