fix(graphrag): drop entities whose name normalizes to nothing

``canonical_name`` answers "" for a punctuation-only name, which callers are
meant to read as "no entity" -- ``_resolve_endpoint`` already does. Entity
extraction did not, and nodes merge on that key, so every such entity in a
source collapsed onto one shared node that belonged to none of them.
This commit is contained in:
Alex committed 2026-09-20 10:45:05 +01:00
1 parent 2b6d4d509e
commit ef5b718f37
2 files changed
+29 -2

No files matched your search

+8 -2
View File
@@ -424,7 +424,7 @@ def extract_graph_for_source(
def _build_entities(raw_entities: Any) -> List[Dict[str, Any]]:
"""Normalize the LLM's entity dicts (drop nameless ones)."""
"""Normalize the LLM's entity dicts (drop the ones with no usable name)."""
entities = []
for e in raw_entities:
if not isinstance(e, dict):
@@ -432,10 +432,16 @@ def _build_entities(raw_entities: Any) -> List[Dict[str, Any]]:
name = str(e.get("name", "")).strip()
if not name:
continue
normalized_name = normalize_entity_name(name)
if not normalized_name:
# A punctuation-only name normalizes to nothing, and nodes merge on
# that key: keeping it collapses every such entity onto one shared
# node. The relationship side already drops them.
continue
entities.append(
{
"name": name,
"normalized_name": normalize_entity_name(name),
"normalized_name": normalized_name,
"type": str(e.get("type") or "") or None,
"description": str(e.get("description") or "") or None,
}