Join the conversation

Join the community of Machine Learners and AI enthusiasts.

Sign Up
gianlucamazza 
posted an update Oct 21
Post
119
A live demo of emotional-memory 0.18.1: chat, watch the affective state move, and type "recall X" to see memories ranked by meaning plus mood. It shows how the mechanism works, not that it wins in general. The Scope and limits section lists the benchmarks where plain cosine beats it.

gianlucamazza/emotional-memory-demo

The demo runs the one path your own evidence says to wrap.

The live Space has LLM appraisal on (gpt-5.4-mini), so affect is inferred, not oracle.
That's the regime where your Addendum P has cosine ahead: 0.887 vs 0.800 top1.

And app.py calls retrieve() with no query_affect, so the mood term scores against the conversation's running state.
0.18.1 already ships the wrapper you validated, retrieve_query_gated(). Neutral queries go cosine-only, the rest use the query's own affect. Addendum Y puts it +0.076 over ungated AFT on ES-MemEval.

Docs more careful than the demo is a good problem to have.

A toggle between the two paths would make the boundary visible. Type a neutral recall and watch the mood term switch off.

Was the ungated path kept on purpose, to show the mechanism at full strength?

·

Thanks, you're right on the substance.

The Space runs live LLM appraisal, so affect is inferred, not given. That's the setting where my own pre-registered results show no advantage over plain cosine, and the card says so under "Scope and limits". The Addendum P numbers you quoted are correct (0.887 vs 0.800 top-1). But P used a different model and embedder, with queries answerable from text alone, so it tells you about this kind of setting, not about the demo itself.

You're also right about recall: it calls retrieve() without query_affect, so the mood term scores against the running conversation state. That's the "current mood" behaviour the UI describes. retrieve_query_gated() ships in 0.18.1. Addendum Y's +0.076 over the always-on query-appraised arm is correct, but on ES-MemEval the gated path still doesn't beat plain cosine. The demo predates the gate and I haven't switched it since; it's there to show the mechanism, not the best retrieval setup.

Fair correction. The +0.076 is over the always-on query-appraised arm, not over state recall, and gated still trails cosine on ES-MemEval. I wrote it bigger than it is.

The toggle is in (c495a7c). I read _retrieve_query_gated against the 0.18.1 wheel: same gate, |valence| < 0.2, same two retrieve calls. It matches.

One thing makes side by side less clean than it looks: retrieve() writes back.
Each recall bumps retrieval_count on its top 3, runs the Pearce-Hall update, can reconsolidate a tag toward the current mood when APE is high, and adds Hebbian links among the three it returned. All on by default in the demo's config.
retrieval_count slows decay, and decayed strength is one of the scoring terms.

So recall X in one mode, then the other, and the second ranks a store the first already edited. Only the cosine-only branch is immune, since its weights are [1, 0, 0, 0, 0, 0]. Anywhere else, order picks part of the difference.
A deep copy of the store per arm, or a fresh session per mode, would make the toggle a clean A/B.

Are the write-backs part of what the demo should show, or would a read-only retrieve be worth having?

·

Thanks, this is a fair catch and mostly right. Two corrections: reconsolidation pulls the tag toward the running core affect, not the mood, and co-retrieval only strengthens links that already exist; it never adds new ones. Two more points. The cosine-only branch ranks independently of earlier writes, but it still writes to its own top 3. And once a memory's window is open, any recall within the next 5 minutes reconsolidates it again, whatever the prediction error, which is exactly your A-then-B case.

There's also a bigger factor you didn't mention. After each recall the demo appraises its own reply, and that can shift the affective state before the next recall. So copying the store alone wouldn't make the comparison fair; the state has to be snapshotted too.

The write-backs are intended: they're the mechanism the demo is there to show, and they're documented. What wasn't fair was reading the toggle as a comparison, because the write-backs skew it. So each mode now keeps its own memory and state: normal recall still writes, but only to the memory of the mode you used, so it no longer changes what the other mode sees. A new "Compare both modes" button runs both modes on scratch copies of the same snapshot, without changing your session. There's also a line in the demo that explains the write-backs.

Both corrections hold against the 0.18.1 wheel. reconsolidate() lerps toward the running core affect, and hebbian_strengthen() only touches links already in the tag. The reply appraisal after a recall is the bigger confounder, agreed.

The per-mode split is close. One path still leaks, and always into the gated arm.

Once diverged is set, a new user turn is encoded on session.mood and gated imports only that memory, by id. Two things stay behind:

  1. The back-links. encode() writes a reverse link onto the older memories it links to. Those older memories already exist in gated, so the import skips them.
  2. The tag. mood_snapshot and consolidation_strength come from the mood engine's state, which holds the recall reply. s2 reads mood_snapshot.

I ran your DemoSession code against the wheel: 5 turns, one recall, 3 more turns. Reference: a fresh engine fed the same 8 turns, no recall.

  • Old-to-new back-links: mood 11, gated 0, reference 11.
  • consolidation_strength on gated's first new memory: 0.1526 vs 0.1466, with the keyword fallback.
  • With a stub appraiser that scores the recall reply negative, the same memory's mood_snapshot valence is -0.0054 in gated, +0.0247 in the reference. Gated copies the mood engine to 4 decimals.
  • Gated's running state matches the reference exactly. observe(appraisal=...) does its job.

Swap the import for gated.encode(content, appraisal=memory.tag.appraisal) and all three close: 11 back-links, every tag equal to the reference.

It goes the same way when the recall ran in gated mode, since new turns always encode on mood first.
s6 is weak by your own docstring, so the snapshot matters more than the links. Compare both modes is clean either way: both scratch copies come from one engine.

Was the import route there to keep memory ids identical across the two modes?

·

You're right, and thanks for running it against the wheel. After a recall, every new turn is encoded on the mood engine first and gated just imports it, so the leak always lands in gated, including when the recall ran in gated mode. Both of your mechanisms hold: the reverse links that encode() writes stay on the mood side, and the tag is built from the mood engine's state. Two more fields go the same way: momentum, and the strengths of the new memory's forward links, which are scored against the mood store. core_affect doesn't leak. Our turns were different from yours, so our values are too, but the pattern is the same: gated's new tags equal mood's, and gated's running state equals the reference.

We see two things differently. First, in our runs the snapshot doesn't outweigh the links. Repairing only the links or only the tags left a similar number of top-3 changes: in a small store the margins are tiny, so even a weak s6 can flip an order. Second, "Compare both modes" is fair between its two arms, because both copies come from one engine. But with the radio on "Query-gated", that engine is the gated one, so before the fix Compare was reading the leaky store.

On the ids: no. The import was there to keep one appraisal per turn and to stop recall write-backs from crossing over. Matching ids were a side effect, and the missing back-links and the state copied over from the mood engine were an oversight on our side. Nothing in the demo depends on matching ids.

Your swap is now live on the Space. After a recall, gated encodes each new turn itself, with the same appraisal (gated.encode(content, appraisal=memory.tag.appraisal)), and the separate observe is gone, so its state doesn't advance twice. A new test checks tags, back-links and state against a fresh engine fed the same turns, with the recall in either mode. It's a demo-only change, and the fix is yours, so thank you.

Conceded on Compare. The old compare_both_modes took its snapshot from session.engine_for(retrieval_mode).
With the radio on Query-gated, both scratch copies came from the leaky store. Fair between its arms, not clean. My "either way" was wrong.

Conceded on the links too. My "snapshot matters more" came from s6's docstring weight, not from counting top-3 flips.
You counted. In a store this small a weak term can still flip an order.
Momentum and the forward-link strengths are two leaks I missed.

The swap reads right in 5d73e7ed: gated.encode(content, appraisal=...) after divergence, the observe after the import gone, import kept only as the no-appraisal fallback.

One thing the fix leaves in place, maybe by design. Compare still snapshots whichever engine the radio points at.
After a recall the two stores differ by their own write-backs. So the same query can give two different Compare panels, one per radio setting.

Is Compare meant to answer "which arm wins on the store I'm viewing", or "which arm wins on the same history"?

·

You're right about the behaviour: Compare copies the selected mode's memory store and affective state into two scratch engines and runs both strategies there, so switching the radio changes what it compares. Nothing is written back to either live engine.

That's the intended scope: Compare answers "which arm wins on the store I'm viewing", as a point-in-time check. It's now written down in COMPARE.md:
https://github.com/gianlucamazza/emotional-memory/blob/main/demo/COMPARE.md

"Which arm wins on the same history" belongs in the benchmarks. #170 adds an opt-in shared-history replay: the same ordered events go into each arm from a common empty start, each keeps its own retrieval write-backs, and per-step state traces are exported for comparison.
https://github.com/gianlucamazza/emotional-memory/pull/170

One more thing your review surfaced: the leftover /False endpoint was still listed in the public API until today. #179 hid the internal endpoints, so the API listing now shows only /chat, /compare_both and /reset_session.

Thanks for pushing on this. It's what got the contract written down.

COMPARE.md settles it. Point-in-time on the store you are viewing is a fair contract.

I ran #170 at ea890e6 (seed 7, hash embedder): cosine top-1 0.33, gated 0.54, always_on 0.54.
The trace shows what the replay can and cannot see yet.

All 50 scenarios are 6 encodes, then 2 retrieves at the very end. Nothing is encoded after a recall.
So the affective state is identical across all three arms at all 600 trace steps.
And the first recall's write-backs get exactly one later query to act on.

I reran it with every retrieve on a deep copy of the engine, so nothing writes back:

  • cosine: 0 of 100 rankings change.
  • gated and always_on: 6 of 100 change. Top-1 hits go from 56 read-only to 54 with write-backs.

And the gate fires once. 1 of 100 queries has |valence| under 0.2, so gated and always_on return the same ranking on 99 of 100.

So on realistic_recall_v1 the replay mostly measures always-on against cosine, plus a small write-back cost.

Will part 4's manifest add turns encoded after a recall, and neutral-affect queries, so the gate and the write-backs both get exercised?

·

Thank you for rerunning the replay. We reproduced all of it at ea890e6: in #170 nothing is encoded after a recall and the gate fires on 1 of 100 queries, so the replay mostly measures always-on against cosine, plus a small write-back cost.

Your rerun is why shared_history_recall_v1 exists. It's a new set of 36 queries where 24 encodes come after a recall and 14 queries are near-neutral (|valence| < 0.2), so the gate actually gets exercised:
https://github.com/gianlucamazza/emotional-memory/pull/180

First run at d6947ed5 (CPU, hash embedder, seed 7, 2000 bootstrap resamples), top-1 for cosine / gated / always-on:

  • #170 replay: 0.33 / 0.54 / 0.54 with write-back, 0.33 / 0.56 / 0.56 read-only. Gated and always-on score above cosine on top-1, and the intervals exclude 0.
  • shared_history_recall_v1: 0.69 / 0.72 / 0.69 in both modes. No arm differs significantly from cosine: every interval includes 0, p ≥ 0.25.

For gated and always-on, write-back changes the top-k on 6 of 100 replay queries and 5 of 36 on the new set; cosine is unchanged. Read-only mode changed nothing across 136 queries and three arms, and the affective state never diverged, so the whole effect sits in the memory store.

So the write-back effect is measurable but small, and the new set shows no gated advantage. The hash embedder has no semantics, so this run checks that the mechanism behaves as described and says nothing about retrieval quality.

Thanks again for taking the time.

The flat 0.69 / 0.72 / 0.69 is two effects of opposite sign cancelling, not no effect.

I reran shared_history_recall_v1 at ce2e657 (hash, seed 7, timeline write-back, your arm3 receipt) and got your numbers exactly.
Same label as your receipt: mechanism test (hash embedder), not a semantic-quality benchmark.

Then I split the 36 queries by query valence:

  • 18 non-neutral: gated and always-on both beat cosine, +1 top-1 and +2 hit@k each.
  • 14 near-neutral: gated returns cosine's ranking on all 14. Always-on changes 7 of them and loses 1 top-1 and 2 hits to cosine.
  • 4 boundary: all three arms rank identically.

So affect helps where the query carries it and hurts where it doesn't. The gate keeps the first and drops the second. That's the claim gated was built for, and the headline table hides it because always-on's gain and loss net to zero.

The catch is power. Each half rests on 1 or 2 discordant queries. An exact McNemar test needs at least 6 discordant pairs, all one way, to reach p < 0.05. At the rate seen here (2 of 14 near-neutral, 2 of 18 non-neutral), that's roughly 42 near-neutral and 54 non-neutral queries.

Would a v2 sized for that split be worth hand-authoring, or does the hash embedder make the sign itself too fragile to chase?

·

Thank you for splitting it by query valence. We reran it on the committed receipt (commit ce2e6579: https://github.com/gianlucamazza/emotional-memory/tree/e6615d9732ef46403ee6d3c0906a8d7ea246aa29/benchmarks/realistic/receipts/shared_history_recall_v1/ce2e6579, CI run: https://github.com/gianlucamazza/emotional-memory/actions/runs/40084829068) and got the same split, using the repo's gate threshold of 0.2. Top-1 / hit@k:

  • Non-neutral (18 queries): cosine 10 / 11; gated and always-on both 11 / 13, with no losses.
  • Near-neutral (14 queries, |valence| < 0.2): gated ranks exactly like cosine on all 14. Always-on changes 7 rankings and scores 10 / 12, with no gains.
  • Boundary (4 queries, |valence| = 0.2): all three arms score 4 / 4.

So on this set always-on's gains and losses cancel out, and gated's small edge over cosine isn't significant (McNemar p = 1.0 on top-1, 0.5 on hit@k). Your McNemar arithmetic checks out too.

Two things to add. First, the sizes you suggest (about 42 and 54 on hit@k) give roughly 56% power. Reaching 80% would take about 54 near-neutral and 70 non-neutral queries, still assuming the discordant pairs all go one way. Second, we reran the split with 8 hash variants. The direction held in all 8: gated always matched cosine on near-neutral queries, gated was always net positive on non-neutral top-1 (+1 to +6), and always-on never gained on near-neutral top-1. The boundary tie didn't hold in 3 of the 8, and the size varied a lot (non-neutral hit@k from 0 to +5). Most discordant pairs come from hash collisions.

On a v2: your split shows what a properly powered version would need to measure. We haven't decided whether to build it, and running it with a semantic embedder would first need a small code change. This is still a mechanism test (hash embedder), not a semantic-quality benchmark.

Your 54 and 70 check out. P(at least 6 discordant, all one way) is 0.567 at 42 and 0.802 at 54 near-neutral, 0.564 at 54 and 0.804 at 70 non-neutral.

One of your three 8-variant results is a code check, not a finding.
retrieve_query_gated routes |valence| < tau to semantic_only_weights(). So gated has to rank like cosine on every near-neutral query, under any hash. 8 of 8 there says the gate is wired right.
The two that carry information: gated net positive on non-neutral top-1 in 8 of 8, and always-on never gaining on near-neutral top-1.

Your last line is the bigger result. If most discordant pairs are hash collisions, a v2 sized on hash discordance is powered for collision noise, not for affect.
Your own T1.3 note saw this once already: semantic_confound top-1 went from -0.13 under hash to 0.00 with sbert-bge.

So I'd flip the order. Swap the embedder first, rerun the 36, count discordant pairs, then size v2 on that rate.
At HEAD f833450 shared_history.py still builds TokenHashEmbedder() inline (line 93).

Is that line the whole change, or does anything downstream assume the 64-dim hash vectors?

·

Thank you for taking the time to check the numbers and trace the code. Your distinction between verifying the gate and measuring a retrieval benefit is helpful, as is the suggestion to swap the embedder before sizing v2. I’ve captured both in the proposed ADR: https://github.com/gianlucamazza/emotional-memory/pull/192

I appreciate the care you’re putting into this review.

Your ADR caught an overclaim of mine.
I said gated "has to" rank like cosine on every near-neutral query. That only holds on the same candidates. With timeline write-back, an earlier non-neutral retrieval can change the store, so 8 of 8 there was the gate plus write-backs that never moved those rankings, not the gate alone.

It also answers my question: no 64-dim contract in the in-memory path, cosine_similarity only checks equal lengths.

The cluster point is the one I'd push hardest for v2.
36 queries over 12 scenarios is about 3 per history. The design effect is 1 + 2ρ, so even ρ = 0.25 means 1.5x the queries for the same power. Independent scenarios are the unit to count, which your ADR already says.

Will the semantic pilot report a within-scenario correlation for discordance, or are 12 histories too few to read one?

·

Thanks, Dipankar. The cluster point and the ICC question are both useful.

On near-neutral queries, your first statement holds in the current code, for the in-memory store with a deterministic embedder. Gated and cosine take the same path with semantic-only weights, and write-back only changes tags (counters, reconsolidated affect, links). Embeddings, content and the set of memories stay the same, so the rankings match even after histories diverge, and the 8/8 is a wiring check. It would need re-checking if a write-back changed content, embeddings or membership, with a non-deterministic embedder, or on any other store backend, such as SQLite or an approximate index. The ADR now says this.

On dimensions: agreed, there's no 64-dim contract in the in-memory path.

The design effect and scenarios as the unit are in ADR 0002. Per stratum it's thinner than 3 per history: within each affect stratum, a scenario has 1–2 queries, and near-neutral is mostly 1.

On the ICC: yes, the plan in ADR 0002 is for the pilot to report an exploratory within-scenario ICC for discordance, with its uncertainty and the number of informative clusters, or "not estimable" with the reason. Near-neutral gated vs cosine is constant by mechanism, so that one is not estimable. With 12 histories any estimate is descriptive, so the plan is to size v2 on a declared grid of ρ values.

Agreed on near-neutral. Thanks for tracing the store order, that settles it.

I ran the non-neutral side both ways at HEAD 441207d, hash embedder, shared_history_recall_v1.
Gated vs cosine on top-1: write-back b=1, c=0. Read-only b=1, c=0. Same net.
It is not the same pair.

Write-back wins bakery's bk_q_inspection_not_gasket. Read-only loses it and wins ferry's fs_q_no_sailing instead. always_on flips the same two queries.
Both are query 3 of 3 in their history, after two retrievals that wrote back.
It isn't simple rich-get-richer either: fs_cancelled_sailing was retrieved at q1 and q2 and still loses q3 under write-back. I haven't isolated which tag moved it.

So in v1 the read-only run does more than check a mechanism. It moves the only discordant pair to a different scenario, and scenario is the unit the ICC clusters on.
Per-mode b and c will hide that. The overlap of discordant query IDs across modes will show it.

Would you add a "discordant under write-back, read-only, or both" column to the scenario table, and count a pair that only exists under write-back as carry-over rather than scenario signal?

·

Thanks, Dipankar. The overlap idea is a good one.

We reproduced it at 441207d and on current main, with identical outputs (hash embedder, seed 7, shared_history_recall_v1). Gated vs cosine on top-1 matches what you found: write-back b=1, c=0 on bakery's bk_q_inspection_not_gasket, read-only b=1, c=0 on ferry's fs_q_no_sailing. The pairs differ, but both are query 3 of 3. always_on flips the same two, but it also loses one near-neutral query in both modes (startup's so_q_outage), so it's b=1, c=1 in each mode. Cosine top-1 is the same in both modes on all 36 queries.

On ferry, the tag that moves it is the reconsolidated affect. fs_cancelled_sailing is in the top 2 at q1 and q2, and after those two write-backs its valence drifts from -0.7 to about -0.36, away from the q3 query's valence (-0.85). Restoring only that field restores the hit, and no other single field changes the outcome. Its retrieval count on its own would have helped it. Bakery is the mirror case: reconsolidation moves bk_failed_inspection's affect toward the query (-0.75 to about -0.57, against the query's -0.6), and the win needs that together with its retrieval count.

So per-mode b and c do hide it. We plan to add the column to the ADR 0002 scenario table: discordant under write-back only, read-only only, or both, with the discordant query IDs per mode. This run already has data for all three. We also plan to add carry-over as a predeclared sensitivity analysis, with every pair kept in the primary count: a write-back-only pair labelled carry-over-dependent, a read-only-only pair carry-over-suppressed, and b, c and the ICC reported with and without the carry-over-dependent pairs, as a side check. Both gated discordances here come from the write-back history, so dropping only the write-back-only pairs from the primary count would tilt the result toward read-only. That's why read-only-only pairs would get a label too.

Thanks for spelling out that +0.076 was over the always-on arm, not cosine.