---
id: wiki-2026-0508-knowledge-representation-in-ai
title: Knowledge Representation in AI
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [knowledge representation, KR, ontology, knowledge graph, semantic web, RDF, OWL]
duplicate_of: none
source_trust_level: A
confidence_score: 0.92
verification_status: applied
tags: [ai, knowledge-representation, ontology, knowledge-graph, semantic-web, rdf]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: Python / RDF / SPARQL
  framework: RDFLib / Neo4j / Cypher
---

# Knowledge Representation in AI

## 매 한 줄
> **"매 facts + 매 rules 의 의 의 machine-processable 의 represent"**. 매 ontology, knowledge graph, semantic web. 매 modern: 매 LLM 의 implicit KR + 매 KG-RAG hybrid.

## 매 핵심

### 매 paradigms
- **Logic**: FOL, Description Logic.
- **Frames** (Minsky).
- **Semantic networks**.
- **Production rules** (CLIPS).
- **Ontologies** (OWL).
- **Knowledge graphs** (RDF, property graph).
- **LLM** (implicit / parametric).

### 매 modern combo
- **KG + LLM**: 매 RAG with structure.
- **Neuro-symbolic**: 매 symbolic + neural.
- **GraphRAG** (Microsoft 2024).

### 매 응용
1. Search (Google KG).
2. Recommendation.
3. Drug discovery.
4. Compliance.
5. RAG with structure.

## 💻 패턴

### RDF triple (RDFLib)
```python
from rdflib import Graph, Literal, URIRef, Namespace

g = Graph()
EX = Namespace('http://example.com/')
g.add((EX.alice, EX.knows, EX.bob))
g.add((EX.alice, EX.age, Literal(30)))
g.serialize(format='turtle')
```

### SPARQL query
```sparql
PREFIX ex: <http://example.com/>
SELECT ?person ?friend
WHERE { ?person ex:knows ?friend . FILTER(?person = ex:alice) }
```

### Property graph (Neo4j)
```cypher
CREATE (alice:Person {name: 'Alice', age: 30})
CREATE (bob:Person {name: 'Bob'})
CREATE (alice)-[:KNOWS {since: 2020}]->(bob);

MATCH (a:Person)-[:KNOWS]->(b:Person)
WHERE a.name = 'Alice'
RETURN b.name;
```

### Ontology (OWL)
```turtle
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <http://example.com/> .

:Person a owl:Class .
:Employee a owl:Class ; rdfs:subClassOf :Person .
:hasManager a owl:ObjectProperty ; rdfs:domain :Employee ; rdfs:range :Employee .
```

### Description Logic (rules)
```
Person ⊓ ∃hasChild.Person ⊑ Parent
∀x. Parent(x) → Person(x) ∧ ∃y. hasChild(x, y) ∧ Person(y)
```

### Reasoning (Pellet, HermiT)
```python
from owlready2 import get_ontology, sync_reasoner_pellet
onto = get_ontology('http://example.com/onto.owl').load()
with onto:
    sync_reasoner_pellet()  # 매 infer subclasses, instances
```

### Triple store query (Python + RDFLib)
```python
results = g.query("""
    SELECT ?name WHERE { ?person ex:name ?name . ?person ex:age ?age . FILTER(?age > 25) }
""")
for row in results: print(row.name)
```

### Build KG from text (LLM-aided)
```python
def text_to_triples(text, llm):
    prompt = f"""Extract (subject, predicate, object) triples.

Text: {text}

Output JSON list of triples."""
    return json.loads(llm.generate(prompt))
```

### GraphRAG (Microsoft 2024)
```python
def graphrag_pipeline(documents, llm):
    """매 simplified."""
    # 매 1. Extract entities + relations
    triples = []
    for doc in documents:
        triples.extend(text_to_triples(doc, llm))
    
    # 매 2. Build graph
    G = build_graph(triples)
    
    # 매 3. Cluster (community detection)
    communities = G.community_detection()
    
    # 매 4. Summarize each community
    summaries = {c: llm.summarize(community_text(c)) for c in communities}
    
    # 매 5. Query → relevant communities → LLM
    return summaries
```

### Neuro-symbolic (combine)
```python
def neuro_symbolic_classify(image, kg, classifier):
    visual_features = classifier.encode(image)
    visual_pred = classifier.predict(visual_features)
    
    # 매 KG constraint
    if not kg.is_consistent_with(visual_pred):
        return kg.most_consistent_alternative(visual_pred)
    return visual_pred
```

### Embedding-based KG (TransE)
```python
import torch.nn as nn
class TransE(nn.Module):
    def __init__(self, n_entities, n_relations, dim):
        super().__init__()
        self.entity_emb = nn.Embedding(n_entities, dim)
        self.relation_emb = nn.Embedding(n_relations, dim)
    
    def score(self, h, r, t):
        return -(self.entity_emb(h) + self.relation_emb(r) - self.entity_emb(t)).norm(dim=-1)
```

### Cypher integration with LLM
```python
def llm_to_cypher(question, schema, llm):
    prompt = f"""Convert natural language to Cypher.

Schema: {schema}
Question: {question}

Cypher query:"""
    return llm.generate(prompt)
```

### Schema.org (web KR)
```html
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Person",
  "name": "Alice",
  "knows": [{"@type": "Person", "name": "Bob"}]
}
</script>
```

### Maintain KG (incremental update)
```python
class KG:
    def add_triple(self, s, p, o, source, confidence):
        # 매 store with provenance
        self.graph.add((s, p, o, source, confidence, datetime.now()))
    
    def query_with_provenance(self, pattern):
        return [(triple, source, conf) for triple, source, conf, _ in self.graph.match(pattern)]
```

## 매 결정 기준
| 상황 | Approach |
|---|---|
| Structured facts | Knowledge Graph |
| Logical inference | Description Logic + reasoner |
| Web data | Schema.org + RDF |
| Visual reasoning | Neuro-symbolic |
| Modern QA | GraphRAG (KG + LLM) |
| Recommendation | KG + embedding (TransE) |

**기본값**: 매 modern = LLM + KG hybrid (GraphRAG-style) + 매 schema.org for web data + 매 Neo4j for prod KG + 매 provenance tracking.

## 🔗 Graph
- 부모: [[AI]] · [[Symbolic-AI]]
- 변형: [[Ontology]] · [[Knowledge-Graph]] · [[GraphRAG]]
- 응용: [[Semantic-Web]] · [[RAG]] · [[Recommender-Systems]]
- Adjacent: [[GNN]] · [[Foundation-Models]] · [[Logic-Programming]]

## 🤖 LLM 활용
**언제**: 매 structured QA. 매 enterprise data. 매 recommendation.
**언제 X**: 매 free-form text only.

## ❌ 안티패턴
- **Pure symbolic in LLM era**: 매 hybrid 의 win.
- **No provenance**: 매 trust X.
- **Stale KG**: 매 update 의 critical.
- **Over-engineer ontology**: 매 yagni.

## 🧪 검증 / 중복
- Verified (Brachman & Levesque KR textbook, Microsoft GraphRAG 2024).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — paradigms + 매 RDF / Neo4j / OWL / GraphRAG / TransE code |
