-
Notifications
You must be signed in to change notification settings - Fork 2
Knowledge Graph Pipeline
type: concept up: "Wiki-LLM-Pattern" status: implemented tags: [kg, sparql, retrieval]
The frontmatter and body cross-references in the wiki feed an optional knowledge-graph pipeline that exposes the wiki as a SPARQL-queryable graph. Shipped in PR #14 as scripts/kg/. See Implementation-Status for the broader real-vs-aspirational classification and Wiki-Corrections-Log for the 2026-06-12 entry recording the transition of this page from aspirational to implemented.
scripts/kg/build-graph.sh walks the wiki, extracts frontmatter and body links, and produces a typed-edge graph as both JSON-LD and Turtle, plus a SHACL conformance report. The pipeline runs in-process Python using rdflib + pyshacl: no Java, no Fuseki, no subprocess.
- Frontmatter typed edges (
extends:,supports:,criticizes:,source:,up:,related:) become typed predicates resolving under the LA3D ontology (https://la3d.github.io/llm-wiki-colab/ontology#). - Body cross-references (
[text](Page-Name)) becomementionsedges, weighted via RDF-star. - Materialisation (inverse edges, area inheritance, hub flagging) runs as SPARQL CONSTRUCT queries against the loaded graph.
- SHACL validation produces
validation-report.ttl.
Outputs land in scripts/kg/build/ (gitignored): graph.jsonld, graph.ttl, graph-weights.ttl, graph-full.ttl, validation-report.ttl.
The typing comes from Typed-Edges-and-Frontmatter; the operations come from Three-Operations.
Use the KG for topology questions:
- "Which pages cite finding X?"
- "What concepts does this experiment depend on, transitively?"
- "Find all pages tagged Y that
criticizes:a parent of Z."
Use direct file reads for content questions: "What does page X actually say?"
The right pattern: use the KG to discover where to look, then use file tools to read what the chosen pages say. Reserve grep for non-wiki code or content searches that span many files.
Run ./scripts/kg/build-graph.sh after each ingest, or periodically. The script is idempotent. Flags: --wiki=PATH for a custom wiki location, --refresh-spec to re-fetch the LA3D ontology/SHACL spec (cached in .cache/), --stats for extractor coverage, --help for the full list.
The default mode is in-process: queries run against the loaded graph object directly. No server, no HTTP. For multi-client query, agent-write via SPARQL UPDATE, federated queries, or web dashboards, Apache Jena Fuseki can host the produced graph-full.ttl and rdflib talks to it via SPARQLStore. This is opt-in. The future agent-memory feature is expected to depend on the Fuseki path because cross-session writes need SPARQL UPDATE and an HTTP surface.
scripts/kg/ is not yet listed in ALWAYS_FILES in either sync script (see Sync-Flow). The pipeline exists in the template repo and is exercised by the test harness, but derived projects do not automatically receive it on update-from-template.sh. The likely path is shipping it as an opt-in feature under features/ (see the in-progress feature-flag framework, RFC #13) rather than promoting to ALWAYS_FILES.
Without the typed-edge contracts, the KG collapses to a directed graph of mentions between pages. That is useful but flat. With typed edges, the same query can ask not just "which pages connect to X" but "which pages support a claim that X". Edge typing is what turns the KG from a navigation aid into a reasoning substrate.
- Wiki-LLM-Pattern
- Typed-Edges-and-Frontmatter
- Three-Operations
- OKF-Alignment-Ideas: query semantics OKF v0.1 deliberately omits and our KG fills
- Limitation-Inverse-Edges-Missing
-
Sync-Flow: why
scripts/kg/does not yet propagate to derived projects - Wiki-Corrections-Log: receipt for the 2026-06-12 transition from aspirational to implemented