YanSte commited on
Commit
62d8d01
·
1 Parent(s): 872fa96

cleaned code

Browse files
Files changed (1) hide show
  1. 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 not already_edge:
244
- return
245
-
246
- # Get weight with default 0.0 if missing
247
- already_weights.append(already_edge.get("weight", 0.0))
248
-
249
- # Get source_id with empty string default if missing or None
250
- if "source_id" in already_edge and already_edge["source_id"] is not None:
251
- already_source_ids.extend(
252
- split_string_by_multi_markers(
253
- already_edge["source_id"], [GRAPH_FIELD_SEP]
254
  )
255
- )
256
 
257
- # Get description with empty string default if missing or None
258
- if "description" in already_edge and already_edge["description"] is not None:
259
- already_description.append(already_edge["description"])
260
 
261
- # Get keywords with empty string default if missing or None
262
- if "keywords" in already_edge and already_edge["keywords"] is not None:
263
- already_keywords.extend(
264
- split_string_by_multi_markers(
265
- already_edge["keywords"], [GRAPH_FIELD_SEP]
 
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)