Knowledge Representation (KR): Formalization of information with explicit rules, relationships, and constraints enabling computational reasoning and inference.
Key distinction: Not just storing facts, but encoding the logic to derive new facts automatically.
Example: "Mary is 30" + "All persons over 18 are adults" → infer "Mary is an adult"
Knowledge Engineering Value Proposition
Automated Inference: Derive new facts without explicit programming.
Semantic Search: Find information by meaning, not just keywords.
Data Validation: Enforce complex business rules beyond structural checks.
Decision Support: Provide explicit reasoning steps for decisions.
System Integration: Shared ontology for disparate systems.
Explainable AI: Auditable reasoning chains for trust and compliance.
Six Technical Challenges with SQL for KR
Composability: Building reusable rule components and layered knowledge structures is cumbersome.
Procedural vs. Declarative: Complex rules often require stored procedures or triggers, scattering logic.
Integrity Constraints vs. Business Rules: Complex domain rules don't fit simple CHECK constraints.
Burdensome DDL: Schema changes in large RDBMS slow agile knowledge evolution.
Schema-on-write rigidity: Must define structure before data, clashing with exploratory knowledge discovery.
NULL/3-valued logic: Deviates from standard two-valued logic foundational to KR.
The Three-Layer Problem
Conceptual Model: Domain meaning and business rules, technology-independent.
Logical Model: Maps to a data model (relational, graph, object), abstracts from storage.
Physical Model: Actual storage, indexing, performance optimizations.
The Problem: Traditional SQL design forces blending these layers. Choosing VARCHAR size (physical) impacts how "name" (conceptual) is perceived. KE requires clean separation with loosely coupled mappings.
CWA vs. OWA: A Fundamental Divide
Closed World Assumption (CWA): SQL's default. If a fact isn't in the database, it's false.
Open World Assumption (OWA): Common in KR (e.g., OWL). If a fact isn't known, it's unknown (not false).
Impact: CWA simplifies querying but struggles with incomplete knowledge. OWA is better suited for dynamic, real-world knowledge. SQL can simulate OWA with LEFT JOIN or NOT EXISTS, but it's not native.
SQL ≠ The Relational Model
Relational Model (Codd, Date, Darwen): Powerful logical framework with rich declarative integrity constraints.
SQL implementations: Deviate from the formal model in ways that impact KR.
Key insight: Criticisms of SQL don't necessarily apply to the formal Relational Model itself.
The formal RM provides robust knowledge representation through declarative constraints. A "relvar" is a predicate stating truth about the world.
Date & Darwen: SQL's Deviations from RM
NULL values: Three-valued logic (true/false/unknown) complicates reasoning, deviates from two-valued logic in KR.
Lack of true assertions: Weak support for complex, cross-table integrity constraints. RM allows arbitrary assertions.
Duplicate rows/tuple ordering: RM uses mathematical sets (no duplicates, no order). SQL allows both, undermining logical purity.
Imperfect type system: Less sophisticated than needed for rich conceptual types and hierarchies.
The Composability Challenge
Date & Darwen: SQL lacks true closure—SELECT doesn't always produce relational results (duplicates, NULLs).
LINQ/Rx perspective: Impedance mismatch between SQL strings and host language type systems hinders modular composition.
Result: Building layered knowledge structures from reusable rule components is harder than in Datalog or relational calculus.
When SQL's declarative features fall short, developers resort to procedural code, scattering logical definitions.
Use SQL Where It Shines
Transactional integrity, joins, indexing, and execution plans.
Mature governance, operations, and performance tooling.
Excellent substrate for views, materializations, and access control.
Robust data storage and retrieval of foundational facts.
Strategy: Use SQL for what it does best, not as the sole KR solution.
SQL is Evolving (Stonebraker: "What Goes Around Comes Around")