Skip to content

Add opt-in event_entity KG builder, event_join partitioner and event extraction profiles - #195

Merged
ChenZiHong-Gavin merged 3 commits into
InternScience:mainfrom
Leon-Algo:pr-c-event-entity-pipeline
Nov 8, 2026
Merged

ChenZiHong-Gavin merged 3 commits into
InternScience:mainfrom
Leon-Algo:pr-c-event-entity-pipeline

Conversation

@Leon-Algo

Copy link
Copy Markdown
Contributor

Summary

  • Opt-in event pipeline: kg_method: event_entity builds an EVENT star graph via a profile-driven extractor; partition.method: event_join groups same-anchor events. Default light_rag + ECE route is untouched.
  • Event profiles: graphgen/templates/event_profile_loader.py validates manifest+prompt fail-closed with SHA-256 lineage. Ships only generic_event.v1 as an example; no default profile — event_entity mode without an explicit event_profile errors instead of falling back to a domain policy.
  • External profile paths preserved end-to-end: BuildKGService validates at init but passes the original path reference through to the builder (fixes the second-load event_profile_not_found bug flagged in Add versioned prompt profiles and event-entity generation pipeline #192).
  • Support citations fixed: <support> edge citations accept the rendered -- separator and both endpoint orders, canonicalize to stored orientation, and closure validation accepts only edges that actually exist in the partition (fixes the always-stripped citations bug flagged in Add versioned prompt profiles and event-entity generation pipeline #192).
  • Membership edges self-describing: extract() sets event_member=True at creation and deterministic merge persists the participant role (fixes direct-builder misuse and role loss flagged in Add versioned prompt profiles and event-entity generation pipeline #192).
  • Robust partitioning: a missing-anchor event is skipped (consistent with extraction's drop-and-count) instead of raising and killing the whole partition stage.
  • No PMS profiles/gates/docs, no import-time file I/O, no fork identity.

Third of three PRs split from #192 per review. Depends on #193 (partitioner test fixes; the ECE integration tests don't collect on main) and #194 (profile/prefill/LLM mechanisms this builds on).

Validation

  • pytest tests/unit_tests → 13 passed: disk-profile service→builder propagation, citations both orders + strict closure, anchor skip, merge role persistence, direct extraction marker, loader validation.
  • Default-route check: PR A's synced ECE tests run green against this branch's production code.
  • pylint on all touched modules → 10.00/10.

🤖 Generated with Claude Code

…event profiles

改了什么:
- 新增 profile 驱动的 event_contract/event_entity 星型图构建器:事件节点带 anchor 与 graph_role,成员边在 extract() 即写入 event_member 标记与 role,事件/参与者/成员边合并全部确定性完成并持久化 role
- 新增 EventJoinPartitioner:按共享参与者 join 事件星型子图,缺 anchor 事件跳过而非报错,require_same_anchor 硬约束跨锚扩展
- 新增 event_profile_loader 与内置 generic_event.v1 唯一示例 profile:event_entity 模式强制要求 event_profile,无任何隐式默认;显式文件路径 profile 在 service→builder 全链路原样透传
- 新增 generator support 视图:生成期把事件 ID 换成可读名,support 边引用支持渲染的 "--" 格式且双向端点序均可解析回 canonical 边,closure 校验只接受实际存在的节点/边
- BuildKGService 增加 kg_method=event_entity opt-in 分发,PartitionService 增加 event_join 分发;MANIFEST 收录 event_profiles 数据文件

达成什么目标:不改动 LightRAG 默认链路的前提下,为上游提供可插拔的事件-实体图能力;focused 单测(profile 经 service→builder 磁盘加载、双向边引用严格 closure、anchor 跳过、合并 role 持久化、直接抽取标记)与默认 ECE 分区器测试全部通过,touched 生产模块 pylint 10.00/10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Leon-Algo pushed a commit to Leon-Algo/GraphGen that referenced this pull request Oct 19, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ChenZiHong-Gavin ChenZiHong-Gavin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The three bugs from #192 are fixed here (path profiles survive the second load, -- citations in both endpoint orders with strict closure, event_member/role set at extraction), the default light_rag + ECE route is untouched, and pylint is green on 3.10/3.11/3.12. #193 and #194 are now merged, so this rebases onto main cleanly (no overlapping files).

Three things before merging, all small:

  1. graphgen/models/generator/support.py has no caller. Nothing under graphgen/ imports parse_support / build_generation_view / validate_support; only the unit test does. In #192 these were wired into the generator/service; this PR ships the module unwired, so the fix is dead code upstream. Either wire it at its intended call site (with a test on that path) or drop the module and its test from this PR.

  2. The only shipped profile cannot produce partitions with the default partitioner settings. generic_event.v1 has anchor.required=false, pattern=null, so every event node is stored with anchor="". EventJoinPartitioner defaults to require_same_anchor=True (and PartitionService re-defaults it to True), and _grow skips every event whose anchor is empty, so kg_method: event_entity + partition.method: event_join out of the box yields zero communities. Please either default require_same_anchor to False and let anchor-bearing profiles opt in, or derive it from the profile (anchor.required).

  3. No way to discover the feature. There is no example config and no README/docs mention of kg_method: event_entity, event_profile, or partition.method: event_join and its method_params. Please add one example YAML (under graphgen/configs/ or examples/) plus a short paragraph in the docs.

Nits inline. Happy to merge once these are in.

Comment thread graphgen/models/generator/support.py Outdated
@@ -0,0 +1,128 @@
"""Parse support blocks and build a display-safe graph view for generators."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused in production code: no module under graphgen/ imports parse_support, build_generation_view or validate_support. Please wire it to its intended call site or remove it from this PR.

token_sum = 0
anchor = _anchor(seed[0])
# skip events without the required anchor instead of failing
if require_same_anchor and not anchor:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With require_same_anchor=True (the default) and the shipped generic_event.v1 profile (no anchor), every event hits this branch and the partitioner returns nothing. Suggest defaulting require_same_anchor to False, or deriving it from the profile field anchor.required.

self.method_params = dict(self.method_params)
self.method_params.setdefault("event_entity_type", partition_kwargs.get("event_entity_type", "EVENT"))
self.method_params.setdefault("anchor_attribute", partition_kwargs.get("anchor_attribute", "anchor"))
self.method_params.setdefault("require_same_anchor", partition_kwargs.get("require_same_anchor", True))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same default problem as in the partitioner: True here means the only shipped profile produces zero partitions unless the user knows to set require_same_anchor: false in method_params, and nothing documents that key.

normalized_key = tuple(sorted(key))
if any(endpoint in event_ids for endpoint in normalized_key):
for edge in value:
edge["event_member"] = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extract() now sets event_member=True on every membership edge it creates, so this post-hoc injection is redundant. Fine to keep as a guard, but a one-line comment saying so would help the next reader.

@ChenZiHong-Gavin

Copy link
Copy Markdown
Collaborator

Correction to my review above: after merging #194 this branch does conflict with main, but only in MANIFEST.in (both PRs append one recursive-include line at the end). Keep both lines when rebasing:

recursive-include graphgen/templates/profiles *.json
recursive-include graphgen/templates/event_profiles *

Everything else merges automatically.

MeshyAI and others added 2 commits November 8, 2026 22:05
…fault require_same_anchor=False, add example)

- remove graphgen/models/generator/support.py and its test: nothing in the
  package calls it after the split from InternScience#192
- EventJoinPartitioner / PartitionService default require_same_anchor to
  False so the shipped generic_event.v1 profile (no anchor) partitions out
  of the box; anchor-bearing profiles opt in explicitly
- build_event_kg: drop the post-hoc event_member injection, extract() already
  sets it
- add examples/generate/generate_event_qa (config, script, README documenting
  kg_method/event_profile/event_join params)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation examples labels Nov 8, 2026
@ChenZiHong-Gavin

Copy link
Copy Markdown
Collaborator

To save a round trip I pushed the changes to this branch myself (eae7b60, on top of a merge of main that resolves the MANIFEST.in conflict):

  • removed graphgen/models/generator/support.py and its test (no caller in the package);
  • EventJoinPartitioner and PartitionService now default require_same_anchor to False, with a unit test that the default partitions unanchored events; anchor-bearing profiles set it to true explicitly;
  • dropped the redundant event_member injection in build_event_kg.py;
  • added examples/generate/generate_event_qa/ (config, run script, README documenting kg_method, event_profile and the event_join params).

Pylint is green on 3.10/3.11/3.12, merging. If you would rather keep support.py, a follow-up PR that wires it into a generator is welcome.

@ChenZiHong-Gavin ChenZiHong-Gavin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review items addressed in eae7b60; pylint green. Approving and merging.

@ChenZiHong-Gavin
ChenZiHong-Gavin merged commit 7174d9d into InternScience:main Nov 8, 2026
5 checks passed
@Leon-Algo
Leon-Algo deleted the pr-c-event-entity-pipeline branch November 10, 2026 07:06
Leon-Algo pushed a commit to Leon-Algo/GraphGen that referenced this pull request Nov 10, 2026
…ce#195 + 维护者评审修复)

Co-Authored-By: Claude Code <noreply@anthropic.com>
Leon-Algo pushed a commit to Leon-Algo/GraphGen that referenced this pull request Nov 10, 2026
…nce#195 + 维护者评审修复)

冲突解决策略:
- 上游评审版为主:分区器默认翻转、构建器重构、profile loader、
  抽取器与 8 个生成器的签名/格式修复
- fork 生产特性保留:support 出处接线(生成器+服务+透传)、
  三个 PMS 出题门、中文事件描述模板、max_communities loss 选题、
  reload 有界重试、思考模型空响应容错(PMS_PATCHES InternScience#11)、
  pms 身份与 event_profiles 资源

Co-Authored-By: Claude Code <noreply@anthropic.com>
Leon-Algo pushed a commit to Leon-Algo/GraphGen that referenced this pull request Nov 10, 2026
上游 InternScience#195 将 parse_extraction_response 的 entity_types 改为必填、
event_node_name legacy 默认翻转为 False。PMS 契约测试与潜在直连导入方
按 1.2.x 语义调用;恢复可选默认 + 省略全策略参数时的 legacy PMS 回退,
profile 驱动的 builder 路径全显式传参不受影响(PMS 兼容套件 37 过)。

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Leon-Algo

Copy link
Copy Markdown
Contributor Author

Thanks so much for the thorough review and for merging this, @ChenZiHong-Gavin — and especially for pushing the fixes to the branch yourself (eae7b60) to save a round trip. That was really generous.

Your review comments genuinely improved the design. Making everything opt-in through an explicit profile, with no hidden defaults, is exactly the right call, and we have fully adopted that on our side as well.

GraphGen has become a core part of our synthetic data pipeline, and it has been a real pleasure to work with a maintainer this responsive and careful. Looking forward to contributing more to the project in the future — and happy to help with reviews or testing anytime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation examples tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants