Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
438 changes: 382 additions & 56 deletions .claude/knowledge/cognitive-shader-architecture.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions crates/lance-graph-contract/src/collapse_gate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! CollapseGate write protocol — MergeMode + GateDecision.
//!
//! CollapseGate enum (Flow/Block/Hold) lives in ndarray::hpc::bnn_cross_plane.
//! This module adds the write-back protocol types consumed by the 7-layer stack.
//!
//! Layer 3: CollapseGate decides SHOULD this delta land?
//! MergeMode decides HOW overlapping writes merge.
//! GateDecision = gate + merge mode (owned microcopy, 2 bytes).

/// How overlapping writers merge their deltas.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum MergeMode {
/// XOR commit: `target ^= delta`. Self-inverse, reversible.
/// For single-target updates where order doesn't matter.
Xor = 0,
/// Bundle: majority vote across all pending deltas.
/// For multi-writer consensus (e.g., multiple agents posting to blackboard).
Bundle = 1,
/// Superposition: keep ALL deltas without resolution.
/// For ambiguous cases where we want to preserve all variants.
Superposition = 2,
}

/// A gate decision: what the CollapseGate decided + how to merge.
/// Copy type, 2 bytes. The microcopy returned by gate evaluation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct GateDecision {
/// Flow = apply delta. Block = reject. Hold = queue for next cycle.
pub gate: u8, // 0=Flow, 1=Block, 2=Hold (matches ndarray CollapseGate ordinals)
/// How to merge if Flow.
pub merge: MergeMode,
}

impl GateDecision {
pub const FLOW_XOR: Self = Self { gate: 0, merge: MergeMode::Xor };
pub const FLOW_BUNDLE: Self = Self { gate: 0, merge: MergeMode::Bundle };
pub const FLOW_SUPER: Self = Self { gate: 0, merge: MergeMode::Superposition };
pub const BLOCK: Self = Self { gate: 1, merge: MergeMode::Xor };
pub const HOLD: Self = Self { gate: 2, merge: MergeMode::Xor };

#[inline]
pub fn is_flow(&self) -> bool { self.gate == 0 }
#[inline]
pub fn is_block(&self) -> bool { self.gate == 1 }
#[inline]
pub fn is_hold(&self) -> bool { self.gate == 2 }
}
64 changes: 64 additions & 0 deletions crates/lance-graph-contract/src/container.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Container — the BindSpace record unit at 16K width.
//!
//! A Container is a `[u64; 256]` = 16,384 bits = 2 KB, 64-byte aligned.
//! It's the universal address unit — every program, every agent, every
//! shader emits and consumes Containers in the same BindSpace.
//!
//! The Container type is intentionally a type alias for `[u64; 256]`,
//! not a newtype. This keeps it zero-cost and compatible with
//! `ndarray::simd::Fingerprint<256>` (same backing store).
//!
//! CogRecord = metadata Container + content Container = 4 KB.
//! Read-only after construction. Mutations go through CollapseGate.

/// Container = 256 × u64 = 16,384 bits = 2 KB.
/// Same backing as `ndarray::hpc::fingerprint::Fingerprint<256>`.
pub type Container = [u64; 256];

/// Container width in u64 words.
pub const CONTAINER_WORDS: usize = 256;

/// Container width in bits.
pub const CONTAINER_BITS: usize = CONTAINER_WORDS * 64;

/// Container width in bytes.
pub const CONTAINER_BYTES: usize = CONTAINER_WORDS * 8;

/// A cognitive record = metadata + content.
/// 4 KB total. Read-only after construction.
#[derive(Clone, Debug)]
pub struct CogRecord {
/// Container 0: metadata (identity, NARS, edges, qualia, adjacency).
pub meta: Container,
/// Container 1: content (fingerprint, embedding, SPO, whatever geometry says).
pub content: Container,
}

impl CogRecord {
/// Create from metadata + content containers.
pub fn new(meta: Container, content: Container) -> Self {
Self { meta, content }
}

/// Zero record (both containers zeroed).
pub fn zero() -> Self {
Self { meta: [0u64; 256], content: [0u64; 256] }
}

/// Total byte size.
pub const BYTE_SIZE: usize = CONTAINER_BYTES * 2; // 4096
}

/// Content geometry: how to interpret Container 1.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum ContentGeometry {
/// 16K bitpacked fingerprint (standard holographic).
Bitpacked16K = 0,
/// Dense f32 embedding (Jina, sentence-transformer). Truncated to fit 2KB.
DenseF32 = 1,
/// 3 × Fingerprint (Subject + Predicate + Object decomposition).
TripleSPO = 2,
/// Packed edge list (adjacency as content, not metadata).
EdgePacked = 3,
}
2 changes: 2 additions & 0 deletions crates/lance-graph-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ pub mod high_heel;
pub mod literal_graph;
pub mod exploration;
pub mod orchestration_mode;
pub mod collapse_gate;
pub mod container;
76 changes: 56 additions & 20 deletions docs/COGNITIVE_SHADER_HYDRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,62 @@ Session N+3:

## Type System for AGI Endgame

The struct-of-arrays is NOT a data structure — it's the BindSpace
ADDRESS SPACE DIMENSIONS. Each dimension is a separate Hamming-sweepable
fingerprint column. The AGI query is an AND across independent cascades.

```rust
// The unified record: identity × encoding × cognition × perspective
pub struct CognitiveRecord {
// Identity
pub fingerprint: Fingerprint<256>, // 16K bits canonical
pub cam_address: [u8; 6], // CAM-PQ 6-byte address

// Encoding (bgz side)
pub hhtl_entry: HhtlDEntry, // 4B tree address
pub palette_idx: u8, // bgz17 archetype

// Cognition (thinking side)
pub edge: CausalEdge64, // u64 SPO+NARS packed
pub shader_mask: u8, // active CognitiveShader layers
pub coca_idx: u16, // 4096 COCA position

// Perspective (AGI)
pub topic: Fingerprint<256>, // what this is about
pub angle: Fingerprint<256>, // from whose viewpoint
pub qualia: [f32; 18], // 18D phenomenal coordinates
pub rung: u8, // Pearl's causal level
// Each column: one fingerprint array, independently sweepable
pub struct BindSpaceColumns {
// Content identity — WHAT
pub content: Vec<Fingerprint<256>>, // Hamming sweep: "find similar"
pub cam_address: Vec<[u8; 6]>, // CAM-PQ 3-stroke cascade

// Topic — ABOUT WHAT (sweep: "everything about cats")
pub topic: Vec<Fingerprint<256>>,

// Angle — FROM WHERE (sweep: "from a vet's perspective")
pub angle: Vec<Fingerprint<256>>,

// Causality — WHY/HOW (sweep: "interventional only")
pub causality: Vec<CausalEdge64>, // rung level filter

// Qualia — FEELS LIKE (sweep: "high urgency")
pub qualia: Vec<[f32; 18]>, // 18D phenomenal coordinates

// Temporal — WHEN (sweep: "last 5 minutes")
pub temporal: Vec<u64>, // timestamp index

// Shader state — WHO PRODUCED THIS
pub shader: Vec<u8>, // which CognitiveShader output
}
```

Why struct-of-arrays, not array-of-structs:
- You NEVER read all 7 dimensions for one record
- You sweep ONE dimension across ALL records (one popcount cascade)
- Then intersect survivors across dimensions
- The CognitiveShader per-cycle stream IS this: 5 cascades, intersect, emit

```
Per cycle:
sweep topic[] → 50K survivors (2ms, Hamming)
sweep angle[] → narrow to 5K (0.2ms, Hamming)
sweep causality[] → narrow to 500 (0.05ms, CausalEdge64 filter)
sweep qualia[] → narrow to 50 (scalar, 18D range check)
exact on 50 → palette lookup → CausalEdge64 output

Total: ~2.3ms for 1M records across 5 dimensions
```

The BindSpace 64-bit address (16-bit type + 48-bit hash) means ALL
content — weight archetypes, inference outputs, COCA verbs, grammar
triangles, dream consolidations, user queries — lives in the SAME
address space. One XOR. One sweep. One lookup. Regardless of origin.

The gazillions of programs (codecs, shaders, learning, grammar, search,
spectroscopy) compile into the same binary because they all emit and
consume the same 64-bit addresses into the same fingerprint columns.

The weights are seeds. The columns are the memory. The shader is the
program. The cascade is the CPU. The edges are the output.
Loading