/knowledge-graph-extract:knowledge-graph-extractfrom knowledge-graph-extract
Extracts subject-relation-object triplets from documents into a JSONL dataset with deterministic chunking and progress tracking. Supports resuming interrupted extractions and generating Cypher import scripts for Neo4j/Memgraph.
Ships in knowledge-graph-extract. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Extract subject–relation–object triplets from documents into an append-only JSONL dataset, with deterministic chunking and a progress manifest so an interrupted run resumes exactly where it stopped. Optional schema enforcement and Cypher generation via bundled stdlib-only Python scripts (no pip dependencies, no network, no database connections).
Core principle: the output directory is the state. Every step reads its inputs from and
records its result in <output_dir> before moving on. If the session dies at any point,
re-invoking this skill on the same directory continues the work.
File formats: see references/output-format.md. Schema format: see references/schema-format.md.
Collect from the user (ask only for what's missing):
<output_dir>/schema.json) or inline types in the
prompt (write the equivalent schema.json and show it to the user)."generated_by": "agent" so a resumed session knows it was inferred.triples.jsonl's vocabulary as you go.If <output_dir>/manifest.json exists, this is a resume:
python3 scripts/kg_status.py <output_dir>
Report progress to the user, then continue at Phase 3 from the chunk kg_status.py names.
An in_progress chunk is re-extracted from scratch — its earlier triplets may partially
exist; the validator's duplicate check cleans exact repeats later. Never edit the chunk plan
of an existing manifest.
Chunk boundaries must be deterministic — decided once, recorded, never recomputed.
Record a unit per document ("line" or "page") so resume and status reporting know
how to address each chunk.
unit: "line":
awk 'END{print NR}' <file> (counts a final line that has no
trailing newline, which wc -l silently drops).start_line/end_line.unit: "page":
pages arg): a PDF of ≤ 10
pages reads in full (make it one chunk — done), and a larger one errors with the exact
total ("This PDF has N pages…") — use that N.start_page/end_page.manifest.json (format: references/output-format.md) with every
chunk pending. The chunk plan is now immutable; only status/triplets fields change.For each pending chunk, in manifest order:
in_progress:
python3 scripts/kg_mark.py <output_dir> <doc> <chunk_id> in_progressunit: "line" → Read with offset/limit over
start_line..end_line; unit: "page" → Read with the pages parameter set to
start_page-end_page.cut -c1-160 <output_dir>/entities.jsonl — you need names, types, and aliases,
not the full records.triples.jsonl and new entities/aliases to entities.jsonl
(one JSON object per line; append with >>, never rewrite these files).done with its triplet count (this also flips the document to done
once its last chunk finishes):
python3 scripts/kg_mark.py <output_dir> <doc> <chunk_id> done --triplets <n>Context discipline (what makes long runs survive):
triples.jsonl back — it is write-only for you.manifest.json — change status only through kg_mark.py, which
rewrites it atomically so an interrupted write cannot corrupt the resume anchor.python3 scripts/validate_triples.py <output_dir> # report only
python3 scripts/validate_triples.py <output_dir> --apply # quarantine violations
Checks structure, schema conformance (types, relation domain/range), and exact duplicates.
--apply moves violations to rejected.jsonl (quarantined, never deleted) and rewrites
triples.jsonl atomically. Run report mode first and show the user the summary before
applying.
python3 scripts/generate_cypher.py <output_dir>
Writes cypher/00_constraints_neo4j.cypher and cypher/00_constraints_memgraph.cypher
(one indexes the MERGE key per label; load only the one matching the target DB — the DDL
syntax differs), then cypher/01_entities.cypher and cypher/02_relations.cypher — batched
UNWIND … MERGE statements with escaped literals grouped by label/relation type (portable
openCypher). Load order: the matching 00_constraints_* file → 01_entities → 02_relations.
The user loads them themselves (cypher-shell, Neo4j Browser, Memgraph); never connect to a
database on their behalf.
| Task | How |
|---|---|
| Show progress / find next chunk | python3 scripts/kg_status.py <output_dir> |
| Update chunk status (atomic) | python3 scripts/kg_mark.py <output_dir> <doc> <chunk_id> <status> [--triplets N] |
| Validate against schema | python3 scripts/validate_triples.py <output_dir> [--apply] |
| Generate Cypher | python3 scripts/generate_cypher.py <output_dir> |
| Resume interrupted run | Re-invoke skill with same output dir — Phase 1 handles it |
| Add triples/entities | Append (>>) to the .jsonl files, never rewrite |
generate_cypher.py; hand-written Cypher with interpolated names breaks on quotes and backslashes.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
knowledge-graph, entity-extraction, triplet-extraction, cypher, neo4j, memgraph
Other plugins' skills for the same job
npx claudepluginhub maddataanalyst/knowledge-graph-extract --plugin knowledge-graph-extract