知识图谱提取 是 AI Skill Hub 本期精选Claude技能之一。综合评分 8.0 分,整体质量较高。我们强烈推荐将其纳入你的 AI 工具库,帮助提升工作效率。
知识图谱提取 是一款基于 Python 开发的开源工具,专注于 claude_skill、ai_agent、知识图谱 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
知识图谱提取 是一款基于 Python 开发的开源工具,专注于 claude_skill、ai_agent、知识图谱 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:pip 安装(推荐)
pip install mykg
# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install mykg
# 方式三:从源码安装(获取最新功能)
git clone https://github.com/SenolIsci/mykg
cd mykg
pip install -e .
# 验证安装
python -c "import mykg; print('安装成功')"
# 命令行使用
mykg --help
# 基本用法
mykg input_file -o output_file
# Python 代码中调用
import mykg
# 示例
result = mykg.process("input")
print(result)
# mykg 配置文件示例(config.yml) app: name: "mykg" debug: false log_level: "INFO" # 运行时指定配置文件 mykg --config config.yml # 或通过环境变量配置 export MYKG_API_KEY="your-key" export MYKG_OUTPUT_DIR="./output"
<p align="center"> <img src="https://gcore.jsdelivr.net/gh/SenolIsci/mykg@main/docs/mykg-logo-text.svg" width="400px" style="vertical-align:middle;"> </p>
MyKG builds trustworthy knowledge graphs through a self-evolving ontology that continuously adapts, maintains consistency, and assigns confidence scores to knowledge, keeping information grounded and reliable as it grows.
Install mykg, then run the interactive setup wizard — it asks for your provider, model, and API key and writes mykg_config.yaml and .env.mykg in one step.
pip install mykg
mykg init
Then extract a knowledge graph from your notes:
mykg extract-graph my_notes/
Open mykg_sessions/<timestamp>/output/knowledge_graph.html in your browser to explore the result.
Install uv, clone the repo, sync dependencies, run the setup wizard, then extract.
git clone https://github.com/SenolIsci/mykg && cd mykg
uv sync && uv run mykg init --force
Then extract a knowledge graph from your notes:
uv run mykg extract-graph my_notes/
For Ollama (local inference, no API key needed), pull a model and select the ollama-local profile when mykg init prompts you.
ollama pull llama3.3
mykg init
mykg extract-graph my_notes/
```
<input_dir> is any directory containing your source files. Subdirectories are included recursively. Only files matching the configured extensions are copied into the session:
.md — always included (the pipeline's native format)preprocess.extensions in mykg_config.yaml (.pdf, .docx, .doc, .pptx, .xlsx, .png, .jpg, .jpeg, .html, .htm, .txt by default)Everything else (.py, .json, .yaml, lock files, etc.) is ignored. Hidden directories (.venv, .git, etc.) and the sessions folder are also excluded automatically, so you can safely point extract-graph at the project root or any parent directory.
output/obsidian_vault/ and ask questions, trace relationships, and get answers grounded in your own documentsmykg mcp-serve to expose your knowledge graph via the Model Context Protocol; integrates with Claude Desktop, Cherry Studio, and any MCP-compatible client — 13 query tools let LLMs search entities, explore relationships, find paths, traverse the graph, and read wiki notes directly from your extracted knowledge; see MCP Server--base-schema TTL file (RDFS or OWL) to lock in classes and properties from an existing formal ontology; the LLM expands it with domain-specific concepts but will not rename, remove, or contradict your authoritative vocabulary. Please note that this mechanism is controlled by the LLM, and may not be strictly enforced. Add --freeze-schema to skip LLM schema induction entirely and extract from the documents strictly against your ontology verbatim — no surprise types, no invented properties--thesaurus to load a SKOS vocabulary; skos:exactMatch terms are collapsed silently, skos:closeMatch terms trigger a warning — giving the schema merger richer synonym awareness than string matching aloneintermediate/schema.ttl) that can be opened directly in ontology editors such as Protégé. The TTL is validated by rdflib (syntax + semantic checks: domain/range refer to declared classes, no conflicting ranges) before any extraction begins--review, edit the schema, and resume extraction. Edit schema.json directly or refine schema.ttl in Protégé and feed it back with --freeze-schema<p align="center"> <img src="https://gcore.jsdelivr.net/gh/SenolIsci/mykg@main/docs/diagrams/architecture-sketch.png" width="95%" style="vertical-align:middle;"> </p>
Requires Python 3.11+ (developed on macOS; automated CI runs the test suite on Ubuntu and Windows), and one of: an Anthropic/OpenAI/Gemini/OpenRouter API key, Ollama running locally, or the claude CLI.
Walkthroughs and case studies on Medium:
```bash
mykg merge-graphs 2026-05-01T10-00-00 2026-05-15T14-30-00
All configuration lives in a single mykg_config.yaml file discovered automatically from the working directory (or any parent). There are no hardcoded defaults in the code — the YAML is the sole source of truth.
mykg init # interactive: choose provider, model, paste API key
# writes mykg_config.yaml and .env.mykg in one step
mykg init --force # overwrite an existing config
mykg init --profile openrouter-free --model google/llama-4-maverick --api-key sk-or-... # non-interactive
The wizard walks you through three prompts:
ANTHROPIC_API_KEY=sk-ant-... ``` For source installs you can also copy sample.env.mykg to .env.mykg as a starting template.
| Option | Description |
|---|---|
--session NAME | Resume an existing session by folder name |
--from-step NAME | Delete a step's outputs and re-run from that point |
--review | Pause after Pass 1 for manual schema review |
--append | Skip Pass 1; extract NEW files only. Modified and deleted files are detected and warned about — add --sync to act on them |
--sync | With --append: reconcile the graph against the folder — re-extract MODIFIED files and remove DELETED ones |
--update | Shorthand for --append --sync |
--append-with-grow-schema | Like --append, but runs a locked Pass 1 over changed files to expand the schema. Composes with --sync |
--pass1-schema-induction-only | Run every step before Pass 2 (through schema_flatten), then stop — inspect/edit the schema before extracting |
--pass2-kg-extraction-only | Skip schema induction (requires an existing schema) and extract the full corpus through validate_graph. Unlike --from-step pass2, always re-derives flattened_schema.json first, so a hand-edited schema is picked up |
--profile NAME | Use a different LLM profile from mykg_config.yaml for THIS run only (config file untouched; re-resolves provider/model/workers/timeouts from that profile) |
--model NAME | Override the model for this run. Requires --profile |
--workers N | Parallel workers for Pass 2 (default: pass2.max_workers from the active/selected profile) |
--confidence-agg mean\|max | Confidence aggregation when deduplicating |
--base-schema PATH | Locked TBox TTL file (locked classes/properties cannot be changed by the LLM) |
--freeze-schema | Use --base-schema verbatim: skip Pass 1 LLM induction entirely |
--thesaurus PATH | SKOS TTL thesaurus for synonym resolution in schema merge |
--obsidian-vault | Force Obsidian vault export for this run (overrides config) |
--neo4j-csv | Force Neo4j LOAD CSV bundle export for this run (overrides config) |
--log-file PATH | Write logs here (relative paths placed inside the session folder) |
--verbose / -v | Enable DEBUG-level logging |
mykg extract-graph my_notes/ --profile openrouter-free --model google/llama-4-maverick
mykg fetch-web https://github.com/SenolIsci/mykg mykg extract-graph ./mykg_web_fetch/github.com_SenolIsci_mykg/input/
myKG reads API keys from environment variables. Set them by exporting directly or by creating a .env.mykg file in your project directory (loaded automatically on startup).
Option A — export in your shell:
export ANTHROPIC_API_KEY=sk-ant-...
Option B — create a .env.mykg file:
```bash
A 429 surfaces in the log as a retry warning like:
[WARNING] mykg.llm.retry — OpenAI 429 rate-limit (attempt 1/5) — retrying in 2.0s
429 is a "Too Many Requests" error. If you see repeated 429 errors during pass1, pass2, or the orphan-connection pass, your account's requests-per-minute limit is lower than the number of concurrent calls mykg is making. Each profile sets these independently under pipeline::
pass1.max_workers — concurrent schema-induction batch callspass2.max_workers — concurrent per-file extraction callsorphan_pass.max_workers — concurrent orphan-connection callsLower these (e.g. from 8 down to 2–4) in the active profile to reduce concurrent requests. This is especially likely on openrouter-free (free-tier models have very low per-minute caps), on gemini with a free-tier key (5 requests/minute/model — drop pass1/pass2/orphan_pass to 1–2), and on lower-tier anthropic-claude/openai accounts. llm.retry_429_max / llm.retry_429_base_delay control automatic backoff on a 429, but a persistent 429 is a signal to reduce max_workers, not just retry harder. claude-cli is unaffected — it is serial by design (max_workers: 1); it doesn't hit API rate limits since there's no API call. agent-claude-code is not API rate-limited either (no API key involved), but it is not serial — its default profile sets pass1/pass2/orphan_pass max_workers > 1 (configurable, like any other profile), since the skill dispatches multiple subagents per wave.
Also check your quota/credits. Some providers return 429 when your account has exhausted its token quota or spending balance, not only for request cadence. If lowering max_workers doesn't help and the 429s persist from the very first call, check that your account still has available tokens/credits (e.g. the OpenAI/Anthropic billing dashboard, or your OpenRouter balance). No max_workers value will clear a 429 caused by a depleted balance — top up or switch to a profile with quota (e.g. ollama-local for local inference, or claude-cli which bills via your Claude Pro/Max plan instead of the API).
Reads a directory of mixed format files and produces a typed knowledge graph in three output formats. The pipeline runs 12 sequential steps; all intermediate state is persisted so any step can be re-entered without repeating upstream work.
The pipeline runs 12 steps in sequence. All intermediate state is written to disk so any step can be re-entered without repeating upstream work.
| # | Step | LLM | Key outputs |
|---|---|---|---|
| 1 | preprocess | — | preprocess.done, preprocess_manifest.json, files under input/_preprocessed/ *(routes non-md inputs to MinerU, markdownify, or rename; no-op for pure Markdown corpora)* |
| 2 | ingest | — | file_manifest.json |
| 3 | pass1 | ✓ (3 calls) | schema.json, schema.ttl, schema_history/, pass1_batch_selection.json, pass1_batch_proposals/ |
| 4 | schema_validate | — | schema_validate.done |
| 5 | human_review | — | schema_approved.flag *(only with --review)* |
| 6 | schema_flatten | — | flattened_schema.json |
| 7 | pass2 | ✓ | raw_extractions.json, chunk_node_index.json |
| 8 | normalize_names | ✓ | name_normalization.json |
| 9 | assemble | — | edge_metadata.json, nodes.json, merge_log.json |
| 10 | orphan_score | — | orphan_candidates.json |
| 11 | orphan_connect | ✓ | orphan_connections.json, orphan_log.json |
| 12 | validate_graph | — | nodes.jsonl, edges.jsonl, knowledge_graph.ttl, knowledge_graph.html, networkx_output/, obsidian_vault/, neo4j_csv/ *(optional)* |
Pass 1 internally runs four sequential stages: parallel batch induction → algorithmic merge → harmonization LLM call → quality review LLM call. pass1.max_schema_proposals (default 50) caps the number of batches dispatched to the LLM; set to -1 to dispatch all batches on large corpora.
mykg approve-schema --session <name> mykg extract-graph my_notes/ --session <name> --review # resumes from Pass 2 ```
mykg 是一个能够构建高可信度知识图谱的工具。它通过一种能够自我演进的本体(Ontology)机制,实现知识的持续适配与一致性维护。通过为提取的知识分配置信度评分,mykg 确保了随着知识库规模的增长,信息始终保持在事实基础上(Grounded)且高度可靠。
mykg 的核心优势在于其自演进的本体构建能力。它不仅能自动适应不断变化的信息,还能在提取过程中保持逻辑一致性。通过为每个知识点引入置信度评分机制,开发者可以有效识别并管理知识的可靠性,从而构建出一个既动态生长又严谨可靠的知识图谱系统。
运行 mykg 需要 Python 3.11+ 环境。在执行 live 测试时,需确保环境变量或 `.env.mykg` 文件中已配置 `OPENROUTER_API_KEY`。此外,根据选择的推理后端,你可能需要准备 Anthropic、OpenAI 或 OpenRouter 的 API key,或者在本地运行 Ollama 以实现无 API key 的本地推理。
你可以通过 PyPI 进行快速安装:执行 `pip install mykg` 后,运行 `mykg init` 进入交互式设置向导,自动生成 `mykg_config.yaml` 和 `.env.mykg`。若需从源码安装,请使用 `uv` 工具:克隆仓库后执行 `uv sync`,并通过 `uv run mykg init --force` 完成初始化。对于本地推理需求,支持通过 Ollama 运行模型。
mykg 提供基于本体引导(Ontology-Guided)的提取功能。提取过程严格遵循 RDFS/OWL Schema,确保概念类型、属性名称及层级关系在提取前是显式且可检查的。用户可以通过 `--base-schema` 参数导入现有的 TTL 文件,实现“自带本体”模式,让 LLM 在既定的形式化框架内进行精准的知识提取。
所有的配置均统一管理在工作目录下的 `mykg_config.yaml` 文件中,该文件是系统的唯一事实来源(Source of Truth)。对于 API Key 等敏感信息,mykg 会自动从 `.env.mykg` 文件中读取。你可以通过 `mykg init` 交互式地配置 Provider、Model 及 API Key,无需手动修改代码中的硬编码默认值。
在使用过程中,如果遇到 HTTP 429 错误(API Rate Limits),说明你的 API 账号每分钟请求频率限制低于 mykg 的并发调用量。你可以通过修改 `pipeline:` 配置项下的 `max_workers` 参数(如 `pass1.max_workers`)来降低并发数,从而适配不同的 API 使用限制。
mykg 的提取流水线(Extract Pipeline)采用高度模块化的设计,能够读取混合格式的文件并生成三种格式的类型化知识图谱。整个流程包含 12 个顺序执行的步骤,且所有中间状态都会持久化到磁盘。这意味着你可以随时从任何一个步骤重新进入,而无需重复执行之前的上游工作,极大地提升了处理大规模数据的效率。
高质量的知识图谱提取工具
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
经综合评估,知识图谱提取 在Claude技能赛道中表现稳健,质量优秀。如果你已有明确的使用需求,可以直接上手体验;如果还在评估阶段,建议对比同类工具后再做决策。
| 原始名称 | mykg |
| 原始描述 | 开源Claude技能:Knowledge graph extractor: Markdown (or any format) → knowledge graph with RDFS/。⭐39 · Python |
| Topics | claude_skillai_agent知识图谱 |
| GitHub | https://github.com/SenolIsci/mykg |
| License | MIT |
| 语言 | Python |
收录时间:2026-06-28 · 更新时间:2026-07-03 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端