This vignette demonstrates FunctorFlow v1’s core design goal: building AI systems by categorical construction. We walk through the canonical v1 workflow:
Define two KET models as first-class categorical model objects
Declare interface morphisms from each into a shared context
Build a pullback representing the joint constraint-compatible model
Verify the construction satisfies the universal property
Compile and run the pullback on concrete data
Emit a proof certificate for the construction
Construct a universal morphism from an external cone
This is the kind of compositional assembly that FunctorFlow v0 could not express — where categorical structure is the actual method of assembly, not merely a descriptive label.
Step 1: Define KET Models as Categorical Objects
We start with two KET modules that process different modalities — text and code — each with its own value space and attention incidence structure.
usingFunctorFlow# KET model for semantic text understandingket_text =ket_block(; name =:TextKET, value_kind =:tokens, incidence_kind =:attention, description ="Semantic text understanding via KET attention")# KET model for code structure understandingket_code =ket_block(; name =:CodeKET, value_kind =:ast_nodes, incidence_kind =:syntax_edges, description ="Code structure understanding via KET attention")println("TextKET: ", length(ket_text.objects), " objects, ",length(ket_text.operations), " operations")println("CodeKET: ", length(ket_code.objects), " objects, ",length(ket_code.operations), " operations")
Now we promote these diagrams to first-class categorical model objects — the key v1 abstraction. A CategoricalModelObject wraps a diagram with an ambient category, typed interface ports, boundary maps, and semantic laws that can be verified.
Define interface morphisms from each model into a shared context object. These morphisms express how each model’s output maps into a common representational space.
We can also compose morphisms and apply them to model objects:
# Apply the text projection to get the shared context imageshared_from_text = FunctorFlow.apply(f, text_obj)println("Image of TextKET under f: ", shared_from_text.name)println(" ambient category: ", shared_from_text.ambient_category)
Image of TextKET under f: SharedContext
ambient category: FinVect
Step 3: Build the Pullback
The pullback is the central v1 construction: it takes two models that both map into a shared context and produces the most general model that is simultaneously compatible with both.
Call verify() to check that the pullback satisfies its universal property: both factors are present, the shared object exists, and the commuting constraint is enforced.
v =verify(pb)println("Verification passed: ", v.passed)println("Construction type: ", v.construction)println("\nIndividual checks:")for (check, passed) in v.checks status = passed ? "✓":"✗"println(" $status$check")end
-- Auto-generated by FunctorFlow.jl
namespace FunctorFlowProofs.Generated.JointModel
open FunctorFlowProofs in
def exportedDiagram : DiagramDecl := {
name := "JointModel",
objects := ["left__Values", "left__Incidence", "left__ContextualizedValues", "right__Values", "right__Incidence", "right__ContextualizedValues", "SharedContext", "left__aggregate", "right__aggregate"],
operations := [{ name := "left__aggregate", kind := OperationKind.leftKan, refs := ["left__Values", "left__Incidence",...
Step 7: Universal Morphism
Given any other model (a “test cone”) that also maps into both factors, the universal property guarantees a unique mediating morphism into the pullback:
# Build a test cone — any other model that wants to interact with both TextKET and CodeKETtest_cone =ket_block(; name =:ExternalModel)mediating =universal_morphism(pb, test_cone)println("Mediating diagram: ", mediating.name)println(" Objects: ", length(mediating.objects))println(" Operations: ", length(mediating.operations))println("\n Mediating objects:")for (name, obj) in mediating.objectsprintln(" ", name, " (", obj.kind, ")")end
This end-to-end pipeline demonstrates the v1 design thesis:
Categorical objects elevate KET models from macro expansions to first-class compositional entities
Universal constructions (pullbacks, pushouts, etc.) serve as the actual assembly method — not ad hoc glue code
Verification checks structural properties at the categorical level
Compilation lowers constructions to executable systems while preserving their provenance
Proof certificates record the construction faithfully for formal verification
Universal morphisms express the interface guarantee: any compatible model factors uniquely through the construction
The same pattern extends to pushouts (model merging), products (independent combination), coproducts (hypothesis aggregation), and equalizers (consistency enforcement). Together they provide a principled compositional language for building AI systems from categorical structure.
# Clean up the model registrydelete!(MODEL_REGISTRY, :TextKET)delete!(MODEL_REGISTRY, :CodeKET)println("✅ Canonical v1 example complete")