Repository navigation
Add opt-in event_entity KG builder, event_join partitioner and event extraction profiles - #195
Conversation
…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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ChenZiHong-Gavin
left a comment
There was a problem hiding this comment.
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:
-
graphgen/models/generator/support.pyhas no caller. Nothing undergraphgen/importsparse_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. -
The only shipped profile cannot produce partitions with the default partitioner settings.
generic_event.v1hasanchor.required=false, pattern=null, so every event node is stored withanchor="".EventJoinPartitionerdefaults torequire_same_anchor=True(andPartitionServicere-defaults it toTrue), and_growskips every event whose anchor is empty, sokg_method: event_entity+partition.method: event_joinout of the box yields zero communities. Please either defaultrequire_same_anchortoFalseand let anchor-bearing profiles opt in, or derive it from the profile (anchor.required). -
No way to discover the feature. There is no example config and no README/docs mention of
kg_method: event_entity,event_profile, orpartition.method: event_joinand itsmethod_params. Please add one example YAML (undergraphgen/configs/orexamples/) plus a short paragraph in the docs.
Nits inline. Happy to merge once these are in.
| @@ -0,0 +1,128 @@ | |||
| """Parse support blocks and build a display-safe graph view for generators.""" | |||
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
Correction to my review above: after merging #194 this branch does conflict with Everything else merges automatically. |
…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>
|
To save a round trip I pushed the changes to this branch myself (eae7b60, on top of a merge of
Pylint is green on 3.10/3.11/3.12, merging. If you would rather keep |
ChenZiHong-Gavin
left a comment
There was a problem hiding this comment.
Review items addressed in eae7b60; pylint green. Approving and merging.
…ce#195 + 维护者评审修复) Co-Authored-By: Claude Code <noreply@anthropic.com>
…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>
上游 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>
|
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. |
Summary
kg_method: event_entitybuilds an EVENT star graph via a profile-driven extractor;partition.method: event_joingroups same-anchor events. Defaultlight_rag+ ECE route is untouched.graphgen/templates/event_profile_loader.pyvalidates manifest+prompt fail-closed with SHA-256 lineage. Ships onlygeneric_event.v1as an example; no default profile — event_entity mode without an explicitevent_profileerrors instead of falling back to a domain policy.BuildKGServicevalidates at init but passes the original path reference through to the builder (fixes the second-loadevent_profile_not_foundbug flagged in Add versioned prompt profiles and event-entity generation pipeline #192).<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).extract()setsevent_member=Trueat creation and deterministic merge persists the participantrole(fixes direct-builder misuse and role loss flagged in Add versioned prompt profiles and event-entity generation pipeline #192).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.pylinton all touched modules → 10.00/10.🤖 Generated with Claude Code