Merge pull request #1794 from danielaskdd/weight-default

fix: change default edge weight from 0.0 to 1.0 in entity extraction and graph storage
This commit is contained in:
Daniel.y 2025-07-17 11:42:31 +08:00 committed by GitHub
commit 30e5aac6f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 11 deletions

View file

@ -414,7 +414,7 @@ class MemgraphStorage(BaseGraphStorage):
if records:
edge_result = dict(records[0]["edge_properties"])
for key, default_value in {
"weight": 0.0,
"weight": 1.0,
"source_id": None,
"description": None,
"keywords": None,

View file

@ -535,7 +535,7 @@ class Neo4JStorage(BaseGraphStorage):
# logger.debug(f"Result: {edge_result}")
# Ensure required keys exist with defaults
required_keys = {
"weight": 0.0,
"weight": 1.0,
"source_id": None,
"description": None,
"keywords": None,
@ -559,7 +559,7 @@ class Neo4JStorage(BaseGraphStorage):
)
# Return default edge properties on error
return {
"weight": 0.0,
"weight": 1.0,
"source_id": None,
"description": None,
"keywords": None,
@ -610,7 +610,7 @@ class Neo4JStorage(BaseGraphStorage):
edge_props = edges[0] # choose the first if multiple exist
# Ensure required keys exist with defaults
for key, default in {
"weight": 0.0,
"weight": 1.0,
"source_id": None,
"description": None,
"keywords": None,
@ -621,7 +621,7 @@ class Neo4JStorage(BaseGraphStorage):
else:
# No edge found set default edge properties
edges_dict[(src, tgt)] = {
"weight": 0.0,
"weight": 1.0,
"source_id": None,
"description": None,
"keywords": None,

View file

@ -1016,8 +1016,8 @@ async def _merge_edges_then_upsert(
already_edge = await knowledge_graph_inst.get_edge(src_id, tgt_id)
# Handle the case where get_edge returns None or missing fields
if already_edge:
# Get weight with default 0.0 if missing
already_weights.append(already_edge.get("weight", 0.0))
# Get weight with default 1.0 if missing
already_weights.append(already_edge.get("weight", 1.0))
# Get source_id with empty string default if missing or None
if already_edge.get("source_id") is not None:
@ -1284,6 +1284,7 @@ async def merge_nodes_and_edges(
"content": f"{edge_data['src_id']}\t{edge_data['tgt_id']}\n{edge_data['keywords']}\n{edge_data['description']}",
"source_id": edge_data["source_id"],
"file_path": edge_data.get("file_path", "unknown_source"),
"weight": edge_data.get("weight", 1.0),
}
}
await relationships_vdb.upsert(data_for_vdb)
@ -2493,9 +2494,9 @@ async def _find_most_related_edges_from_entities(
if edge_props is not None:
if "weight" not in edge_props:
logger.warning(
f"Edge {pair} missing 'weight' attribute, using default value 0.0"
f"Edge {pair} missing 'weight' attribute, using default value 1.0"
)
edge_props["weight"] = 0.0
edge_props["weight"] = 1.0
combined = {
"src_tgt": pair,
@ -2548,9 +2549,9 @@ async def _get_edge_data(
if edge_props is not None:
if "weight" not in edge_props:
logger.warning(
f"Edge {pair} missing 'weight' attribute, using default value 0.0"
f"Edge {pair} missing 'weight' attribute, using default value 1.0"
)
edge_props["weight"] = 0.0
edge_props["weight"] = 1.0
# Use edge degree from the batch as rank.
combined = {