Knowledge & Reasoning10 min read

Knowledge Representation

How machines store facts about the world
scope:Core Conceptdifficulty:Beginner

The Mind Map of a Machine

Close your eyes and think about "Paris." Instantly, your brain lights up with connections: France, Eiffel Tower, croissants, City of Lights, romance, the Seine river...

Your brain doesn't store "Paris" as an isolated word. It stores it as a web of connections. Paris IS-A city. Paris IS-IN France. Paris HAS-A Eiffel Tower. Paris IS-KNOWN-FOR romance.

This is knowledge representation β€” figuring out how to store facts and relationships so a computer can reason about the world the way you do. Without it, AI is just crunching numbers. With it, AI can understand concepts.

Why This Matters

Imagine asking an AI: "If I'm in the capital of France, which famous tower can I visit?"

To answer this, the AI needs to know: Paris is the capital of France, and the Eiffel Tower is in Paris. It needs structured knowledge β€” not just a bag of words, but facts organized in a way that supports reasoning.

Four Ways to Represent Knowledge

Over the decades, AI researchers have developed several approaches:

1. Semantic Networks

A graph where nodes are concepts and edges are relationships. Like a mind map: Dog β†’ IS-A β†’ Animal, Dog β†’ HAS β†’ Fur. Simple, visual, and intuitive.

2. Frames

Like filling out a form for each concept. A "Restaurant" frame might have slots for: name, cuisine, location, price_range. Think of it as an early version of object-oriented programming, but for knowledge.

3. Ontologies

Formal, hierarchical systems. "Animal" is a superclass. "Mammal" is a subclass of Animal. "Dog" is a subclass of Mammal. They inherit properties down the chain β€” if mammals are warm-blooded, then dogs are warm-blooded too.

4. Knowledge Graphs

The modern standard. Google's Knowledge Graph connects billions of facts as triples: (subject, predicate, object). (Einstein, born-in, Ulm), (Einstein, field, Physics). When you Google a celebrity and see that info panel on the right? That's a knowledge graph at work.

Building a Simple Knowledge Graph

class KnowledgeGraph:
def __init__(self):
self.triples = [] # (subject, predicate, object)
def add(self, subject, predicate, obj):
self.triples.append((subject, predicate, obj))
def query(self, subject=None, predicate=None, obj=None):
"""Find triples matching a pattern (None = wildcard)."""
results = []
for s, p, o in self.triples:
if (subject is None or s == subject) and \
(predicate is None or p == predicate) and \
(obj is None or o == obj):
results.append((s, p, o))
return results
# Build our knowledge graph
kg = KnowledgeGraph()
kg.add("Paris", "is-a", "City")
kg.add("Paris", "is-in", "France")
kg.add("Paris", "capital-of", "France")
kg.add("Eiffel Tower", "is-in", "Paris")
kg.add("Eiffel Tower", "is-a", "Landmark")
kg.add("France", "is-a", "Country")
kg.add("France", "is-in", "Europe")
# Ask questions
print("What's in Paris?")
for s, p, o in kg.query(predicate="is-in", obj="Paris"):
print(f" {s}")
print("\nFacts about France:")
for s, p, o in kg.query(subject="France"):
print(f" France {p} {o}")
print("\nWhat is Paris?")
for s, p, o in kg.query(subject="Paris", predicate="is-a"):
print(f" Paris is a {o}")
Output
What's in Paris?
  Eiffel Tower

Facts about France:
  France is-a Country
  France is-in Europe

What is Paris?
  Paris is a City
Note: Google's Knowledge Graph contains over 500 billion facts about 5 billion entities. When you search for "Barack Obama" and see his birthday, family, and career at a glance β€” that's knowledge representation in action. The entire info panel is generated from structured triples, not scraped from web pages.

The Challenge: Common Sense

Humans know millions of "obvious" facts that are surprisingly hard to encode: water is wet, fire is hot, you can't fit an elephant in a suitcase. This is called the common sense problem, and it remains one of the biggest challenges in AI.

The CYC project, started in 1984, attempted to manually encode all common sense knowledge. Decades later, it has millions of rules β€” and still doesn't cover everything a five-year-old knows intuitively.

Modern AI systems like large language models take a different approach: they learn implicit knowledge from vast amounts of text, but they still struggle with basic physical and social reasoning that comes naturally to humans.

Quick check

What is a 'triple' in a knowledge graph?
Challenge

Continue reading