Skip to content

Commit c13655e

Browse files
fix(graphrag): count the findings dropped from evidences
Review asked for visibility on the new filter. Log a debug-level count of the findings it omits, without their content, and hold it with an assertion so removing the log fails the test. Left the rest of index.py unformatted on purpose. ruff format rewrites a regex list and two logging calls 200 lines away, and that churn does not belong here.
1 parent c2ecffb commit c13655e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

rag/graphrag/general/index.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,13 +936,17 @@ async def save_community_checkpoint(checkpoint_key: str, payload):
936936

937937
chunks = []
938938
for stru, rep in zip(community_structure, community_reports):
939+
# A finding may be a plain string rather than a dict, which the schema check allows
940+
# because it only requires ("findings", list). CommunityReportsExtractor
941+
# ._get_text_output handles both shapes. A string finding carries no separate
942+
# explanation, and its text still reaches content_ltks through the report.
943+
dict_findings = [f for f in stru["findings"] if isinstance(f, dict)]
944+
skipped_findings = len(stru["findings"]) - len(dict_findings)
945+
if skipped_findings:
946+
logging.debug("Omitted %d non-dict findings from community evidences", skipped_findings)
939947
obj = {
940948
"report": rep,
941-
# A finding may be a plain string rather than a dict, which the schema check
942-
# allows because it only requires ("findings", list). CommunityReportsExtractor
943-
# ._get_text_output handles both shapes. A string finding carries no separate
944-
# explanation, and its text still reaches content_ltks through the report.
945-
"evidences": "\n".join([f.get("explanation", "") for f in stru["findings"] if isinstance(f, dict)]),
949+
"evidences": "\n".join([f.get("explanation", "") for f in dict_findings]),
946950
}
947951
# Deterministic id derived from (kb_id, community title) so reruns of
948952
# extract_community produce stable ids. Combined with insert-then-

test/unit_test/rag/graphrag/test_community_chunk_findings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"""
2222

2323
import json
24+
import logging
2425
from types import SimpleNamespace
2526
from unittest.mock import MagicMock
2627

@@ -73,13 +74,15 @@ async def fake_insert(chunks, *_args, **_kwargs):
7374
class TestCommunityChunkFindings:
7475
@pytest.mark.p2
7576
@pytest.mark.asyncio
76-
async def test_string_findings_do_not_break_chunk_building(self, monkeypatch):
77+
async def test_string_findings_do_not_break_chunk_building(self, monkeypatch, caplog):
7778
structure = [{"title": "Community", "weight": 1.0, "entities": ["A"], "findings": ["Alpha matters", _DICT_FINDING]}]
7879

79-
chunks = await _run_extract_community(monkeypatch, structure, ["report text"])
80+
with caplog.at_level(logging.DEBUG, logger="root"):
81+
chunks = await _run_extract_community(monkeypatch, structure, ["report text"])
8082

8183
assert len(chunks) == 1
8284
assert json.loads(chunks[0]["content_with_weight"])["evidences"] == "Because of beta"
85+
assert "Omitted 1 non-dict findings" in caplog.text
8386

8487
@pytest.mark.p2
8588
@pytest.mark.asyncio

0 commit comments

Comments
 (0)