Skip to content

update PMLL.py#27

Closed
drQedwards wants to merge 2 commits intoSamsungSAILMontreal:mainfrom
drQedwards:patch-1
Closed

update PMLL.py#27
drQedwards wants to merge 2 commits intoSamsungSAILMontreal:mainfrom
drQedwards:patch-1

Conversation

@drQedwards
Copy link

Concept
Description
Memory Line
A single experience vector: {key, value, context, timestamp, recency, novelty, similarity} Anchor Chain
64-bit BLAKE2 hash linking consecutive lines: anchorₙ = hash(anchorₙ₋₁ ⊕ key ⊕ value ⊕ ctx) Race / Trace
Dual process: Race runs parallel candidate updates; Trace commits the winning anchor and decays others. Concert Heuristic
Weighted tri-blend controlling bias output: α (recency) + β (similarity) + γ (novelty) ΔW Overlay
Optional low-rank weight delta applied to LM head or attention projection

Concept
Description
Memory Line
A single experience vector: {key, value, context, timestamp, recency, novelty, similarity}
Anchor Chain
64-bit BLAKE2 hash linking consecutive lines: anchorₙ = hash(anchorₙ₋₁ ⊕ key ⊕ value ⊕ ctx)
Race / Trace
Dual process: Race runs parallel candidate updates; Trace commits the winning anchor and decays others.
Concert Heuristic
Weighted tri-blend controlling bias output: α (recency) + β (similarity) + γ (novelty)
ΔW Overlay
Optional low-rank weight delta applied to LM head or attention projection
@drQedwards
Copy link
Author

🧠 Persistent Memory Logic Loop (PMLL)

Extended Technical Overview — v2.0.0 (October 2025)

Author: Dr. Josef Kurk Edwards (Dr. Q) & John Trompeter
License: MIT — for research and reproducibility


1. Purpose

The Persistent Memory Logic Loop is a plug-in memory architecture for transformers and reasoning systems.
It replaces transient KV-cache behavior with a persistent lattice of hashed “memory lines,” enabling models to remember, revise, and reason recursively without retraining.


2. Core Concepts

Concept Description
Memory Line A single experience vector: {key, value, context, timestamp, recency, novelty, similarity}
Anchor Chain 64-bit BLAKE2 hash linking consecutive lines: anchorₙ = hash(anchorₙ₋₁ ⊕ key ⊕ value ⊕ ctx)
Race / Trace Dual process: Race runs parallel candidate updates; Trace commits the winning anchor and decays others.
Concert Heuristic Weighted tri-blend controlling bias output: α (recency) + β (similarity) + γ (novelty)
ΔW Overlay Optional low-rank weight delta applied to LM head or attention projection.

3. Mathematical Heuristics

Recency Decay

r_i = e^{-(t_now - t_i)/τ}

with default τ = 6 hours.

Novelty

n_i = 1 - max_j sim(k_i, k_j)

Composite Weight

w_i = αr_i + βs_i + γn_i
b = Σ w_i v_i / Σ w_i

Defaults: α = 0.35, β = 0.50, γ = 0.08, similarity floor = 0.15.


4. System Architecture

        ┌──────────────┐
        │ Transformer  │
        │ (HF / Nano)  │
        └──────┬───────┘
               │ query_vec
               ▼
      ┌────────────────────┐
      │ PMLL Service       │
      │  • LMDB + FAISS    │
      │  • Anchor Chain    │
      └────────────────────┘
               │ bias_vector / ΔW
               ▼
        ┌──────────────┐
        │ RTM Controller│
        │ (PLAN→REFLECT)│
        └──────────────┘

5. API Endpoints (local mode)

put(key, value, ctx, prev_anchor=None) → anchor

Stores a new vector pair with context. Automatically computes similarity and novelty.

query(query_vec, k=5) → List[MemoryLine]

Retrieves top-k entries by cosine similarity and recency decay.

bias_vector(query_vec, k=5) → np.ndarray

Aggregates weighted values for logit-bias or adapter injection.


6. Integration Patterns

HF Transformers (Logits Bias)

logits += alpha * pmll.bias_vector(hidden[-1])

LoRA Adapter (ΔW Overlay)

delta = pmll.bias_vector(q)
W_eff = W_base + beta * low_rank(delta)

Controller Loop (Recursive RTM)

y, anchor = model.step(x)
pmll.put(x, y, {"stage": "reflect"})

7. Storage Options

Backend Use Case Notes
JSON (default) Rapid prototyping Human-readable, slower for >10⁴ lines
LMDB Embedded cache Fast key/value persistence
DuckDB Analytical mode Enables temporal queries, joins
Faiss/ScaNN Vector index Accelerates nearest-neighbor lookup

8. Security & Integrity

  • Anchors use BLAKE2b-64 hash chains for tamper detection.
  • Each session can export seal.json containing final anchor and FNV-1a/64 checksum.
  • Optional AES or libsodium encryption layer (pmll_secure.py) for sensitive memory.

9. Future Extensions

Module Description ETA
pmll_server.py gRPC service for remote RTM calls Q4 2025
pmll_graphiti.py Neo4j / GraphRAG adapter Q1 2026
pmll_cuda.cu GPU-accelerated similarity kernel Q2 2026
pmll_visualizer.ipynb Grafana / Plotly dash for recency & novelty Q1 2026

10. Example Session

$ python3 PMLL.py
Anchor A: ed1f79b3c2a19d42
Queried 1 memory lines.
Bias Vector: [0.18 -0.02 … 0.33]

11. References

  1. Edwards & Trompeter (2025) Persistent Memory Logic Loop Architecture: Memory Footprint Reduction in Large Language Models — TechRxiv.
  2. Edwards (2025) The Recursive Transformer Model: Architecture, Theory, and Implementation with Persistent Memory Logic Loops — ResearchGate.
  3. Edwards et al. (2025) Hybrid TRM–RTM Controller Integration — ESS Open Archive.

@drQedwards
Copy link
Author

Please see
karpathy/nanochat#89 (comment)

in Karparthy’s nano project for a different context example of this logic loop in recursive implementations for models!

@drqsatoshi
Copy link

Ignore this please see recent work on the Q promise logic loop commit. That is the actually PMLL recursive loop

Copy link

@drqsatoshi drqsatoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add the pop and peek functions for the short term memory context

@drQedwards
Copy link
Author

Pull Request: #27

#65

Copy link

@drqsatoshi drqsatoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually will work well with the other memory tools

@drQedwards
Copy link
Author

drQedwards#2

@drQedwards drQedwards changed the title Create PMLL.py update PMLL.py Feb 26, 2026
@drqsatoshi drqsatoshi mentioned this pull request Feb 26, 2026
@drQedwards drQedwards closed this Feb 26, 2026
@drQedwards drQedwards deleted the patch-1 branch February 26, 2026 15:50
@drQedwards
Copy link
Author

Architecture / separation ✅ A Clean layering, pluggable hooks
Deterministic hashing ✅ A Properly stable JSON keys
Persistence (JSONLStore) ✅ A Append-only + snapshot pattern is correct
Async support ✅ B+ Good, minor lock concern
JSON comment stripping ⚠️ C Regex approach breaks on http:// in strings
rewind() recursion ⚠️ C Will stack-overflow at max_blocks=10_000
Thread safety ⚠️ C No lock on _blocks for async path
API compatibility ⚠️ B iter_q breaks sync → async contract
Integration with trm_ers_pmll.py ⚠️ B Not yet wired in; would replace inline classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants