Liking cljdoc? Tell your friends :D

← Documentation Index

OpenCog Hyperon Architecture

This document provides a comprehensive overview of OpenCog Hyperon, the cognitive architecture that underlies MeTTa and serves as the foundation for MeTTaIL's semantic type checking capabilities.

Source: Goertzel et al. "OpenCog Hyperon: A Framework for AGI at the Human Level and Beyond" (2023)


Table of Contents

  1. Introduction
  2. Architectural Overview
  3. Atomspace: The Metagraph Knowledge Store
  4. Four Atom Meta-Types
  5. Two-Layer Type System
  6. Pattern Matching as Core Operation
  7. Gradual Typing and Paraconsistent Logic
  8. Distributed Atomspace
  9. Cognitive Synergy
  10. Relevance to MeTTaIL

Introduction

OpenCog Hyperon is an open-source framework designed for Artificial General Intelligence (AGI). Unlike narrow AI systems optimized for specific tasks, Hyperon provides a flexible infrastructure where multiple AI paradigms can cooperate and share knowledge through a unified representation.

Design Goals

  1. Cognitive Flexibility: Support multiple AI approaches simultaneously
  2. Knowledge Integration: Unified representation across paradigms
  3. Scalability: Distributed operation across compute clusters
  4. Introspection: Self-modifying, self-improving capabilities
  5. Theoretical Foundation: Grounded in formal semantics

Architectural Overview

The Hyperon architecture consists of layered components:

┌─────────────────────────────────────────────────────────────────┐
│                         AI Agents                                │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐            │
│  │  GOFAI  │  │  Neural │  │  Evol.  │  │ Prob.   │            │
│  │  Logic  │  │  Nets   │  │  Algo.  │  │ Graphs  │            │
│  └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘            │
│       │            │            │            │                   │
│       └────────────┴────────────┴────────────┘                  │
│                         │                                        │
│              ┌──────────▼──────────┐                            │
│              │       MeTTa         │  ← Programming Language    │
│              │  (Meta Type Talk)   │                            │
│              └──────────┬──────────┘                            │
│                         │                                        │
│              ┌──────────▼──────────┐                            │
│              │     Atomspace       │  ← Metagraph Knowledge     │
│              │   (Atomese Core)    │     Store                  │
│              └──────────┬──────────┘                            │
│                         │                                        │
│              ┌──────────▼──────────┐                            │
│              │  Distributed AS     │  ← Scalable Storage        │
│              │       (DAS)         │                            │
│              └──────────────────────┘                            │
└─────────────────────────────────────────────────────────────────┘

Layer Descriptions

LayerComponentPurpose
TopAI AgentsDomain-specific algorithms
MiddleMeTTaProgramming language interface
CoreAtomspaceKnowledge representation & manipulation
BaseDASDistributed storage & retrieval

Atomspace: The Metagraph Knowledge Store

The Atomspace is a metagraph data structure that stores all knowledge in Hyperon. Unlike traditional graphs, metagraphs allow edges to connect to other edges, enabling higher-order relationships.

Definition: Metagraph

A metagraph M = (V, E) where:

  • V is a set of vertices (Atoms)
  • $E \subseteq P(V \cup E) \times P(V \cup E)$ is a set of hyperedges that can connect vertices or other edges

Key Properties

  1. Hyperedges: Edges can connect arbitrary sets of nodes or edges
  2. Typed Nodes: Every atom has an associated type
  3. Attention Values: Atoms carry importance/relevance weights
  4. Truth Values: Probabilistic confidence annotations
  5. Grounding: External function/data attachment

Example Structure

Atomspace:
  (Inheritance "cat" "animal")
  (Evaluation "has-property"
    (List "cat" "furry"))
  (TypedAtom
    (: "add" (-> Number Number Number)))

Four Atom Meta-Types

MeTTa uses exactly four fundamental atom meta-types. Every atom in the system is classified as one of these:

1. Symbol

A named constant representing an identifier or value.

; Symbols
foo          ; Named identifier
+            ; Operator symbol
Type         ; Type name
"string"     ; String literal (also a symbol)

Properties:

  • Immutable
  • Hashable for efficient lookup
  • Used for constructors, operators, type names

2. Variable

A placeholder for pattern matching and unification.

; Variables (prefixed with $)
$x           ; Simple variable
$pattern     ; Named pattern variable
$_           ; Anonymous/wildcard variable

Properties:

  • Bound during pattern matching
  • Scope determined by enclosing expression
  • Support unification with constraints

3. Expression

An ordered list of atoms (can contain any meta-type).

; Expressions (parenthesized lists)
(+ 1 2)                    ; Function application
(: x Int)                  ; Type annotation
(= (f $x) (g $x $x))       ; Equality declaration
(if $cond $then $else)     ; Control flow

Properties:

  • Ordered (position matters)
  • Heterogeneous (mixed types allowed)
  • Recursive (expressions contain expressions)

4. Grounded

Foreign data or functions from the host language (Rust, Python, etc.).

; Grounded atoms (opaque to MeTTa)
<Rust::HashMap>            ; External data structure
<Python::numpy.array>      ; Foreign array
<fn:add-integers>          ; External function

Properties:

  • Opaque to MeTTa's pattern matcher
  • Evaluated by host language
  • Enable external system integration

Meta-Type Hierarchy

                    Atom
                     │
       ┌─────────────┼─────────────┐
       │             │             │
       ▼             ▼             ▼
   ┌───────┐   ┌───────────┐  ┌──────────┐
   │Symbol │   │Expression │  │ Grounded │
   └───────┘   └───────────┘  └──────────┘
       │
       ▼
   ┌───────┐
   │Variable│
   └───────┘

Two-Layer Type System

Atomese 2 (MeTTa's underlying representation) employs a two-layer type architecture designed for maximum flexibility:

Layer 1: Generic Core

The generic core provides minimal type infrastructure:

; Type declaration syntax
(: expr TypeName)

; Examples
(: 42 Number)
(: "hello" String)
(: add (-> Number Number Number))

Core Features:

  • Basic type annotations
  • Gradual typing (optional annotations)
  • Type variables for polymorphism
  • Structural subtyping

Layer 2: Specialized Type Systems

Domain-specific type systems built atop the core:

; Example: Linear type system for resource tracking
(: LinearType Type)
(: consume (-> (Linear $a) Unit))

; Example: Dependent types for refinement
(: Vector (-> Type Nat Type))
(: zeros (-> (n : Nat) (Vector Int n)))

Specialized Systems:

  • Linear types: Resource tracking
  • Dependent types: Value-indexed types
  • Behavioral types: Process properties (OSLF)
  • Spatial types: Namespace constraints

Why Two Layers?

"We designed Atomese 2 with two separate layers: a generic core, plus one or more specific type systems that define their own notions of 'type' and their own checking/inference algorithms."

— OpenCog Hyperon Paper

This separation enables:

  1. Interoperability: Different systems can share the core
  2. Experimentation: New type systems without core changes
  3. Gradual adoption: Add types incrementally
  4. Domain optimization: Specialized checking per domain

Pattern Matching as Core Operation

Pattern matching is the fundamental operation in MeTTa. All computation proceeds via matching patterns against the Atomspace.

Basic Pattern Matching

; Knowledge base
(parent Alice Bob)
(parent Bob Carol)

; Query pattern (returns all matches)
!(match &self (parent $x $y) ($x $y))
; Result: ((Alice Bob) (Bob Carol))

Unification Semantics

Pattern matching implements unification with occurs check:

match(pattern, target) → BindingsSet

Where BindingsSet = { σ₁, σ₂, ... } and each σᵢ : Var → Atom

Algorithm Properties:

  • Soundness: $\sigma(\text{pattern})$ = target for all $\sigma$ in result
  • Completeness: All unifiers found
  • Most general: Returns MGU when unique

Rewrite Rules

Computation proceeds via conditional rewriting:

; Define rewrite rule
(= (factorial 0) 1)
(= (factorial $n)
   (* $n (factorial (- $n 1))))

; Evaluate (triggers rewrites)
!(factorial 5)
; Result: 120

The Seven Minimal Operations

From Meta-MeTTa, the core operations are:

OperationPurpose
evalEvaluate expression
evalcConditional evaluation
chainSequential composition
function/returnFunctional abstraction
unifyPattern unification
cons-atom/decons-atomList construction
collapse-bind/superpose-bindNondeterminism

Gradual Typing and Paraconsistent Logic

MeTTa supports gradual typing, allowing typed and untyped code to coexist.

Gradual Typing Semantics

; Fully typed
(: add (-> Int Int Int))
(= (add $x $y) (+ $x $y))

; Untyped (dynamically checked)
(= (flexible-add $x $y) (+ $x $y))

; Mixed (type at boundary)
(= (safe-add $x $y)
   (if (and (is-int $x) (is-int $y))
       (add $x $y)
       (Error "Type mismatch")))

Connection to Paraconsistent Logic

Via the Curry-Howard correspondence, gradual types map to paraconsistent logic — a logic that tolerates contradictions without explosion:

Gradual Type System ↔ Paraconsistent Logic
         │                    │
    Type errors          Contradictions
    are localized        don't propagate

Implications:

  • Type errors don't crash the entire system
  • Partially typed code can still execute
  • Inconsistencies are contained to their scope

Distributed Atomspace

The Distributed Atomspace (DAS) enables Hyperon to scale across machines.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    Distributed Atomspace                         │
├─────────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐             │
│  │   Node 1    │  │   Node 2    │  │   Node 3    │             │
│  │ ┌─────────┐ │  │ ┌─────────┐ │  │ ┌─────────┐ │             │
│  │ │Local AS │ │  │ │Local AS │ │  │ │Local AS │ │             │
│  │ └────┬────┘ │  │ └────┬────┘ │  │ └────┬────┘ │             │
│  │      │      │  │      │      │  │      │      │             │
│  │ ┌────▼────┐ │  │ ┌────▼────┐ │  │ ┌────▼────┐ │             │
│  │ │ Cache   │ │  │ │ Cache   │ │  │ │ Cache   │ │             │
│  │ └────┬────┘ │  │ └────┬────┘ │  │ └────┬────┘ │             │
│  └──────┼──────┘  └──────┼──────┘  └──────┼──────┘             │
│         │                │                │                     │
│         └────────────────┼────────────────┘                     │
│                          │                                       │
│                 ┌────────▼────────┐                             │
│                 │  Query Router   │                             │
│                 └────────┬────────┘                             │
│                          │                                       │
│                 ┌────────▼────────┐                             │
│                 │   Index Layer   │                             │
│                 │ (MongoDB/Redis) │                             │
│                 └─────────────────┘                             │
└─────────────────────────────────────────────────────────────────┘

Query Distribution

Pattern queries are distributed using:

  1. Hash-based partitioning: Atoms sharded by hash
  2. Index-based routing: Queries directed to relevant shards
  3. Result aggregation: Distributed joins for complex queries

Cognitive Synergy

Hyperon's architecture enables cognitive synergy — multiple AI paradigms cooperating through shared knowledge.

Paradigm Integration

ParadigmAtomspace RepresentationInteraction Mode
Symbolic AILogic atoms, rulesDirect manipulation
Neural NetworksWeight atoms, activationsGrounded atoms
EvolutionaryPopulation atomsMutation operators
ProbabilisticTruth values, distributionsInference atoms

Synergy Example

; Neural network suggests candidates
(neural-suggest "image-features" $candidates)

; Symbolic reasoning filters
(logical-filter $candidates
  (satisfies safety-constraint))

; Evolutionary search optimizes
(evolve-solution $filtered
  fitness-function
  100)  ; generations

Relevance to MeTTaIL

The OpenCog Hyperon architecture directly informs MeTTaIL's design:

Type System Alignment

Hyperon ConceptMeTTaIL Mapping
Two-layer typesBasic sorts + OSLF predicates
Gradual typingOptional behavioral annotations
MetagraphTheory categories
Pattern matchingPredicate evaluation

Implementation Path

  1. Layer 1 (Current): Sort-based validation in MeTTaIL
  2. Layer 2 (Planned): OSLF behavioral predicates

Key Insight

The two-layer type system from Atomese 2 validates MeTTaIL's approach:

  • Generic core = MeTTaIL's sort/constructor checking
  • Specialized systems = OSLF behavioral types

This alignment ensures MeTTaIL can serve as MeTTa's native type system while supporting advanced behavioral reasoning for Rholang integration.


Summary

OpenCog Hyperon provides:

  1. Metagraph knowledge store (Atomspace)
  2. Four atom meta-types (Symbol, Variable, Expression, Grounded)
  3. Two-layer type system (generic core + specialized)
  4. Pattern matching as the core operation
  5. Gradual typing with paraconsistent semantics
  6. Distributed scalability (DAS)
  7. Cognitive synergy across AI paradigms

These foundations directly support MeTTaIL's semantic type checking goals and provide the theoretical justification for the layered approach to behavioral types.


References

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close