Skip to content
learn
  1. Learn
  2. Artificial Intelligence
  3. Knowledge, Logic and Planning

AI AI-02.01

Knowledge representation

Why AI systems store knowledge explicitly, and the classic forms it takes: facts, rules, frames with inheritance, and semantic networks.

Beginner 10 min Last reviewed

The big idea

The search algorithms in the last module were given everything on a plate: the states, the actions, the costs. Somebody had to write that down. A route planner needs to know which roads exist; a medical assistant needs to know which symptoms go with which illnesses; a support bot needs to know that a refund requires a receipt. Knowledge representationThe study of how to store what a system knows (facts, rules, objects and their relationships) in a form a program can reason with. is the craft of storing that knowledge in a form a program can reason with, not just look up.

Compare a pile of index cards with a well-organised filing cabinet. Both hold the same information. With the pile you can only find what you wrote down; with the cabinet, where each drawer says what kind of thing is inside and folders point at related folders, you can answer questions nobody wrote an answer for: "which of our suppliers are in countries with a port strike?" Representation is the drawer labels and the pointers.

Today most AI learns its knowledge from data instead of having it typed in. But explicit representations never went away. They live on in knowledge graphs, business rules, database schemas, and in the structured descriptions of tools that language-model agents call. Knowing the classic forms makes all of those easier to understand.

How it works

Step 1: Facts

The simplest unit is a factA single statement taken to be true, such as 'Paris is the capital of France', usually stored as a relation between named things.: a statement taken to be true. Written in a structured way, a fact is a relation between named things:

  • capital_of(Paris, France)
  • parent_of(Ada, Byron)
  • price(widget_42, 9.99)

Structure is the point. "Paris is the capital of France" as a sentence must be parsed and interpreted every time; capital_of(Paris, France) can be matched, indexed and combined with other facts directly. A database table is a large collection of facts of the same shape.

Step 2: Rules

A ruleA statement of the form 'if these conditions hold, then this conclusion holds', used to derive new facts from known ones. says how new facts follow from existing ones: if the conditions hold, then the conclusion holds.

  • If parent_of(X, Y) and parent_of(Y, Z), then grandparent_of(X, Z).
  • If an order is over 100 and the customer is new, then flag the order for review.

Rules are compact. One grandparent rule covers every family in the database, including families added next year. A program that applies rules to facts to derive new facts is an inference engine, and you will build one in First-order logic .

Step 3: Semantic networks

A semantic networkA graph whose nodes are concepts or objects and whose labelled edges are relationships between them, such as is-a and has-part. draws knowledge as a graph: nodes for concepts and objects, labelled edges for relationships. The most important edge is is-a, which builds a hierarchy of categories. Properties attached to a category are inherited by everything below it, so you state "birds have feathers" once instead of for every bird.

A semantic network of animals with inheritance and an exception Tweety is a Penguin, Penguin is a Bird, Bird is an Animal, and Robin is also a Bird. Bird has the properties covering feathers and can fly yes. Penguin overrides can fly with no. The question 'can Tweety fly' follows the glowing is-a edges from Tweety up to Penguin, where the answer no is found before the Bird default is reached. is-a is-a is-a is-a is-a Animal alive: yes Bird feathers . can fly: yes Robin habitat: gardens Penguin can fly: no Rocky a robin Tweety can Tweety fly? Figure 1. Properties live on the most general node they apply to and are inherited down the is-a edges. To answer 'can Tweety fly?', follow the glowing edges upward and take the first answer: Penguin's 'no' overrides Bird's default 'yes'.

Step 4: Frames

A frameA structured record for a concept or object, with named slots holding values, defaults, or links to other frames, and an is-a link to inherit slots from a parent. packages everything about one concept into a record with named slots, much like an object in a programming language or a row with a parent pointer. A Bird frame has slots for covering, legs and can-fly; a Penguin frame inherits them and overrides can-fly. Slots can hold default values ("birds fly, unless told otherwise"), links to other frames, or even small procedures that compute a value when it is asked for.

Defaults are what make frames practical, and also what makes them tricky. Real categories are full of exceptions, and a representation that cannot express "usually, but not always" ends up either wrong or enormous.

Try it

Here is the network from Figure 1 as frames, with a lookup that walks up the is-a chain and stops at the first value it finds:

frames.pyruns with python3 (standard library)
# Frames: each concept has slots and inherits its parent's ("is_a").
FRAMES = {
    "Animal":  {"is_a": None,     "alive": True},
    "Bird":    {"is_a": "Animal", "covering": "feathers", "can_fly": True,
                "legs": 2},
    "Penguin": {"is_a": "Bird",   "can_fly": False, "habitat": "coasts"},
    "Robin":   {"is_a": "Bird",   "habitat": "gardens"},
    "Tweety":  {"is_a": "Penguin"},
    "Rocky":   {"is_a": "Robin",  "legs": 1},   # an injured robin
}

def lookup(thing, slot):
    """Walk up the is_a chain; the most specific value wins."""
    path = []
    while thing is not None:
        path.append(thing)
        if slot in FRAMES[thing]:
            return FRAMES[thing][slot], " -> ".join(path)
        thing = FRAMES[thing]["is_a"]
    return None, " -> ".join(path)

for thing, slot in [("Tweety", "can_fly"), ("Rocky", "can_fly"),
                    ("Rocky", "legs"), ("Tweety", "covering"),
                    ("Tweety", "alive"), ("Tweety", "colour")]:
    value, path = lookup(thing, slot)
    where = f"via {path}" if value is not None else f"unknown ({path})"
    print(f"{thing + '.' + slot:15} = {str(value):9} {where}")

Output

Tweety.can_fly  = False     via Tweety -> Penguin
Rocky.can_fly   = True      via Rocky -> Robin -> Bird
Rocky.legs      = 1         via Rocky
Tweety.covering = feathers  via Tweety -> Penguin -> Bird
Tweety.alive    = True      via Tweety -> Penguin -> Bird -> Animal
Tweety.colour   = None      unknown (Tweety -> Penguin -> Bird -> Animal)

Tweety cannot fly because Penguin overrides the Bird default one level up. Rocky, an injured robin, has its own legs slot, so the specific value 1 beats the general value 2. Nobody wrote down that Tweety is alive; it is inherited from Animal, three levels up. And asking for a slot that nobody filled in returns "unknown", which is an honest answer, not "false".

Now sort some knowledge by the form that suits it best:

Which representation fits each piece of knowledge best?

Show answers
  • Order 1182 was shipped on 3 March: Fact. A single statement about specific things: one relation, one row.
  • If a payment fails three times, lock the account: Rule. It derives an action from conditions and applies to every account.
  • Laptops and phones are electronics; electronics have a two-year warranty: Hierarchy with inheritance. The warranty is stated once on the category and inherited by everything under it.
  • Berlin is in Germany: Fact. A single relation between two named things.
  • Anyone who manages a manager is a senior manager: Rule. A general if-then pattern over people and relations, chained like grandparent_of.
  • All mammals are warm-blooded, except a few such as the naked mole-rat: Hierarchy with inheritance. A default on a category with an exception that overrides it lower down, exactly like Penguin and can-fly.

Going deeper

What makes a representation good

A representation is good when it makes the questions you care about easy to answer and the knowledge easy to maintain. Those pull in different directions:

  • Expressiveness: can it say what you need? Plain facts cannot say "every", rules cannot easily say "usually", and none of these can say "probably 80 percent".
  • Efficiency of inference: the more expressive the language, the more expensive reasoning becomes. Full first-order logic is so expressive that some questions in it can never be answered by any algorithm; that is why practical systems restrict themselves.
  • Maintainability: knowledge changes. A change should touch one place. Inheritance helps; thousands of interacting rules hurt, as the expert systems of the 1980s discovered ( Expert systems and rule engines ).

The problems that never fully went away

Three classic difficulties explain why hand-written knowledge struggled to scale. The qualification problem: real rules have endless exceptions ("a car starts when you turn the key, unless the battery is flat, the fuel is out, the key is wrong..."). The frame problem: when an action happens, stating everything that did not change is surprisingly hard. And the knowledge acquisition bottleneck: experts know far more than they can put into words, so typing knowledge in is slow and incomplete.

Machine learning sidesteps the bottleneck by learning patterns from data, at the cost of knowledge that is implicit and hard to inspect. Much of modern practice combines the two: learned models for perception and language, explicit structures for facts that must be exact, current and auditable. Knowledge graphs and ontologies shows the modern form of semantic networks, knowledge graphs.

Trade-offs

OptionWins whenLoses when
Facts (tables, triples) Large amounts of exact, specific data that must be queried quickly Cannot express general patterns or exceptions
Rules General, explicit, auditable decision logic Interactions between many rules become hard to predict and maintain
Frames and semantic networks Category hierarchies with defaults and inheritance Exceptions and multiple inheritance get messy; meaning of links can be vague
Learned representations (embeddings, networks) Knowledge too fuzzy or vast to write down, such as language and images Hard to inspect, edit or guarantee; can be confidently wrong

Common mistakes

  • Treating "not found" as "false". A missing fact usually means unknown, and confusing the two causes wrong conclusions.
  • Copying a property onto every object instead of stating it once on the category. Every copy is a place to forget an update.
  • Using vague link labels ("related to") in a semantic network. A link a program cannot interpret is a link it cannot reason with.
  • Assuming explicit knowledge is obsolete. Exact, current and auditable facts still belong in explicit structures, even next to a language model.

In the wild

Where you will see this: database schemas and the entity-relationship diagrams behind them are knowledge representation at industrial scale. Search engines and digital assistants answer factual questions from knowledge graphs, the direct descendants of semantic networks. Medical coding systems and product catalogues organise millions of concepts into is-a hierarchies so that a query for "electronics" finds every laptop. And when a language-model agent is handed a list of tools with typed inputs and descriptions, that list is a frame-like representation of what the agent can do.

Check yourself

  1. What does a rule add that a list of facts does not?

    Show answer

    B. A general pattern that derives new facts, including for data added later One rule such as grandparent_of covers every case that matches its conditions, now and in the future.

  2. In Figure 1, why does the system answer that Tweety cannot fly?

    Show answer

    B. Penguin overrides the Bird default, and lookup takes the most specific value Lookup walks up from Tweety and stops at Penguin's can-fly slot before reaching Bird's default.

  3. A frame lookup for Tweety's colour finds nothing. What should the system conclude?

    Show answer

    B. Tweety's colour is unknown Absence of a stored value means the system does not know, not that the answer is no.

  4. Why did hand-written knowledge bases struggle to scale?

    Show answer

    B. Real rules have endless exceptions and experts cannot write down all they know The qualification problem and the knowledge acquisition bottleneck made large, correct knowledge bases slow and costly to build and maintain.

Recap

  • Knowledge representation stores what a system knows in a form it can reason with, not just look up.
  • Facts state specific relations; rules derive new facts from patterns.
  • Semantic networks and frames organise concepts into is-a hierarchies with inherited properties and defaults.
  • Good representations balance expressiveness, efficient inference and maintainability.
  • Explicit knowledge lives on in knowledge graphs, rule engines, schemas and agent tool descriptions.

Get new lessons by email

Get new posts on backend and AI internals. No spam, unsubscribe anytime.

Your email is only used to send new posts. Privacy