Knowledge Representation In AI
Knowledge representation is how an AI system stores what it knows about the world, in a form it can actually use to reason and make decisions.
What Is Knowledge Representation?
Knowledge representation (KR) is the part of AI concerned with how facts, rules, and relationships are stored so a program can use them to answer questions, make decisions, or draw new conclusions. It's the bridge between raw information and reasoning.
Why AI Needs to Represent Knowledge
A computer doesn't understand the world the way a person does — it only has whatever facts and rules are given to it in a structured form. Without a good representation, an AI system can't connect related facts, reuse what it already knows for a new situation, or explain why it reached an answer. Good knowledge representation is what turns raw data into something the system can actually reason with.
Types of Knowledge
AI systems typically work with a few different kinds of knowledge, often combined.
Declarative Knowledge
Facts about the world — statements that are simply true or false, like "Paris is the capital of France."
Procedural Knowledge
Knowing how to do something, like the steps for solving an equation or sorting a list.
Structural Knowledge
How pieces of knowledge relate to each other, such as "a car has wheels" or "a bird is a kind of animal."
Heuristic Knowledge
Rules of thumb built from experience, like "check the most likely cause first." It's not guaranteed to be correct, but it often speeds up reasoning.
Representation Approaches Overview
There are several common ways to structure knowledge so an AI system can use it.
Logical Representation
Facts and rules written in formal logic, such as "IF X is a bird AND X is not a penguin THEN X can fly." This is precise and lets a system prove new facts from old ones.
Semantic Networks
A graph of nodes (things) connected by labeled links (relationships), like Sparrow → is-a → Bird → is-a → Animal. A system can follow the links to inherit properties — a Sparrow "inherits" whatever is true of Bird and Animal.
Frames
Record-like structures with named slots for properties, similar to an object in programming. A Bird frame might have slots for can_fly, has_feathers, and diet, each filled in with a value.
Production Rules
Simple IF condition THEN action rules, often used together in a rule-based system. When a rule's condition matches what's known, its action fires, which can add new facts or trigger a step.
Example: A Small Semantic Network
Here's a semantic network in Python. Each bird "inherits" properties from Bird and Animal by following is-a links, unless it has its own property that overrides the inherited one:
facts = [
("Sparrow", "is-a", "Bird"),
("Bird", "is-a", "Animal"),
("Bird", "has-property", "can-fly"),
("Bird", "has-property", "has-feathers"),
("Animal", "has-property", "can-move"),
("Penguin", "is-a", "Bird"),
("Penguin", "has-property", "cannot-fly"), # overrides the general rule
]
def get_properties(entity):
props = set()
current = entity
visited = set()
while current and current not in visited:
visited.add(current)
for subj, rel, obj in facts:
if subj == current and rel == "has-property":
props.add(obj)
parent = next((obj for subj, rel, obj in facts if subj == current and rel == "is-a"), None)
current = parent
return props
for entity in ["Sparrow", "Penguin"]:
print(f"{entity}: {sorted(get_properties(entity))}")Output
Sparrow: ['can-fly', 'can-move', 'has-feathers']
Penguin: ['can-fly', 'can-move', 'cannot-fly', 'has-feathers']Explanation:
Sparrow inherits correctly from Bird and Animal. But Penguin ends up with both can-fly and cannot-fly — simple inheritance doesn't know the specific fact should override the general one. This is a well-known limitation of basic semantic networks, and it's why real KR systems add extra rules for handling exceptions.
Quick Summary
| Approach | Structure | Good For |
|---|---|---|
| Logical Representation | Formal if-then statements | Proving new facts from known ones |
| Semantic Networks | Nodes linked by relationships | Inheritance and showing connections |
| Frames | Slots and values, like a record | Grouping related properties together |
| Production Rules | IF condition THEN action | Rule-based reasoning systems |