The Knowledge Layer manages the organization and persistence of concepts in AGISystem2. It builds on the Geometry Layer to store bounded diamonds, manage their evolution through clustering, and enable layered contexts through the theory stack. This layer provides the semantic substrate on which reasoning operates.

Specification: DS(/storage/concepts) · DS(/storage/cluster_manager) · DS(/core/theory_stack)

ConceptStore

The ConceptStore is the primary repository for concepts. Each concept is identified by a canonical name and stored as one or more bounded diamonds. The store provides fast lookup by name and supports iteration over all stored concepts.

ConceptStore Name Index "Dog" → ptr "Cat" → ptr "Animal" → ptr ... Diamond Storage Diamond 1 Diamond 2 Persistence StorageAdapter → disk/memory .AGISystem2/

ConceptStore architecture. The name index provides O(1) lookup by concept name. Diamond storage holds the geometric representations. The persistence layer syncs changes to disk or other storage backends.

Operations

OperationDescriptionComplexity
get(name) Retrieve concept by canonical name O(1)
put(name, diamond) Store or update concept O(1) amortized
exists(name) Check if concept exists O(1)
listConcepts() Return all concept names O(N)
delete(name) Remove concept O(1)

Concept Structure

Each concept in the store contains:

{
  name: "Dog",                    // Canonical name
  diamonds: [                     // One or more bounded diamonds
    {
      center: Int8Array,          // Centroid vector
      min: Int8Array,             // Per-dimension minimums
      max: Int8Array,             // Per-dimension maximums
      radius: number,             // L1 radius
      mask: Uint8Array,           // Relevance mask
      observationCount: number    // Training observations
    }
  ],
  metadata: {
    created: timestamp,
    lastModified: timestamp,
    source: "assertion" | "inference"
  }
}

ClusterManager

The ClusterManager decides how new observations affect concept shapes. When a new point is observed for a concept, the manager must choose: expand an existing diamond, create a new diamond, or split an overgrown diamond.

New Observation Inside? Inside No change needed Expand OK? Expand Widen diamond New Diamond Create cluster Yes No Yes No

ClusterManager decision flow. If the new observation is already inside an existing diamond, no change is needed. If outside, the manager decides whether to expand the nearest diamond or create a new one based on distance thresholds and concept coherence.

Expansion Policy

The expansion policy controls when a diamond grows versus when a new diamond is created. Key parameters:

function handleObservation(concept, point) {
  // Find nearest diamond
  const nearest = findNearestDiamond(concept.diamonds, point);
  const dist = distanceToSurface(nearest, point);

  if (dist <= 0) {
    // Already inside
    return { action: 'none' };
  }

  if (dist < expansionThreshold && nearest.radius + dist < maxRadius) {
    // Expand existing diamond
    return expandDiamond(nearest, point);
  }

  // Create new diamond
  return createNewDiamond(concept, point);
}

Splitting

When a diamond grows too large or becomes incoherent (covering semantically distant points), it can be split into multiple smaller diamonds. Splitting uses k-means clustering on the observation history to find natural subclusters.

TheoryStack

The TheoryStack enables layered knowledge contexts. Each layer can override specific aspects of concepts without modifying the base knowledge. This mechanism supports:

Base Knowledge Dog IS_A Animal, Cat IS_A Animal, ... Theory Layer: medical_context Aspirin REDUCES Inflammation Theory Layer: hypothetical_1 Dog CAN Fly (hypothetical) Stack grows up depth 0 depth 1 depth 2

Theory stack structure. The base layer contains permanent knowledge. Upper layers add or override facts for specific contexts. When querying, the system composes layers from top to bottom, with upper layers taking precedence.

Stack Operations

OperationDescription
push(name) Create and push new layer with given name
pop() Remove top layer, discarding its changes
peek() Get current top layer without removing
depth() Return current stack depth
compose(conceptName) Get runtime view of concept through all layers
save(filename) Persist current top layer to file
load(filename) Load layer from file and push

Layer Composition

When a concept is requested, the stack composes a runtime view by merging all layers:

function getComposedConcept(name) {
  // Start with base concept
  let result = baseStore.get(name) || createEmpty(name);

  // Apply each layer from bottom to top
  for (const layer of stack) {
    if (layer.has(name)) {
      const override = layer.get(name);
      result = mergeConceptOverride(result, override);
    }
  }

  return result;
}

TheoryLayer

Each TheoryLayer contains concept overrides that modify the base knowledge. Overrides can:

Override Structure

{
  name: "medical_context",
  overrides: {
    "Aspirin": {
      // New concept added in this layer
      diamonds: [{ center: [...], min: [...], max: [...], radius: 50, mask: [...] }]
    },
    "Inflammation": {
      // Dimension override for existing concept
      dimensionOverrides: {
        42: { min: -20, max: 20 },  // Override dimension 42 bounds
        87: { min: -10, max: 30 }   // Override dimension 87 bounds
      }
    }
  },
  facts: [
    { subject: "Aspirin", relation: "REDUCES", object: "Inflammation" }
  ]
}

Persistence

The Knowledge Layer uses the StorageAdapter to persist concepts and theories. The default adapter writes to the .AGISystem2/ directory structure:

.AGISystem2/
├── data/
│   ├── concepts/
│   │   ├── Dog.bin          # Binary diamond data
│   │   ├── Cat.bin
│   │   └── ...
│   └── index.json           # Name → file mapping
└── theories/
    ├── base.sys2dsl         # Base theory (optional)
    ├── medical_context.sys2dsl
    └── ...

Binary format stores vectors efficiently; text format (.sys2dsl) stores human-readable fact lists for portability and version control.

Configuration

Parameterauto_testmanual_testprod
maxRadius100150200
expansionThreshold304050
maxDiamondsPerConcept3510
persistenceIntervalimmediate10 ops100 ops

Related Documentation