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

+21
View File
@@ -1085,6 +1085,27 @@ class TestSummaryCountFailure:
assert store.count_nodes.call_args.kwargs.get("strict") is True
@pytest.mark.unit
class TestEntityNormalization:
"""An entity whose name normalizes to nothing is not an entity.
``canonical_name`` answers "" for a punctuation-only name, and nodes are
merged on that key, so keeping them collapses every such entity onto one
shared node. ``_resolve_endpoint`` already drops them on the relationship
side.
"""
@pytest.mark.parametrize("name", ["!!!", "--", "?", " *** "])
def test_a_name_that_normalizes_to_nothing_is_dropped(self, name):
assert extraction_module._build_entities([{"name": name}]) == []
def test_real_names_survive(self):
built = extraction_module._build_entities(
[{"name": "Quill Store"}, {"name": "!!!"}, {"name": "Alder"}]
)
assert [e["normalized_name"] for e in built] == ["quill store", "alder"]
@pytest.mark.unit
class TestParsing:
def test_parses_embedded_json(self):