Skip to content

feat(kg): add dual-mode knowledge graph support#144

Open
huamingjie0815 wants to merge 22 commits into666ghj:mainfrom
huamingjie0815:feat/local-knowledge-graph
Open

feat(kg): add dual-mode knowledge graph support#144
huamingjie0815 wants to merge 22 commits into666ghj:mainfrom
huamingjie0815:feat/local-knowledge-graph

Conversation

@huamingjie0815
Copy link

@huamingjie0815 huamingjie0815 commented Mar 11, 2026

Summary

  • Add kg_adapter for dual-mode knowledge graph (cloud/local)
  • Support switching between Zep Cloud and local Graphiti + Neo4j
  • Improve entity extraction and report agent robustness
  • Add test_kg_adapter.py with unit tests

Test plan

  • Test cloud mode with Zep Cloud
  • Test local mode with Graphiti + Neo4j
  • Run unit tests

🤖 Generated with Claude Code

- Add kg_adapter for dual-mode knowledge graph (cloud/local)
- Support switching between Zep Cloud and local Graphiti + Neo4j
- Improve entity extraction and report agent robustness
- Add test_kg_adapter.py with unit tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Memory Layer Any questions related to RAG, GraphRAG and LLM Memory. labels Mar 11, 2026
huamingjie0815 and others added 9 commits March 11, 2026 23:27
- Update prompt template to use XML format:
  <tool_call name="tool_name">
    <parameter name="param">value</parameter>
  </tool_call>
- Rewrite _parse_tool_calls to support new XML format
- Add fallback support for old JSON format
- Update response cleaning regex to handle new format

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add title requirements section with clear guidelines:
  - Titles should be concise and directly reflect user needs
  - Avoid academic or abstract expressions
  - Add concrete examples of good vs bad titles

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add style and theme constraints to PLAN_SYSTEM_PROMPT to ensure report titles
  are specific and relevant to prediction conditions
- Add "重新分析" (regenerate) button next to "进入深度互动" button in report page
- Button only shows when report generation is complete (isComplete = true)
- Reuses existing /api/report/generate endpoint with force_regenerate=true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Make title constraints more generic and easier to follow
- Emphasize that titles should be direct prediction results like news headlines
- Add specific forbidden words: "变量", "注入", "模拟", "状态", "演化"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add download functionality to report page with button placed
left of regenerate button.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add delete API endpoint (DELETE /api/simulation/<id>)
- Add deleteSimulation method to SimulationManager
- Add delete button to history cards (visible on hover)
- Add confirmation modal for delete action

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(history): add delete simulation functionality
@huamingjie0815
Copy link
Author

支持图谱的local 和cloud 双模式,local 是基于graphiti 改造,需要自己配置embedding模型 ,同时该提交增加一些功能优化,包括删除推演记录、导出报告、重新生成报告等功能,调整report_agent 的tool_call 的格式,从json改为xml 。

huamingjie0815 and others added 2 commits March 12, 2026 14:59
- Use entity_type as dynamic label (e.g., 人物, Person)
- Add Entity as base label for all entities to maintain query compatibility
- Handle edge cases: empty type, numeric-prefixed type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(kg): add dynamic entity labels for local mode
@666ghj
Copy link
Owner

666ghj commented Mar 12, 2026

Wow, this is indeed a great approach to compatibility implementation. Give me some time to take a look!

huamingjie0815 and others added 10 commits March 12, 2026 22:52
- Add database index for trace table to speed up interview result queries
- Optimize interview question generation to 1-3 questions (was 3-5)
- Increase default interview_all_agents timeout from 180s to 240s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add LLM_MAX_TOKENS config option to make max_tokens configurable
via environment variable. Defaults to 4096 if not specified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 添加 EMBEDDING_BATCH_SIZE 配置项(默认 5)
- 新增 SingleEmbeddingEmbedder 支持自定义批处理大小
- Graphiti 适配器使用类级别 event loop
- 添加异步超时保护(默认 300 秒)
- 重构 add_episodes_batch 使用 Graphiti 原生 API
- 添加 set_ontology 方法支持 entity_types
- 增强 search 方法支持 scope 和 reranker 参数
- 优化 get_nodes 使用 group_id 属性
- 减少日志噪音(info 改为 debug)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 删除 _call_llm_for_entities 手动实体提取方法
- delete 方法统一使用 group_id 属性查询

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
使ZepCloudAdapter.search返回与GraphitiAdapter一致的
对象格式(带.edges和.nodes属性),修复检索返回0条的问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
问题原因:
- simulation.py 中 OasisProfileGenerator 初始化时未传入 graph_id
- kg_adapter.py 中 ZepCloudAdapter.search 检查了不存在的 .results 属性

修复内容:
- simulation.py: 传入 graph_id 参数
- kg_adapter.py: 直接返回原始 GraphSearchResults 对象
- oasis_profile_generator.py: 使用实体名作为查询(中文描述搜索效果差)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 补充缺失的 config 参数 (EMBEDDING_BATCH_SIZE, OASIS_* , REPORT_AGENT_*)
- 新增 KNOWLEDGE_GRAPH_MODE.md (中文双模式说明文档)
- 新增 KNOWLEDGE_GRAPH_MODE_EN.md (英文双模式说明文档)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(kg): 优化嵌入批处理和Graphiti适配器
@huamingjie0815
Copy link
Author

Wow, this is indeed a great approach to compatibility implementation. Give me some time to take a look!

上一个版本local 模式并不是真的使用自定义的embedding 模型提取实体信息,这是一个bug。最新提交已经修复了该问题,并解决了一些过程中的其他问题。

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

Labels

Memory Layer Any questions related to RAG, GraphRAG and LLM Memory. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants