Skip to content

Commit a444b37

Browse files
authored
Merge pull request #140 from AdaWorldAPI/claude/vsaclip-hamming-recognition-y0b94
Claude/vsaclip hamming recognition y0b94
2 parents 1387d83 + a0ecf17 commit a444b37

5 files changed

Lines changed: 1768 additions & 0 deletions

File tree

crates/ladybug-contract/src/cogrecord8k.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//! No scan, no index lookup, no serialization.
4040
//! One VPOPCNTDQ pass per container per hop.
4141
42+
#[cfg(test)]
4243
use crate::container::Container;
4344
use crate::wide_container::{WideContainer, EmbeddingFormat, WIDE_BYTES};
4445

@@ -113,6 +114,24 @@ impl CogRecord8K {
113114
record
114115
}
115116

117+
// =========================================================================
118+
// WIDE METADATA ACCESS (16384-bit expanded schema)
119+
// =========================================================================
120+
121+
/// Read-only view into the full 16,384-bit metadata container.
122+
///
123+
/// Provides access to both legacy fields (W0–W127) and expanded schema
124+
/// fields (W128–W255): SPO Crystal, Hybrid Crystal, extended NARS,
125+
/// scent index, causal graph, 10-layer activations, DN spine cache.
126+
pub fn wide_meta(&self) -> crate::wide_meta::WideMetaView<'_> {
127+
crate::wide_meta::WideMetaView::new(&self.meta.words)
128+
}
129+
130+
/// Mutable view into the full 16,384-bit metadata container.
131+
pub fn wide_meta_mut(&mut self) -> crate::wide_meta::WideMetaViewMut<'_> {
132+
crate::wide_meta::WideMetaViewMut::new(&mut self.meta.words)
133+
}
134+
116135
// =========================================================================
117136
// CONTAINER ACCESS
118137
// =========================================================================
@@ -493,4 +512,66 @@ mod tests {
493512
// This means: 4× the data at the same VPOPCNTDQ throughput
494513
// as 8 legacy containers (which would be 8 × 16 = 128 iterations)
495514
}
515+
516+
#[test]
517+
fn test_wide_meta_through_cogrecord8k() {
518+
use crate::wide_meta::SpoTriple;
519+
520+
let mut r = CogRecord8K::new();
521+
522+
// Write SPO triple via wide_meta_mut
523+
let triple = SpoTriple {
524+
subject_dn: 0x0C00,
525+
predicate_hash: 0xABCD,
526+
confidence_q8: 200,
527+
object_dn: 0x0C42,
528+
evidence_count: 5,
529+
flags: 0,
530+
};
531+
r.wide_meta_mut().set_spo_triple(0, &triple);
532+
533+
// Write 10-layer activations
534+
let activations = [0.1, 0.2, 0.9, 0.4, 0.5, 0.6, 0.3, 0.8, 0.7, 0.15];
535+
r.wide_meta_mut().set_layer_activations(&activations);
536+
r.wide_meta_mut().set_calibration_error(0.05);
537+
538+
// Write spine cache
539+
r.wide_meta_mut().set_spine(&[0xA0, 0xB0, 0xC0]);
540+
541+
// Finalize with checksum
542+
r.wide_meta_mut().init_wide();
543+
544+
// Read back via wide_meta
545+
let wm = r.wide_meta();
546+
let read_triple = wm.spo_triple(0);
547+
assert_eq!(read_triple.subject_dn, 0x0C00);
548+
assert_eq!(read_triple.object_dn, 0x0C42);
549+
assert_eq!(read_triple.confidence_q8, 200);
550+
551+
assert_eq!(wm.dominant_layer(), 2); // 0.9 is highest
552+
assert!((wm.calibration_error() - 0.05).abs() < 1e-12);
553+
assert_eq!(wm.spine_depth(), 3);
554+
assert!(wm.verify_wide_checksum());
555+
assert!(!wm.is_legacy_only());
556+
}
557+
558+
#[test]
559+
fn test_wide_meta_legacy_compatibility() {
560+
let mut r = CogRecord8K::new();
561+
562+
// Write via legacy meta view (through wide_meta_mut)
563+
r.wide_meta_mut().legacy_mut().set_dn_addr(0xDEAD_BEEF);
564+
r.wide_meta_mut().legacy_mut().set_rung_level(5);
565+
566+
// Read via wide_meta
567+
assert_eq!(r.wide_meta().dn_addr(), 0xDEAD_BEEF);
568+
assert_eq!(r.wide_meta().rung_level(), 5);
569+
570+
// Also readable through legacy MetaView on the container
571+
let legacy = crate::meta::MetaView::new(
572+
(&r.meta.words[..128]).try_into().unwrap()
573+
);
574+
assert_eq!(legacy.dn_addr(), 0xDEAD_BEEF);
575+
assert_eq!(legacy.rung_level(), 5);
576+
}
496577
}

crates/ladybug-contract/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub mod container;
3535
pub mod wide_container;
3636
pub mod geometry;
3737
pub mod meta;
38+
pub mod wide_meta;
3839
pub mod record;
3940
pub mod cogrecord8k;
4041

@@ -59,6 +60,7 @@ pub use geometry::ContainerGeometry;
5960
pub use record::CogRecord;
6061
pub use cogrecord8k::{CogRecord8K, RECORD8K_BITS, RECORD8K_BYTES, SLOT_META, SLOT_CAM, SLOT_INDEX, SLOT_EMBED};
6162
pub use meta::{MetaView, MetaViewMut};
63+
pub use wide_meta::{WideMetaView, WideMetaViewMut, SpoTriple, WIDE_SCHEMA_VERSION};
6264
pub use address::{CognitiveAddress, CognitiveDomain};
6365
pub use codebook::OpCategory;
6466
pub use nars::TruthValue;

0 commit comments

Comments
 (0)