kg-extract
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKG Extract
KG Extract
Extract entities (classes, functions, modules, types, concepts) and their relations (imports, extends, implements, depends-on, calls) from source files, then store them as a knowledge graph in AgentDB.
从源文件中提取实体(类、函数、模块、类型、概念)及其关系(导入、继承、实现、依赖、调用),然后将它们作为知识图谱存储在AgentDB中。
When to use
适用场景
When you need to build or update a knowledge graph from source code or documentation. Useful for understanding codebase structure, dependency analysis, and impact assessment.
当你需要从源代码或文档中构建或更新知识图谱时。适用于理解代码库结构、依赖分析和影响评估。
Steps
步骤
- Scan files -- use and
Globto enumerate and read source files at the given pathRead - Identify entities -- extract classes, functions, modules, types, and config references from each file
- Map relations -- for each entity, determine its relations to other entities:
- : follow import/require statements
imports - : class inheritance
extends - : interface implementations
implements - : constructor dependencies, injected services
depends-on - : function/method invocations
calls - : documentation mentions, comments
references
- Store in AgentDB -- call for each entity with metadata (name, type, file, line, description)
mcp__claude-flow__agentdb_hierarchical-store - Create edges -- call for each relation with source, target, relation type, and weight
mcp__claude-flow__agentdb_causal-edge - Report -- summarize: total entities by type, total relations by type, files scanned
- 扫描文件——使用和
Glob枚举并读取指定路径下的源文件Read - 识别实体——从每个文件中提取类、函数、模块、类型和配置引用
- 映射关系——为每个实体确定其与其他实体的关系:
- :追踪import/require语句
imports - :类继承关系
extends - :接口实现关系
implements - :构造函数依赖、注入的服务
depends-on - :函数/方法调用
calls - :文档提及、注释引用
references
- 存储到AgentDB——为每个实体调用,并附带元数据(名称、类型、文件、行号、描述)
mcp__claude-flow__agentdb_hierarchical-store - 创建边——为每个关系调用,包含源实体、目标实体、关系类型和权重
mcp__claude-flow__agentdb_causal-edge - 生成报告——总结:按类型统计的实体总数、按类型统计的关系总数、已扫描文件数
CLI alternative
CLI替代方案
bash
npx @claude-flow/cli@latest memory store --namespace knowledge-graph --key "entity-NAME" --value "METADATA_JSON"
npx @claude-flow/cli@latest memory search --query "entities in auth module" --namespace knowledge-graphbash
npx @claude-flow/cli@latest memory store --namespace knowledge-graph --key "entity-NAME" --value "METADATA_JSON"
npx @claude-flow/cli@latest memory search --query "entities in auth module" --namespace knowledge-graph