Six-crate Rust workspace (core/sim/llm/store/server/bin) backing a Three.js + WebGL frontend. Live at http://127.0.0.1:7777 via `cargo run`. Sim - Event-driven scheduler with min-heap, per-engram tick, staggered Spawn events (40 ms apart) so each engram's flight is visually readable. - Solid-donut torus topology (replaces original spherical density-driven shell, see Topology Pivot in docs/system-analysis.md). Configurable major/minor radii in config.toml; live `POST /api/galaxy/:id/resize`. - Physics: Verlet integration + friction; in-hole pull + galactic spin (CCW around +z) for spiral-ejection ejection from the donut centre; soft tube boundary with velocity-reflecting wall. - Cosine-weighted gravity (kiddo k-NN within radius 25, threshold 0.50) and synapse formation (threshold 0.62) gated to inside-the-tube only. - LM Studio integration via OpenAI-compatible REST: batched embeddings, optional Bearer auth, semaphore-bounded parallel ops per §13.5. Server - axum HTTP + WebSocket. Routes: /healthz, /api/galaxy CRUD, /seed, /ingest, /resize, /engrams/:id, /ws/galaxy/:id/events. - Binary 12-byte-aligned position frames at ~20 Hz; JSON for sparse events (Hello, EngramCreated, SynapseCreated, TorusUpdated). - Layered config: config.toml (defaults) + config.local.toml (secrets, gitignored) merged on startup. Frontend - Vite + vanilla TypeScript + three.js 0.169. - Engrams render as additive bloom-friendly point sprites with a per-engram hash-driven hue rotation and breathing pulse. - Comet-style velocity-aligned trails; additive ribbon synapses whose endpoints track engram positions every frame. - UnrealBloomPass + ACES tone-mapping for the linked-particles look. - HUD shows torus dims, engram + synapse counts, LM Studio status; controls for seed, ingest, and live torus resize. Docs - README replaced with docs/IDEA.md; system-analysis.md updated with the topology pivot decisions and Galaxy Ejection refinement notes (the implementation plan lives in ~/.claude/plans, gitignored). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
/// Universal Slate (per §13.1) — Stage 2 layer 1 only: a dense embedding
|
|
/// vector. The deeper LLM-comparison layer arrives in Stage 4.
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Slate(pub Vec<f32>);
|
|
|
|
impl Slate {
|
|
pub fn dim(&self) -> usize {
|
|
self.0.len()
|
|
}
|
|
|
|
pub fn norm(&self) -> f32 {
|
|
self.0.iter().map(|x| x * x).sum::<f32>().sqrt()
|
|
}
|
|
|
|
/// Cosine similarity in `[-1, 1]`. Returns 0 if either vector is zero or
|
|
/// dimensions disagree (the latter can happen across embedding model
|
|
/// changes — see §13 risk #3).
|
|
pub fn cosine(&self, other: &Slate) -> f32 {
|
|
if self.0.len() != other.0.len() {
|
|
return 0.0;
|
|
}
|
|
let mut dot = 0.0_f32;
|
|
let mut a2 = 0.0_f32;
|
|
let mut b2 = 0.0_f32;
|
|
for (a, b) in self.0.iter().zip(other.0.iter()) {
|
|
dot += a * b;
|
|
a2 += a * a;
|
|
b2 += b * b;
|
|
}
|
|
let denom = (a2.sqrt() * b2.sqrt()).max(1e-9);
|
|
dot / denom
|
|
}
|
|
}
|