docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
---
|
||||
id: wiki-2026-0508-rule-based-systems
|
||||
title: Rule-based Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Rule-based AI, Expert Systems, Production Systems]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [rule-based, expert-systems, symbolic-ai, neuro-symbolic, knowledge]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: CLIPS / Drools / experta
|
||||
---
|
||||
|
||||
# Rule-based Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 IF condition THEN action 의 deterministic, auditable knowledge encoding"**. 매 1970s expert systems (MYCIN, DENDRAL, R1/XCON) 의 황금기 → 매 ML winter 후 무대 후퇴 → 매 2024+ neuro-symbolic 부활 (LLM + symbolic constraints, 매 hallucination 통제). 매 finance, healthcare, compliance, fraud 등 매 explainability 가 비협상 의 도메인 의 backbone.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Architecture
|
||||
- **Working Memory**: facts (current state).
|
||||
- **Rule Base**: production rules (LHS → RHS).
|
||||
- **Inference Engine**: forward chaining (data-driven) / backward chaining (goal-driven).
|
||||
- **Conflict resolution**: salience, recency, specificity.
|
||||
- **Rete algorithm**: efficient pattern matching (Forgy, 1982).
|
||||
|
||||
### 매 Forms
|
||||
- **Production rules**: CLIPS, Drools, Jess.
|
||||
- **Decision tables**: tabular form, easy SME edit.
|
||||
- **Decision trees**: hierarchical, ML-extractable.
|
||||
- **Logic programming**: Prolog, Datalog, ASP.
|
||||
- **Business Rule Engines**: Camunda DMN, IBM ODM.
|
||||
|
||||
### 매 응용
|
||||
1. Insurance underwriting / claims adjudication.
|
||||
2. Loan approval, AML/KYC, sanctions screening.
|
||||
3. Clinical decision support (drug interactions).
|
||||
4. Tax/compliance engines.
|
||||
5. Game AI (NPCs, behavior trees as rule variants).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### CLIPS-style rule (experta)
|
||||
```python
|
||||
from experta import KnowledgeEngine, Rule, Fact, Field
|
||||
|
||||
class Patient(Fact):
|
||||
fever = Field(bool, mandatory=True)
|
||||
cough = Field(bool, mandatory=True)
|
||||
duration_days = Field(int)
|
||||
|
||||
class TriageEngine(KnowledgeEngine):
|
||||
@Rule(Patient(fever=True, cough=True, duration_days=lambda d: d >= 7))
|
||||
def likely_pneumonia(self):
|
||||
self.declare(Fact(diagnosis="pneumonia_suspect", urgent=True))
|
||||
|
||||
@Rule(Patient(fever=True, duration_days=lambda d: d < 3))
|
||||
def viral(self):
|
||||
self.declare(Fact(diagnosis="viral_likely"))
|
||||
|
||||
eng = TriageEngine()
|
||||
eng.reset()
|
||||
eng.declare(Patient(fever=True, cough=True, duration_days=8))
|
||||
eng.run()
|
||||
```
|
||||
|
||||
### Drools rule (DRL syntax)
|
||||
```java
|
||||
rule "High value claim escalate"
|
||||
when
|
||||
$c: Claim(amount > 50000, status == "submitted")
|
||||
$p: Policy(id == $c.policyId, riskTier == "HIGH")
|
||||
then
|
||||
$c.setStatus("escalated_review");
|
||||
update($c);
|
||||
insert(new Alert("manual_review", $c.getId()));
|
||||
end
|
||||
```
|
||||
|
||||
### DMN decision table (Camunda)
|
||||
```xml
|
||||
<decision id="discount" name="Customer Discount">
|
||||
<decisionTable hitPolicy="UNIQUE">
|
||||
<input label="Years"><inputExpression typeRef="number">years</inputExpression></input>
|
||||
<input label="Tier"><inputExpression typeRef="string">tier</inputExpression></input>
|
||||
<output label="Discount" typeRef="number"/>
|
||||
<rule><inputEntry><1</inputEntry><inputEntry>"BRONZE"</inputEntry><outputEntry>0</outputEntry></rule>
|
||||
<rule><inputEntry>[1..5]</inputEntry><inputEntry>"SILVER"</inputEntry><outputEntry>0.05</outputEntry></rule>
|
||||
<rule><inputEntry>>5</inputEntry><inputEntry>"GOLD"</inputEntry><outputEntry>0.15</outputEntry></rule>
|
||||
</decisionTable>
|
||||
</decision>
|
||||
```
|
||||
|
||||
### Prolog (backward chaining)
|
||||
```prolog
|
||||
ancestor(X, Y) :- parent(X, Y).
|
||||
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
|
||||
|
||||
parent(tom, bob).
|
||||
parent(bob, alice).
|
||||
% ?- ancestor(tom, alice). → true
|
||||
```
|
||||
|
||||
### Neuro-symbolic — LLM proposes, rules verify (2026)
|
||||
```python
|
||||
import anthropic, json
|
||||
from rule_engine import compile_rules, evaluate
|
||||
|
||||
client = anthropic.Anthropic()
|
||||
COMPLIANCE_RULES = compile_rules([
|
||||
"transaction.amount < 10000 OR transaction.kyc_verified == True",
|
||||
"transaction.country NOT IN sanctions_list",
|
||||
])
|
||||
|
||||
resp = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=512,
|
||||
messages=[{"role": "user", "content": f"Extract transaction: {raw_text}"}],
|
||||
)
|
||||
tx = json.loads(resp.content[0].text)
|
||||
violations = evaluate(COMPLIANCE_RULES, tx)
|
||||
if violations:
|
||||
block(tx, reasons=violations) # rules give auditable why
|
||||
```
|
||||
|
||||
### Forward-chaining engine in plain Python
|
||||
```python
|
||||
def forward_chain(rules, facts, max_iter=100):
|
||||
facts = set(facts)
|
||||
for _ in range(max_iter):
|
||||
new = set()
|
||||
for premises, conclusion in rules:
|
||||
if all(p in facts for p in premises) and conclusion not in facts:
|
||||
new.add(conclusion)
|
||||
if not new:
|
||||
break
|
||||
facts |= new
|
||||
return facts
|
||||
|
||||
rules = [
|
||||
({"has_wings", "lays_eggs"}, "is_bird"),
|
||||
({"is_bird", "swims"}, "is_penguin"),
|
||||
]
|
||||
print(forward_chain(rules, {"has_wings", "lays_eggs", "swims"}))
|
||||
# {'has_wings', 'lays_eggs', 'swims', 'is_bird', 'is_penguin'}
|
||||
```
|
||||
|
||||
### Behavior tree (game AI rule variant)
|
||||
```python
|
||||
from py_trees import behaviours, composites, common
|
||||
|
||||
root = composites.Selector("Root", memory=False)
|
||||
attack = composites.Sequence("Attack", memory=True, children=[
|
||||
behaviours.Condition("EnemyVisible", "EnemyVisible", common.Status.SUCCESS),
|
||||
behaviours.Dummy("FireWeapon"),
|
||||
])
|
||||
patrol = behaviours.Dummy("Patrol")
|
||||
root.add_children([attack, patrol])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Auditable, regulated | Rule engine (Drools, DMN) |
|
||||
| Pattern recognition | ML / DL |
|
||||
| Hybrid (extract + decide) | LLM + rule verifier (neuro-symbolic) |
|
||||
| Few thousand cases, frequent change | Decision table |
|
||||
| Complex ontology | Prolog / Datalog / ASP |
|
||||
|
||||
**기본값**: Drools/DMN for business rules, LLM-extract + rule-verify for unstructured input.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Symbolic-AI]] · [[Knowledge-Representation]]
|
||||
- 변형: [[Expert-Systems]]
|
||||
- Adjacent: [[Neural-Symbolic-Integration|Neuro-Symbolic-AI]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: rule extraction from policy docs, NL-to-DRL translation, rule conflict detection, explanation generation.
|
||||
**언제 X**: as the rule engine itself in regulated domains — use deterministic engine, let LLM only structure the input.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Rule explosion**: 5000+ rules without modules → unmaintainable; refactor to decision tables.
|
||||
- **Conflicting rules silent**: no conflict detection → undefined behavior.
|
||||
- **No version control**: rules edited live in production BRMS UI without git.
|
||||
- **LLM as judge for compliance**: hallucination in regulated path; LLM must propose, rules must verify.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Russell & Norvig AIMA, CLIPS docs, Drools manual, OMG DMN spec).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — production rules, Rete, neuro-symbolic 2026 |
|
||||
Reference in New Issue
Block a user