Skip to content

What is a knowledge graph?

5 min read

In short#

A knowledge graph stores facts as things (nodes) joined by named links (edges), so a program can follow the links to answer a question.

flowchart LR
  accTitle: One drink as a small knowledge graph
  accDescr: Vertex breve is an instance of Breve. Breve is a kind of Latte and a kind of Cappuccino. Vertex breve contains a Double shot.
  breve1["Vertex breve"] -->|instance of| breve["Breve"]
  breve -->|is a| latte["Latte"]
  breve -->|is a| cappuccino["Cappuccino"]
  breve1 -->|contains| shot["Double shot"]

Say a café, Vertex Coffee, wants to answer “which drinks have no milk?” A list of drink names can’t. A graph can. “Vertex breve contains Steamed half-and-half” is a link a program can follow. “Breve is a kind of Latte” shows what else is true about a breve. Without the links, you have a pile of words.

See it#

This is a small part of the ontology you build in the espresso tutorial. Vertex Coffee is the made-up café in that tutorial, so “Vertex breve” is its breve, one real drink on its menu. How to read the graphs explains rings, dots and the controls. The dashed outline marks the drink this page is about.

The graph shows two drinks from the Vertex Coffee menu in the espresso ontology.

  • Vertex breve is an instance of Breve. It contains Double shot, Steamed half-and-half and Milk foam.
  • Vertex cappuccino is an instance of Cappuccino. It contains Double shot, Steamed whole milk and Milk foam.
  • Breve is a kind of Latte and a kind of Cappuccino. Latte and Cappuccino are kinds of Milk drink, which is a kind of Espresso drink, which is a kind of Drink.

Notice the two kinds of link. “Is a” links stack kinds on top of each other, from Breve up to Drink. “Instance of” links join one real drink to its kind. Those two make a knowledge graph more than a pile of facts. The first one is the class hierarchy, and an instance is one real example of a class.

What okb adds#

A graph alone doesn’t stop you from linking a Milk drink to a bicycle. An ontology is the part that says which kinds exist and how they may connect. The ontology plus its real examples is a knowledge base. The okb files (nodes.json and edges.json) are a graph too, and every class, slot and instance in them is a node. See the file format for the details.

In okb#

Run okb show on a drink to see its links. Run it from the espresso folder that the espresso tutorial builds.

okb show "Vertex breve"

You’ll see the kind it belongs to, and then each fact. The links show up as values:

Vertex breve  Instance · i.vertex-breve
  instance of    Breve

  Values
    espressoToMilkRatio 0.33
    texture            foamy
    pullVolumeMl       —
    pourOrder          Shot, half-and-half, then foam
    origin             USA
    contains           Double shot, Steamed half-and-half, Milk foam
    variationOf        Latte, Cappuccino (fixed by Breve)

The contains line is three edges in the graph earlier on this page. The variationOf line is two more, and okb filled them in from the class, so you didn’t have to repeat them for every drink.

Explore it all#

Here is the whole espresso ontology: 31 classes and 16 instances. Use the checkboxes to add the terms, slots and competency questions that built it.

The espresso ontology has 31 classes and 16 instances.

  • Drink is the top class. Espresso drink, Milk drink, Pure espresso and Sweetened drink sit below it, with the drinks themselves below those, such as Cortado, Latte, Mocha and Breve.
  • Ingredient is the other top class. It has Coffee, Water, Milk, Foam, Chocolate, Whipped cream and Gelato.
  • Sixteen instances tie the two together, such as Vertex cortado, which contains Double shot and Steamed whole milk.

Common mistakes

  • Thinking the graph is the picture. The picture is one view. The nodes and edges in the files are the knowledge.
  • Mixing up a kind and an example. “Breve” is a kind of drink. “Vertex breve” is one on the menu. Without the difference, you can’t ask “which of our drinks are lattes?”
  • Linking everything to everything. A link needs a name, such as contains, and the kinds at each end must make sense for it.

Sources#

Ontology Development 101 by Noy and McGuinness (PDF), page 3: “An ontology together with a set of individual instances of classes constitutes a knowledge base.”

View page source