Implement Sophia MVP stages 4-7 (introspection, queries, persistence, polish)

Brings the system from "engrams cluster + form synapses" to a complete
end-to-end demo: ingest text, watch it cluster, ask questions, restart
with state intact.

- Stage 4: birth introspection (taxonomy/goals/open_questions via LLM,
  bounded by the global parallel-op semaphore), per-engram memory log,
  click-to-inspect side panel.
- Stage 5: queries as conversations. POST /api/galaxy/:id/query embeds
  the question, materializes a pinned Query-Engram at the donut center,
  runs broadcast retrieval (global cosine scan + 1-hop synaptic
  expansion with attenuation) and fans out responder LLM calls. The
  integrator runs every 2s on accumulated snippets and streams the
  refining answer back over SSE; responders briefly transition to
  Conversing on the WS bus so the right dots light up.
- Stage 6: snapshot persistence. sled-backed store keyed by galaxy id,
  JSON-encoded values (bincode chokes on internally-tagged enums like
  Manifest/MemoryKind), 60s periodic snapshot task, hydrate-on-boot,
  DELETE /api/galaxy/:id wired through. State survives kill -9.
- Stage 7: HUD additions (sim ticks/sec, LLM queue depth, FPS) via a
  new GET /api/stats polled at 1Hz. `sophia demo` subcommand boots the
  server then auto-ingests a 50-paragraph corpus baked into the binary
  with include_str!. README quickstart added.

Token caps for query_responder/integrator bumped (gemma-4-e4b is a
thinking model — output budget must cover hidden reasoning + visible
answer, otherwise content comes back empty). Pinned engrams skip
physics; their tick scheduling is also skipped at materialization so
they stay perfectly still at the donut center.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-28 11:53:11 +02:00
parent 8688f632bf
commit bae084cd76
36 changed files with 3137 additions and 58 deletions

50
assets/demo_corpus.txt Normal file
View File

@@ -0,0 +1,50 @@
Pasta carbonara uses guanciale, eggs, pecorino romano, and freshly cracked black pepper.
Spaghetti aglio e olio combines garlic, olive oil, chili flakes, and parsley over al dente pasta.
Risotto requires arborio rice, slowly added warm broth, and constant stirring to release starch.
Pesto alla genovese blends basil, pine nuts, garlic, parmesan, pecorino, and olive oil.
Cacio e pepe is just pasta, pecorino, and pepper — emulsion comes from starchy pasta water.
Lasagne bolognese layers ragu, bechamel, and pasta sheets between melted parmesan.
Amatriciana sauces guanciale and tomato together with a touch of pecorino.
Gnocchi alla romana use semolina baked with butter and cheese instead of potato.
Tiramisu layers savoiardi soaked in espresso with mascarpone whipped with eggs and sugar.
Sourdough bread relies on a wild yeast starter and slow bulk fermentation for flavor.
Bechamel sauce is built from a roux of butter and flour cooked into milk.
Caramelization happens to sugars above 160 C; the Maillard reaction needs proteins and amines.
Sushi rice is seasoned with vinegar, sugar, and salt while still warm so seasoning soaks evenly.
Korean kimchi ferments napa cabbage with chili paste, garlic, ginger, and salted shrimp.
French croissants get their flake from laminated layers of cold butter folded into yeasted dough.
Backpropagation computes gradients of a loss with respect to neural network weights via the chain rule.
Gradient descent updates model parameters in the direction that reduces the loss the most.
Stochastic gradient descent samples mini-batches so each step costs less and adds useful noise.
Adam adapts a per-parameter learning rate using running moments of the gradients.
Convolutional neural networks share weights across spatial locations to exploit translation invariance.
Recurrent networks process sequences by feeding state from one step into the next.
Transformers attend over a whole sequence at once instead of recurring through it.
Self-attention computes a weighted sum of values where weights are softmax of query-key dot products.
Layer normalization stabilizes training by normalizing activations along the feature dimension.
Dropout randomly zeroes activations during training as a regularizer.
Residual connections let very deep networks train by giving gradients an additive path back.
Word embeddings map discrete tokens to dense vectors learned end-to-end with the task.
A loss function turns predictions and targets into a single scalar to minimize.
Cross-entropy loss compares a predicted distribution to a one-hot target.
Reinforcement learning learns a policy by trial-and-error rewards in an environment.
Markov decision processes describe RL with states, actions, transitions, and rewards.
Q-learning estimates the value of taking each action in each state.
Policy gradient methods directly adjust the policy to maximize expected reward.
The Roman Empire fell in 476 CE when Romulus Augustulus, the last western emperor, was deposed.
Constantinople fell to the Ottomans under Mehmed II in 1453, ending the Byzantine Empire.
The Magna Carta of 1215 limited the power of the English monarchy and protected baronial rights.
The printing press, perfected by Gutenberg around 1440, accelerated the spread of literacy in Europe.
The Treaty of Westphalia in 1648 ended the Thirty Years War and established sovereign-state diplomacy.
The French Revolution began in 1789 with the storming of the Bastille on July 14.
The Industrial Revolution started in late-eighteenth-century Britain with mechanized textile production.
The American Civil War ran from 1861 to 1865 over slavery, states' rights, and union.
World War I lasted from 1914 to 1918 and was triggered by the assassination of Archduke Franz Ferdinand.
The Russian Revolution of 1917 replaced the tsarist autocracy with Bolshevik rule.
The Great Depression began with the 1929 Wall Street Crash and lasted through the 1930s.
World War II ended in 1945 after Germany surrendered in May and Japan in September.
The United Nations was founded in 1945 in San Francisco to prevent another global war.
The Cold War divided the world between US and Soviet spheres from roughly 1947 to 1991.
The Berlin Wall fell on November 9, 1989, symbolizing the end of the Cold War in Europe.
The Apollo 11 mission landed humans on the Moon for the first time on July 20, 1969.
The European Union was established by the Maastricht Treaty in 1993, succeeding the EEC.