#2573·graphrag

[Bug]: `community_level` does not select a level — the community roll-up in `read_indexer_reports` is a no-op since v2.0.0

Author: lipeidonggzCreated Sep 25, 2026Updated Sep 30, 2026
Labelsbugtriage

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • My model is hosted on OpenAI or Azure. If not, please look at the "model providers" issue and don't file a new one here.
  • I believe this is a legitimate bug, not just a question. If this is a question, please use the Discussions area.

Describe the bug

read_indexer_reports() is documented to perform a per-entity roll-up:

"If not dynamic_community_selection, then select reports with the max community level that an entity belongs to."

and docs/query/global_search.md describes global search as using "community reports from a specified level of the graph's community hierarchy".

Neither holds in current code. The roll-up groups by communities.title:

python
# packages/graphrag/graphrag/query/indexer_adapters.py, lines 91-101
if not dynamic_community_selection:
    # perform community level roll up
    nodes_df.loc[:, "community"] = nodes_df["community"].fillna(-1)
    nodes_df.loc[:, "community"] = nodes_df["community"].astype(int)

    nodes_df = nodes_df.groupby(["title"]).agg({"community": "max"}).reset_index()
    filtered_community_df = nodes_df["community"].drop_duplicates()

    reports_df = reports_df.merge(filtered_community_df, on="community", how="inner")

Since v2.0.0, communities.title is no longer an entity name — create_communities sets it to the literal string "Community N":

python
# packages/graphrag/graphrag/index/workflows/create_communities.py, line 161
final_communities["title"] = "Community " + final_communities["community"].astype(str)

Grouping by that column is therefore an identity operation: each group contains exactly one community, so max(community) returns that same community. filtered_community_df ends up being "every community with level <= community_level", and the effective behaviour degrades to a plain level <= N filter.

Before v2.0.0 this line grouped by entity name, because the input was the (since-removed) entity-level final_nodes table — see the note on final_nodes below. PR #1674 ("Streamline workflows", 2025-02-07) replaced that input with final_communities.explode("entity_ids") but left groupby(["title"]) and the docstring untouched, so the roll-up silently became dead code.

Impact:

  1. Reports from all levels <= N are used, including ancestor communities whose members are already fully covered by deeper communities. Per the partition property of hierarchical Leiden (children partition their parent), such an ancestor can never be "the max community level that an entity belongs to" — yet its report is included.
  2. Consequently an entity is represented by up to N + 1 reports (one per level it belongs to) instead of exactly one, which inflates the map stage: more reports, more batches, more tokens, and duplicated content crowds out other material in the rate-limited reduce step.
  3. The documented tuning knob community_level no longer controls granularity. On flat corpora (all communities at level 0-1) it is inert entirely.

Steps to reproduce

1. From your own bundled example notebook (no setup required)

docs/examples_notebooks/global_search.ipynb, cell 7 prints:

Total report count: 10
Report count after filtering by community level 2: 10

and its report_df.head() output shows a level-0 community whose members are fully partitioned by three level-1 communities:

community level parent children size
0 0 -1 [7, 8, 9] 10
7 1 0 [] 4
8 1 0 [] 3
9 1 0 [] 3

4 + 3 + 3 = 10, i.e. every entity of community 0 also belongs to a deeper (level 1) community, so community 0 cannot be any entity's max-level community. Its report must not survive the roll-up.

Same notebook, cell 14 (result.context_data["reports"], the context actually sent to the LLM) lists report ids:

4, 0, 3, 8, 9, 1, 6, 7, 5, 2

Community 0 is present. expected per the docstring: absent (<= 9 reports).

2. Minimal script against the bundled sample index

python
import pandas as pd
from graphrag.query.indexer_adapters import read_indexer_reports

IN = "docs/examples_notebooks/inputs/operation dulce"
LEVEL = 2

reports_df = pd.read_parquet(f"{IN}/community_reports.parquet")
communities_df = pd.read_parquet(f"{IN}/communities.parquet")

actual = {int(r.short_id) for r in read_indexer_reports(reports_df, communities_df, LEVEL)}

# reference implementation of the documented behaviour: per-entity deepest community
nodes = communities_df.explode("entity_ids")
nodes = nodes[nodes["level"] <= LEVEL]
expected = set(nodes.groupby("entity_ids")["community"].max())

print("actual  :", sorted(actual))
print("expected:", sorted(expected))
print("in actual but not expected:", sorted(actual - expected))

Actual output is expected to contain community 0; the reference set does not.

Expected Behavior

read_indexer_reports(reports_df, communities_df, N) should return the reports of the communities that are, for at least one entity, the deepest available community within level <= N. Equivalently:

kept = { communities at level == N } ∪ { leaf communities at level < N }

(A community is a leaf when it has no children, i.e. it was small enough not to be split further. Because children partition their parent, ancestors that are fully covered by their own descendants are never "deepest for anyone" and must be dropped.)

On the bundled sample with N = 2, the report of community 0 must be absent.

Two other legitimate resolutions, if maintainers prefer them:

  • Strict single level. Return only level == N. This matches the wording "from a specified level" most literally, but shallow branches (whose deepest level is < N) would then contribute nothing — a behaviour change, not just a fix.
  • Keep the level <= N behaviour and fix the documentation instead: update the docstring, remove the # perform community level roll up comment and the now-meaningless groupby, and document that reports from several levels are used. As it stands, code, comment and docs contradict each other.

GraphRAG Config Used

N/A — this is independent of settings.yaml, model provider, and search parameters. It reproduces with the repository's own example index (see steps above) and with any index built by the default pipeline. The notebook run referenced above is:

yaml
# from docs/examples_notebooks/global_search.ipynb
community_level: 2            # read_indexer_reports(report_df, community_df, 2)
dynamic_community_selection: false   # i.e. the default path, where the roll-up runs

Logs and screenshots

Total report count: 10
Report count after filtering by community level 2: 10
# docs/examples_notebooks/global_search.ipynb, cell 14
result.context_data["reports"]
  id                                              title  occurrence weight  rank
0  4          Dulce Base and Operation: Dulce Community                1.0   9.0
1  0     Paranormal Military Squad and Operation: Dulce                1.0   8.5
2  3     Paranormal Military Squad and Operation: Dulce                1.0   8.5
...

Additional Information

  • GraphRAG Version: v3.2.0 (also main @ 769542fb). Affected since v2.0.0 (PR #1674, 2025-02-07), inherited by v2 and v3. v1.x is not affected — there read_indexer_reports still takes the entity-level final_nodes table and groups by entity name, so the roll-up works as documented.
  • Operating System: Windows 11 (analysis + repro); the notebook evidence above is platform-independent.
  • Python Version: 3.14 (pandas 3.0.1) for the standalone analysis of the filter logic.
  • Related Issues: #2348 (_filter_under_community_level silently drops entities without community assignments — same function family, different defect), #1650 (per-level report distribution — related, not a duplicate).

Two extra notes:

  • Suggested minimal fix (one line, no signature change): explode("entity_ids") already yields an entity-id column, which is exactly the "each entity" the docstring refers to, so grouping by it restores the documented behaviour:

    diff
    -        nodes_df = nodes_df.groupby(["title"]).agg({"community": "max"}).reset_index()
    +        nodes_df = nodes_df.groupby("entity_ids").agg({"community": "max"}).reset_index()

    Verified by re-implementing the function over a synthetic hierarchy that satisfies the partition property: with N = 0/1/2/None the fixed version reproduces the intended per-entity roll-up at every level, while the current version returns level <= N in full.

  • Test coverage: tests/unit/query/ currently has no test touching indexer_adapters.py, which is likely why this silent semantic change survived ~1.5 years. A small unit test asserting the invariant "no entity appears in more than one kept community" (or "ancestors fully covered by descendants are dropped") would pin it down.

I'm happy to send a PR with the one-line fix plus such a regression test — per CONTRIBUTING this issue comes first, so I'm filing before opening one.