Knowledge graphsexplained at five levels

One fact — "Santiago is the capital of Chile" — carried up five rungs. A child drags two bubbles and draws a labelled string between them; an expert manipulates the geometry of a scoring function and poisons a GraphRAG retrieval context. Same entities, same edges, five levels of machinery.

The fact under discussion"Santiago is the capital of Chile" — one edge in a tiny graph of cities, countries, people and the sources that vouch for them.
1

To a seven-year-old

Knows: what a city and a country are, and how to draw a line between two dots; does not know what data, a database, or a computer language is.

Look at the panel. Those floating bubbles are things. Santiago is a thing. Chile is a thing. Michelle Bachelet is a thing — she's a person, but people are things too.

Now I want to tell you something true about two of them. Santiago is the capital of Chile. How do I show that, without a sentence?

I tie a string between them. And I write on the string, so nobody forgets which kind of true thing it is. The string between Santiago and Chile says capital of.

Try it. Drag the Santiago bubble onto the Chile bubble. When you drop it, the panel asks you what to write on the string — pick capital of from the little row of words. A string appears, and underneath, the panel reads your fact back to you: "You just said: Santiago is the capital of Chile."

That's a fact. Two bubbles and one string with a word on it. Every fact you know can be tied up this way.

Now do it again. And again.

Tie Chile to South America with located in. Tie Chile to Argentina with borders. Tie Buenos Aires to Argentina with capital of.

After a while you don't have facts any more. You have a web — bubbles all over the place with strings running between them. That web is what grown-ups call a knowledge graph. It's just a map of things and how they're joined.

The good bit

Tap a bubble. Everything it is tied to lights up, and everything else goes pale. That's how you see what one thing's whole story is.

Then press Walk the strings. Watch it start at Santiago, slide along the string to Chile, and then along the next string to South America.

Nobody ever tied Santiago straight to South America. There's no string there. But you just walked from one to the other, so now you know: Santiago is in South America.

That's the whole trick. You tie down the things you were told — and then, by walking, you find out things nobody told you.

Count the number at the bottom of the panel. That's how many facts you've tied so far. Real ones have billions of strings. Nobody tied them by hand.
Draw a fact
Drag one bubble on top of another to tie a string between them.
Facts tied: 0
a thinga string with a word on itthe walk
2

To a teenager

Knows: lists, spreadsheets, maybe a little Python; has used Wikipedia and search engines. Does not know formal semantics or query languages.

Last level we called them bubbles and strings. Time for the real names.

A bubble is an entity. Santiago is an entity. Chile is an entity. So are people, languages, continents — anything you can point at and say "that thing". A string is a relation, and it has a name written on it: capitalOf. Put a head entity, a relation and a tail entity together and you have a triple:

(Q2887, capitalOf, Q298)   # Santiago, capital of, Chile

Those Q codes are not decoration. Real graphs don't store the word "Santiago" as the identity of the thing — the word is ambiguous and language-specific. They store an opaque id and hang labels off it. Wikidata, the graph that feeds a lot of Wikipedia's infoboxes, really does call Santiago Q2887. Open the triple table under the panel and you're looking at the same shape a real graph uses: three columns, one row per fact.

Strings have arrows

Here's the first thing level one lied about by omission. Edges are directed and typed. capitalOf and hasCapital are two different relations pointing opposite ways. Swap the head and tail on capitalOf and you don't get a slightly odd sentence, you get a false one: Chile is not the capital of Santiago. Click a row in the table, hit the flip arrow button, and read what it says. Direction is meaning.

Some relations do survive the flip. borders is symmetric: if Chile borders Argentina then Argentina borders Chile, always. locatedIn is transitive: Santiago in Chile, Chile in South America, therefore Santiago in South America — even though nobody typed that row. Those properties are facts about the relation itself, not about any one pair of entities.

Two kinds of statement

"Santiago is the capital of Chile" is about two specific things. "All capitals are cities" is about every capital that has ever existed or will. You could try to write the second one as a million edges, or you can write it once, as a rule, in a separate layer called the ontology.

Flip show classes in the panel. Class boxes appear beside the entities — City, Country, Place — joined by subclass arrows: Capital ⊑ City ⊑ PopulatedPlace ⊑ Place. Thin edges say which class each entity belongs to. That's the schema. It's a graph too, sitting on top of the facts.

Now flip apply rules. Derived edges appear. Santiago was only ever typed as a City, but a City is a PopulatedPlace, which is a Place — so those types get derived, and the transitive locatedIn hop to South America appears too. Nobody wrote those. A program worked them out from rules you wrote once.

Answers nobody typed

Tap the question chip Which cities are in South America? and watch the panel walk it: start at every entity of class City, follow locatedIn one hop, follow it again. The readout tags each answer ASSERTED if a row in the table says it outright, or DERIVED if the machine reasoned it out. That distinction is the whole point of the level. Turn the rules off and half the answers vanish — the facts didn't change, only what you were allowed to conclude from them.

Triples and types
Click a row in the triple table, or a bubble on the stage.
Head, relation, tail — one row per asserted fact. Coloured rows are derived, not stored.
entityclassderived
3

To a computer science undergraduate

Knows: SQL, relational algebra, basic logic, big-O. Does not know RDF, SPARQL, Cypher, or the open-world assumption.

Last level we called them bubbles, strings and labels. The real words: a knowledge graph is a graph of data intended to accumulate and convey knowledge of the real world, whose nodes represent entities of interest and whose edges represent relations between these entities 1. Formally it is a set of triples G = {(h, r, t)} over an entity set and a relation set 23. Our running edge is (Q2887, capitalOf, Q298).

Two data models, not one

The graph model is not fixed. It may be a directed edge-labelled graph — RDF — or a property graph 1. The difference bites the moment you want to say something about a statement. Santiago has been capital since 1818, and one particular reference vouches for it. In a property graph that is two key/value pairs hanging off the edge. In plain RDF an edge has nowhere to hang anything, so you mint a statement node and point at it — reification:

# RDF: reified statement
:s1 a rdf:Statement ;
    rdf:subject :Q2887 ; rdf:predicate :capitalOf ; rdf:object :Q298 ;
    :start "1818" ; :source <wikidata:Q2887#ref1> .
// Property graph: attributes on the edge itself
(:City {id:'Q2887'})-[:capitalOf {start:1818, source:'wikidata:Q2887#ref1'}]->(:Country {id:'Q298'})

Flip the property-graph view switch in the panel and watch the qualifiers on Santiago's edge migrate between a green statement node and a label on the edge. Same information, four extra triples versus zero.

Querying is relational algebra plus paths

A triple store is a three-column table, so a basic pattern query is a self-join. That part you already know. What graph query languages add is the second half of this sentence: they support not only standard relational operators (joins, unions, projections, etc.), but also navigational operators for recursively finding entities connected through arbitrary-length paths 1. Arbitrary length is the bit plain SQL-92 cannot express.

# SPARQL
SELECT ?city WHERE {
  ?city :capitalOf ?c . ?c :locatedIn+ :Q18 }
// Cypher, same answer
MATCH (city)-[:capitalOf]->(c)-[:locatedIn*1..3]->(:Q18) RETURN city

Run them side by side in the panel. Then set the path length back to *1..1 and the containment hop that needed two steps disappears: with a fixed-length join you must know the depth in advance. That is the navigational operator earning its keep.

Deduction adds edges nobody wrote

Level 2's "rule" has a name and a formalism. Knowledge splits into simple statements, such as "Santiago is the capital of Chile", which live as edges, and quantified statements, such as "all capitals are cities", which need something more expressive 1. That something is an ontology or a rule language, which define and reason about the semantics of the terms used to label and describe the nodes and edges 13. Turn on RDFS entailment and two rules fire over our data: rdfs:subClassOf transitivity up the Capital ⊑ City ⊑ PopulatedPlace ⊑ Place chain, and transitivity of locatedIn, which materialises (Q2887, locatedIn, Q18). Those rows are marked DERIVED in the binding table. Turn entailment off and the same query returns fewer answers — the query did not change, the semantics did.

The open-world assumption

Your database says NOT EXISTS means false. A knowledge graph does not. There is no edge saying Valparaíso is not the capital of Chile, and there is no edge saying Michelle Bachelet does not speak Spanish; under the open-world assumption both are simply unknown. So FILTER NOT EXISTS answers "not in my graph", never "not true in the world". Tick the OWA check in the panel and any query whose answer depends on absence gets flagged. Deduction only ever adds what follows necessarily — which is why the next level stops deducing and starts predicting.

Wikidata is a real graph of exactly this shape, backing Wikipedia and other services 3. Its qualifiers and references are the production version of the switch in the panel.
Query engine
Press Run query.
Engine understands two patterns: ?x :capitalOf ?y then ?y :locatedIn+ :Q18 (edit the relation names and the target id), plus FILTER NOT EXISTS.
entityclassreified statemententailed
4

To a PhD student in knowledge graph completion

Knows: SGD, embeddings, ranking metrics, PyTorch. Does not know the filtered-ranking conventions, the leakage history of FB15k/WN18, or how negative sampling choices dominate results.

Last level the graph was something you queried. A query engine only ever returns what someone wrote down, and under the open-world assumption a missing edge means nothing at all. So take the incompleteness seriously and make it the task.

The task, stated properly

Write the graph as a set of triples, G = {(h, r, t)} ⊆ E × R × E 24. Most graphs of this shape are badly incomplete, and completion means inferring the missing links — concretely, predicting the missing head or tail given (h, r) or (r, t) 2. You learn a scoring function s(h, r, t) that measures the plausibility of a triple from its embeddings, then rank every candidate entity in the tail slot. That framing is pointwise learning-to-rank 4, and it is why your metric is a ranking metric and not accuracy.

Three geometries, one interface

The scoring functions split into translational-distance and semantic-matching families 2. Pick a model in the panel and the formula renders above the plot:

# translational
TransE   s = −‖es + rr − eo‖p        rr ∈ ℝk
# bilinear / semantic matching
DistMult s = ⟨es, rr, eo⟩            rr ∈ ℝk
ComplEx  s = ⟨es, rr, eo⟩            rr ∈ ℂk
# rotation
RotatE   dr(h,t) = ‖h ∘ r − t‖

The formulas and the O(nek + nrk) space costs are lifted verbatim from the ConvE table 4; RotatE's is the Hadamard rotation with p(h,r,t) = sigmoid(γ − dr(h,t)) 5. The geometry buys you specific algebra. DistMult's trilinear product is symmetric in s and o, so it literally cannot separate capitalOf from hasCapital; ComplEx fixes that by moving rr into ℂk and conjugating the object 4. Train DistMult in the panel and watch borders — the symmetric relation — come out fine while the capital pair collapses.

Negatives are half the model

Graphs contain positives only, so you manufacture negatives by corrupting h or t; the established variants are uniform and Bernoulli sampling 2. The loss you actually optimise is

L = −log σ(γ − dr(h,t)) − Σi wi · log σ(dr(h′i,t′i) − γ)

with wi = 1/n under uniform sampling 5. Self-adversarial sampling replaces that with wi = p(h′i,r,t′i) = softmax(α · f(h′i,r,t′i)), weighting each negative by the current model's own score 5. Push the α slider up and most of the gradient goes to the handful of hard negatives; that is where a large part of the reported gain over uniform sampling comes from, which is the first reason to distrust family-versus-family comparisons.

The pitfall your supervisor will lead with

Mean Reciprocal Rank plus Hits@k, computed filtered: when ranking candidates for (h, r, ?) you remove every other tail known to be true from the candidate list, otherwise a correct alternative fact penalises you. Flip filtered off in the panel and watch MRR sag for no modelling reason.

Then the real hazard. WN18 and FB15k suffer test-set leakage from inverse relations of training triples appearing in the test set, and the effect is severe enough that a simple rule-based model achieves state-of-the-art results 4. Our TRIPLES carry the same defect by construction: capitalOf and hasCapital are stored as mirrored pairs. Flip leak inverses and the leakage banner reports how much of the MRR a memorise-the-inverse baseline explains on its own. The remedy in the literature was to derive robust variants of the datasets — FB15k-237 and WN18RR, with the inverse relations removed 45.

Caveats a supervisor gives: nine entities is a toy, so treat the curves as behavioural demonstrations, not results. Report the negative-sampling regime, k, and the training budget with every number, or your ablation is unfalsifiable. And run the inverse-rule baseline on any new benchmark before you claim a model beat it.
Train a link predictor
Pick a model and press Train.
MRR –Hits@1 –Hits@3 –Hits@10 –loss –
Leakage banner: inverse-rule baseline not yet computed.
Top-5 tails for (Santiago, capitalOf, ?)
  1. train to populate
entity embeddingloss curveMRR (filtered)leaked-inverse contribution
5

To a peer working on KG–LLM systems

Knows: retrieval augmentation, transformer internals, adversarial ML, the KGC literature. Needs no scaffolding — needs the seams argued, and needs to know which claims the ledger actually supports.

Four levels in, we have a graph of data whose nodes are entities and whose edges are relations 1, a split between simple statements as edges and quantified statements as axioms 1, a query layer that adds navigational operators to the relational core 1, and a scoring function s(h,r,t) ranked pointwise over candidates 4. Now the honest part. Some of what I told you at level 4 is folklore, and the part of this level that you probably care about most — attacks — is mostly not in my evidence ledger. I will label it as such, in the panel and here.

What level 4 oversold

The family-versus-family story (translational vs. semantic-matching 2, TransE ‖es+rr−eo‖p vs. ⟨es,rr,eo⟩ with rr∈ℝk or ℂk 4, RotatE's dr(h,t)=‖h∘r−t‖ 5) is usually told as geometry: ComplEx handles antisymmetry, RotatE handles composition. That is true about the hypothesis class and mostly silent about the leaderboard. The training regime moves the numbers just as hard: uniform vs. Bernoulli corruption of h or t 2, and self-adversarial weights p(h′i,r,t′i) ∝ exp(α·f) replacing the 1/n in the negative-sampling loss 55. My position: attribute a gain to geometry only when negatives, dimension and budget are matched — and remember that on WN18/FB15k a rule-based model reached state of the art because inverse relations leaked into test, which is why FB15k-237 and WN18RR exist 45.

Three frameworks, and where the trust boundary sits

The canonical taxonomy is three-way: KG-enhanced LLMs, LLM-augmented KGs, synergized LLMs + KGs 6, motivated by a symmetry — LLMs fall short of accessing factual knowledge, KGs are hard to construct 6. Under LLM-augmented KGs you get LLM-augmented embedding, completion, KG-to-text and KGQA 6; under the other direction, KG-guided planning, neuro-symbolic reasoning, and post-hoc factuality checking of LLM output 7; and construction/canonicalization across heterogeneous sources 7. GraphRAG is the concrete instance: "a data pipeline and transformation suite … designed to extract meaningful, structured data from unstructured text using the power of LLMs" 8, using "knowledge graph memory structures to enhance LLM outputs" 8 to "form a targeted context for question answering" 8. Graph-model-plus-LLM retrieval is still active work 6.

Flip the pattern switch in the panel and watch the boundary move. In KG-enhanced-LLM the graph is read-only at inference and the attack surface is retrieval ranking. In LLM-augmented-KG the extractor writes, so attacker-supplied text becomes attacker-authored triples. Synergized closes the loop, and a poisoned write returns as retrieved context on the next question.

The argument I will actually defend

KGs are attractive because their knowledge is "accurate, explicit and easily-modifiable" 7. That third adjective is the whole security story. Explicit means a grounded answer is a deterministic function of a small retrieved subgraph; easily-modifiable means one edge changes that function. Add (Valparaiso, capitalOf, Chile) in the panel and every downstream answer rewrites — no gradient, no jailbreak string, one row. The control point is therefore not the prompt: it is provenance. Our shared data already carries it — source, start, trust per statement — so turn trust weighting on and set the threshold above user-upload.

Boundary of the ledger

Nothing in my sources demonstrates a KG poisoning or prompt-injection attack. The propagation claim is an inference from the explicit/easily-modifiable property 7 combined with the extraction-from-unstructured-text pipeline 8; the panel labels it INFERRED. Passage p3's injection succeeding against a real extractor is speculative here. One thing is documented and worth your operational attention: the reference implementation "is largely in maintenance mode, and won't be accepting new PRs or implementing new features … particularly to address CVEs as they arise" 8. Build on it if you like; own the patch path. And note the level-3 asymmetry never went away — under the open-world assumption a missing edge is not a false one, so a defence that filters low-trust triples buys precision by refusing to answer.

Poison the pipeline
trust threshold 0.00
entityrelationpassage / sourceextracted tripleattacker-controlled

Sources

  1. Knowledge Graphs evidence sq1-1, sq1-4, sq1-2, sq1-3 · quality 5/5/5/5
  2. A Comprehensive Study on Knowledge Graph Embedding ... evidence sq2-1, sq2-2, sq2-3, sq2-4 · quality 4/4/4/4
  3. Knowledge Graphs: Opportunities and Challenges - PMC evidence sq1-6, sq1-7, sq1-8 · quality 4/4/3
  4. Convolutional 2D Knowledge Graph Embeddings evidence sq2-5, sq2-6, sq2-7, sq2-8 · quality 5/5/5/5
  5. RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space | alphaXiv evidence sq2-9, sq2-10, sq2-11, sq2-12 · quality 3/3/3/3
  6. GitHub - RManLuo/Awesome-LLM-KG: Awesome papers about unifying LLMs and KGs · GitHub evidence sq3-5, sq3-6, sq3-7, sq3-8 · quality 3/3/3/3
  7. A Survey on Unifying Large Language Models and Knowledge Graphs for Biomedicine and Healthcare - PMC evidence sq3-3, sq3-2, sq3-1, sq3-4 · quality 4/4/4/3
  8. GitHub - microsoft/graphrag: A modular graph-based Retrieval-Augmented Generation (RAG) system · GitHub evidence sq3-9, sq3-10, sq3-11, sq3-12 · quality 4/4/4/4

Verification

Every material claim in the prose was checked against the evidence ledger by an independent verifier pass: 3 partial, 17 supported.

ClaimVerdictNote
A knowledge graph is a graph of data intended to accumulate and convey knowledge of the real world, whose nodes represent entities of interest and whose edges represent relations between these entitiessupportedsq1-1 states verbatim the definition of a knowledge graph with nodes as entities and edges as relations.
Formally it is a set of triples G = {(h, r, t)} over an entity set and a relation setsupportedsq2-1 formalizes G = {(h, r, t)} over entity set E and relation set R, and sq1-6 supports the triplet formalism.
The graph model may be a directed edge-labelled graph — RDF — or a property graphpartialsq1-1 supports directed edge-labelled graph or property graph, but does not mention RDF explicitly.
Graph query languages support not only standard relational operators (joins, unions, projections, etc.), but also navigational operators for recursively finding entities connected through arbitrary-length pathssupportedsq1-4 states graph query languages support relational operators plus navigational operators for recursively finding entities connected through arbitrary-length paths.
Knowledge splits into simple statements, such as "Santiago is the capital of Chile", which live as edges, and quantified statements, such as "all capitals are cities", which need something more expressivesupportedsq1-2 gives both examples and the need for a more expressive representation for quantified statements.
An ontology or rule language defines and reasons about the semantics of the terms used to label and describe the nodes and edgessupportedsq1-3 says ontologies and rules define and reason about the semantics of terms labelling nodes and edges; sq1-7 adds the ontology-as-schema role.
Wikidata is a real graph of exactly this shape, backing Wikipedia and other servicespartialsq1-8 confirms Wikidata is a knowledge graph supporting Wikipedia and other services, but 'exactly this shape' is an inference not directly evidenced.
Write the graph as a set of triples, G = {(h, r, t)} ⊆ E × R × Esupportedsq2-5 gives G = {(s,r,o)} ⊆ E×R×E and sq2-1 gives the (h,r,t) notation, together matching the claim.
Most graphs of this shape are badly incomplete, and completion means inferring the missing links — concretely, predicting the missing head or tail given (h, r) or (r, t)supportedsq2-2 states most KGs are far from complete and KGC infers missing links by predicting missing head or tail given (h,r) or (r,t).
The framing of learning a scoring function and ranking every candidate entity in the tail slot is pointwise learning-to-ranksupportedsq2-5 formalizes link prediction as a point-wise learning to rank problem with a scoring function.
The scoring functions split into translational-distance and semantic-matching familiessupportedsq2-3 explicitly classifies score functions into translational distance based and semantic matching based models.
The formulas (TransE s = −‖es + rr − eo‖p, DistMult s = ⟨es, rr, eo⟩ with rr ∈ ℝk, ComplEx with rr ∈ ℂk) and the O(nek + nrk) space costs are lifted verbatim from the ConvE tablesupportedsq2-6 quotes the table rows with those exact formulas, parameter domains, and O(nek+nrk) costs; the source is the ConvE paper.
RotatE's scoring is the Hadamard rotation dr(h,t) = ‖h ∘ r − t‖ with p(h,r,t) = sigmoid(γ − dr(h,t))supportedsq2-9 gives dr(h,t)=‖h ◦ r − t‖ and p(h,r,t)=sigmoid(γ − dr(h,t)).
DistMult's trilinear product is symmetric in s and o, so it cannot separate capitalOf from hasCapital; ComplEx fixes that by moving rr into ℂk and conjugating the objectpartialsq2-6 shows DistMult's trilinear product with rr ∈ Rk and ComplEx with rr ∈ Ck, but the quote does not state symmetry, the capitalOf/hasCapital failure, or conjugation of the object.
Graphs contain positives only, so negatives are manufactured by corrupting h or t; the established variants are uniform and Bernoulli samplingsupportedsq2-4 states KGs predominantly contain positive triples, negatives come from corrupting h or t, with established uniform and Bernoulli methods.
The negative-sampling loss L = −log σ(γ − dr(h,t)) − Σi wi · log σ(dr(h′i,t′i) − γ) uses wi = 1/n under uniform samplingsupportedsq2-10 gives the loss with the 1/n weight on each negative term under traditional (uniform) negative sampling.
Self-adversarial sampling replaces uniform weights with wi = p(h′i,r,t′i) = softmax(α · f(h′i,r,t′i)), weighting each negative by the current model's own scoresupportedsq2-11 gives the self-adversarial weighting p(h'i,r,t'i) as a softmax over α·f, adaptively based on the current model's predictions.
WN18 and FB15k suffer test-set leakage from inverse relations of training triples appearing in the test set, and the effect is severe enough that a simple rule-based model achieves state-of-the-art resultssupportedsq2-7 states WN18 and FB15k suffer test set leakage from inverse relations and that a simple rule-based model achieves state-of-the-art.
The remedy in the literature was to derive robust variants of the datasets — FB15k-237 and WN18RR, with the inverse relations removedsupportedsq2-8 describes deriving robust dataset variants and sq2-12 names FB15k-237 and WN18RR as removing inverse relations.
The canonical KG–LLM taxonomy is three-way: KG-enhanced LLMs, LLM-augmented KGs, synergized LLMs + KGs , motivated by a symmetry — LLMs fall short of accessing factual knowledge, KGs are hard to constructsupportedsq3-5 gives the three-way taxonomy and sq3-6 states LLMs fall short of accessing factual knowledge while KGs are hard to construct.

How this was made

Researched by the Richards.AI deep research agent: the topic was scoped, decomposed into subquestions researched by parallel subagents into an append-only evidence ledger, then written at five levels on one running example, audited by an independent claim-verification pass, and its interactive panels were exercised in a headless browser before publication.

preset quickreason lane anthropic:claude-opus-5verifier lane anthropic:claude-opus-5prompt rev 4b9087b9e9c6/ae487a6201b7browser validation passedevidence records 32