feat: Contrastive CSI Embedding Model — ADR-024 (all 7 phases) #52

Merged
ruvnet merged 5 commits from feat/adr-024-contrastive-csi-embedding into main 2026-03-01 14:44:39 +08:00
ruvnet commented 2026-03-01 14:28:31 +08:00 (Migrated from github.com)

Summary

Full implementation of ADR-024: Contrastive CSI Embedding Model with Deep RuVector Integration.

Turns WiFi CSI signals into reusable 128-dim fingerprints for room identification, anomaly detection, person re-identification, and cross-environment transfer — all in 55 KB at INT8, fitting comfortably on an ESP32.

Phases 1-5 (core embedding pipeline):

  • embedding.rs (909 lines): ProjectionHead, CsiAugmenter (5 augmentations), InfoNCE loss, EmbeddingExtractor, FingerprintIndex (4 types), PoseEncoder, cross-modal loss, quantized validation
  • graph_transformer.rs: Added embed() method to CsiToPoseTransformer
  • trainer.rs: Added contrastive loss, pretrain_epoch() for self-supervised SimCLR
  • rvf_container.rs: Added SEG_EMBED (0x0C) for embedding model packaging
  • main.rs: Added --pretrain, --pretrain-epochs, --embed, --build-index CLI flags

Phase 7 (deep RuVector integration):

  • MicroLoRA on ProjectionHead (1,792 params/env, 93% less than full retraining)
  • EWC++ consolidation (pretrain-to-finetune memory preservation)
  • EnvironmentDetector drift-aware embedding extraction
  • Hard-negative mining for efficient contrastive training
  • RVF SEG_LORA (0x0D) for per-environment LoRA profile storage

Total: 3,352 lines added across 8 files, 272 tests (all pass)

Test plan

  • cargo check -p wifi-densepose-sensing-server compiles clean
  • cargo test -p wifi-densepose-sensing-server — 272 tests pass (189 lib + 49 bin + 16 rvf + 18 vitals)
  • Phase 1: ProjectionHead 128-dim L2-normalized output, weight roundtrip, InfoNCE loss properties
  • Phase 2: Pretrain epoch loss decreases, contrastive weight in composite loss
  • Phase 3: FingerprintIndex search returns correct nearest, anomaly detection works
  • Phase 4: PoseEncoder output shape, cross-modal loss finite
  • Phase 5: INT8 quantized embedding rank correlation validated, RVF segment roundtrip
  • Phase 7: LoRA changes output, merge/unmerge roundtrip, param count correct, EWC consolidation, drift detection, hard-negative mining, RVF LoRA profile roundtrip

Closes #50

Generated with claude-flow

## Summary Full implementation of ADR-024: Contrastive CSI Embedding Model with Deep RuVector Integration. Turns WiFi CSI signals into reusable 128-dim fingerprints for room identification, anomaly detection, person re-identification, and cross-environment transfer — all in 55 KB at INT8, fitting comfortably on an ESP32. **Phases 1-5** (core embedding pipeline): - `embedding.rs` (909 lines): ProjectionHead, CsiAugmenter (5 augmentations), InfoNCE loss, EmbeddingExtractor, FingerprintIndex (4 types), PoseEncoder, cross-modal loss, quantized validation - `graph_transformer.rs`: Added `embed()` method to CsiToPoseTransformer - `trainer.rs`: Added `contrastive` loss, `pretrain_epoch()` for self-supervised SimCLR - `rvf_container.rs`: Added `SEG_EMBED` (0x0C) for embedding model packaging - `main.rs`: Added `--pretrain`, `--pretrain-epochs`, `--embed`, `--build-index` CLI flags **Phase 7** (deep RuVector integration): - MicroLoRA on ProjectionHead (1,792 params/env, 93% less than full retraining) - EWC++ consolidation (pretrain-to-finetune memory preservation) - EnvironmentDetector drift-aware embedding extraction - Hard-negative mining for efficient contrastive training - RVF SEG_LORA (0x0D) for per-environment LoRA profile storage **Total**: 3,352 lines added across 8 files, 272 tests (all pass) ## Test plan - [x] `cargo check -p wifi-densepose-sensing-server` compiles clean - [x] `cargo test -p wifi-densepose-sensing-server` — 272 tests pass (189 lib + 49 bin + 16 rvf + 18 vitals) - [x] Phase 1: ProjectionHead 128-dim L2-normalized output, weight roundtrip, InfoNCE loss properties - [x] Phase 2: Pretrain epoch loss decreases, contrastive weight in composite loss - [x] Phase 3: FingerprintIndex search returns correct nearest, anomaly detection works - [x] Phase 4: PoseEncoder output shape, cross-modal loss finite - [x] Phase 5: INT8 quantized embedding rank correlation validated, RVF segment roundtrip - [x] Phase 7: LoRA changes output, merge/unmerge roundtrip, param count correct, EWC consolidation, drift detection, hard-negative mining, RVF LoRA profile roundtrip Closes #50 Generated with [claude-flow](https://github.com/ruvnet/claude-flow)
Sign in to join this conversation.