superlocalmemory 3.2.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +106 -71
  3. package/package.json +1 -2
  4. package/pyproject.toml +16 -1
  5. package/src/superlocalmemory/cli/commands.py +309 -0
  6. package/src/superlocalmemory/cli/main.py +44 -0
  7. package/src/superlocalmemory/core/config.py +282 -11
  8. package/src/superlocalmemory/core/consolidation_engine.py +37 -0
  9. package/src/superlocalmemory/core/engine.py +21 -0
  10. package/src/superlocalmemory/core/engine_wiring.py +58 -8
  11. package/src/superlocalmemory/dynamics/activation_guided_quantization.py +374 -0
  12. package/src/superlocalmemory/dynamics/eap_scheduler.py +276 -0
  13. package/src/superlocalmemory/dynamics/ebbinghaus_langevin_coupling.py +171 -0
  14. package/src/superlocalmemory/encoding/cognitive_consolidator.py +804 -0
  15. package/src/superlocalmemory/hooks/auto_invoker.py +46 -8
  16. package/src/superlocalmemory/hooks/auto_parameterize.py +147 -0
  17. package/src/superlocalmemory/infra/heartbeat_monitor.py +140 -0
  18. package/src/superlocalmemory/infra/pid_manager.py +193 -0
  19. package/src/superlocalmemory/infra/process_reaper.py +572 -0
  20. package/src/superlocalmemory/learning/consolidation_quantization_worker.py +115 -0
  21. package/src/superlocalmemory/learning/forgetting_scheduler.py +263 -0
  22. package/src/superlocalmemory/learning/quantization_scheduler.py +320 -0
  23. package/src/superlocalmemory/math/ebbinghaus.py +309 -0
  24. package/src/superlocalmemory/math/fisher_quantized.py +251 -0
  25. package/src/superlocalmemory/math/hopfield.py +279 -0
  26. package/src/superlocalmemory/math/polar_quant.py +379 -0
  27. package/src/superlocalmemory/math/qjl.py +115 -0
  28. package/src/superlocalmemory/mcp/server.py +2 -0
  29. package/src/superlocalmemory/mcp/tools_v3.py +10 -0
  30. package/src/superlocalmemory/mcp/tools_v33.py +351 -0
  31. package/src/superlocalmemory/parameterization/__init__.py +47 -0
  32. package/src/superlocalmemory/parameterization/pattern_extractor.py +534 -0
  33. package/src/superlocalmemory/parameterization/pii_filter.py +106 -0
  34. package/src/superlocalmemory/parameterization/prompt_injector.py +216 -0
  35. package/src/superlocalmemory/parameterization/prompt_lifecycle.py +275 -0
  36. package/src/superlocalmemory/parameterization/soft_prompt_generator.py +425 -0
  37. package/src/superlocalmemory/retrieval/engine.py +21 -3
  38. package/src/superlocalmemory/retrieval/forgetting_filter.py +145 -0
  39. package/src/superlocalmemory/retrieval/hopfield_channel.py +335 -0
  40. package/src/superlocalmemory/retrieval/quantization_aware_search.py +133 -0
  41. package/src/superlocalmemory/retrieval/spreading_activation.py +1 -1
  42. package/src/superlocalmemory/retrieval/strategy.py +16 -6
  43. package/src/superlocalmemory/retrieval/vector_store.py +1 -1
  44. package/src/superlocalmemory/server/routes/agents.py +68 -8
  45. package/src/superlocalmemory/server/routes/learning.py +18 -1
  46. package/src/superlocalmemory/server/routes/lifecycle.py +36 -17
  47. package/src/superlocalmemory/server/routes/v3_api.py +503 -1
  48. package/src/superlocalmemory/storage/database.py +206 -0
  49. package/src/superlocalmemory/storage/embedding_migrator.py +178 -0
  50. package/src/superlocalmemory/storage/migration_v33.py +140 -0
  51. package/src/superlocalmemory/storage/quantized_store.py +261 -0
  52. package/src/superlocalmemory/storage/schema_v32.py +137 -0
  53. package/conftest.py +0 -5
@@ -0,0 +1,171 @@
1
+ # Copyright (c) 2026 Varun Pratap Bhardwaj / Qualixar
2
+ # Licensed under the MIT License - see LICENSE file
3
+ # Part of SuperLocalMemory V3 | https://qualixar.com | https://varunpratap.com
4
+
5
+ """Ebbinghaus-Langevin coupling — forgetting drift in dynamics.
6
+
7
+ Combines the Ebbinghaus forgetting curve with Fisher-Langevin coupling
8
+ to create a three-way information-dynamic lifecycle:
9
+
10
+ 1. Fisher confidence -> Langevin temperature (existing)
11
+ 2. Ebbinghaus retention -> forgetting drift coefficient (new)
12
+ 3. Combined temperature = T_fisher * (1 + lambda_forget)
13
+
14
+ The forgetting drift pushes low-retention memories toward the Langevin
15
+ boundary faster, while high-retention memories resist drift. This creates
16
+ a thermodynamically grounded forgetting process.
17
+
18
+ Mathematical formulation:
19
+ lambda_forget = (1 - R) * forgetting_drift_scale
20
+ T_combined = T_fisher * (1 + lambda_forget)
21
+ weight_combined = w_fisher * w_ebbinghaus
22
+
23
+ Part of Qualixar | Author: Varun Pratap Bhardwaj
24
+ License: MIT
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ import logging
30
+ from dataclasses import dataclass
31
+
32
+ import numpy as np
33
+
34
+ from superlocalmemory.core.config import ForgettingConfig
35
+ from superlocalmemory.dynamics.fisher_langevin_coupling import (
36
+ FisherLangevinCoupling,
37
+ )
38
+ from superlocalmemory.math.ebbinghaus import EbbinghausCurve
39
+ from superlocalmemory.math.langevin import LangevinDynamics
40
+
41
+ logger = logging.getLogger(__name__)
42
+
43
+
44
+ # ---------------------------------------------------------------------------
45
+ # Coupling state
46
+ # ---------------------------------------------------------------------------
47
+
48
+ @dataclass(frozen=True)
49
+ class EbbinghausCouplingState:
50
+ """State of the Ebbinghaus-Langevin coupling for a single memory.
51
+
52
+ Attributes:
53
+ fact_id: Fact identifier.
54
+ retention_score: R(t) in [0, 1].
55
+ memory_strength: S(m) in [S_MIN, S_MAX].
56
+ lifecycle_zone: One of active/warm/cold/archive/forgotten.
57
+ effective_temperature: Combined T (Fisher + forgetting).
58
+ lifecycle_weight: Combined weight [0, 1].
59
+ forgetting_drift: lambda_forget coefficient.
60
+ is_forgotten: Below forget_threshold.
61
+ consolidation_signal: From Fisher coupling.
62
+ """
63
+
64
+ fact_id: str
65
+ retention_score: float
66
+ memory_strength: float
67
+ lifecycle_zone: str
68
+ effective_temperature: float
69
+ lifecycle_weight: float
70
+ forgetting_drift: float
71
+ is_forgotten: bool
72
+ consolidation_signal: bool
73
+
74
+
75
+ # ---------------------------------------------------------------------------
76
+ # Coupling class
77
+ # ---------------------------------------------------------------------------
78
+
79
+ class EbbinghausLangevinCoupling:
80
+ """Couples Ebbinghaus forgetting to Fisher-Langevin dynamics.
81
+
82
+ Creates a three-way feedback loop:
83
+ 1. Fisher confidence modulates Langevin temperature (existing).
84
+ 2. Ebbinghaus retention adds forgetting drift.
85
+ 3. Combined effect determines lifecycle zone and weight.
86
+ """
87
+
88
+ __slots__ = ("_ebbinghaus", "_langevin", "_fisher_coupling", "_config")
89
+
90
+ def __init__(
91
+ self,
92
+ ebbinghaus: EbbinghausCurve,
93
+ langevin: LangevinDynamics,
94
+ fisher_coupling: FisherLangevinCoupling,
95
+ config: ForgettingConfig,
96
+ ) -> None:
97
+ self._ebbinghaus = ebbinghaus
98
+ self._langevin = langevin
99
+ self._fisher_coupling = fisher_coupling
100
+ self._config = config
101
+
102
+ def compute_coupled_state(
103
+ self,
104
+ fact_id: str,
105
+ fisher_variance: np.ndarray,
106
+ langevin_radius: float,
107
+ access_count: int,
108
+ importance: float,
109
+ confirmation_count: int,
110
+ emotional_salience: float,
111
+ hours_since_last_access: float,
112
+ ) -> EbbinghausCouplingState:
113
+ """Compute the full coupled state for a single memory.
114
+
115
+ Combines Fisher-Langevin coupling with Ebbinghaus forgetting
116
+ to produce a unified lifecycle state.
117
+
118
+ Args:
119
+ fact_id: Fact identifier.
120
+ fisher_variance: Fisher variance vector (diagonal).
121
+ langevin_radius: Current Langevin position radius [0, 1).
122
+ access_count: Total access count.
123
+ importance: PageRank importance score.
124
+ confirmation_count: Evidence/confirmation count.
125
+ emotional_salience: Emotional strength.
126
+ hours_since_last_access: Hours since last access.
127
+
128
+ Returns:
129
+ EbbinghausCouplingState with all computed fields.
130
+ """
131
+ # Step 1: Fisher-Langevin coupling (existing system)
132
+ fl_state = self._fisher_coupling.compute_coupling(
133
+ fisher_variance, langevin_radius, access_count,
134
+ )
135
+
136
+ # Step 2: Ebbinghaus strength
137
+ strength = self._ebbinghaus.memory_strength(
138
+ access_count, importance, confirmation_count, emotional_salience,
139
+ )
140
+
141
+ # Step 3: Ebbinghaus retention
142
+ retention = self._ebbinghaus.retention(hours_since_last_access, strength)
143
+
144
+ # Step 4: Lifecycle zone
145
+ zone = self._ebbinghaus.lifecycle_zone(retention)
146
+
147
+ # Step 5: Forgetting drift coefficient
148
+ # Higher forgetting (lower R) -> stronger drift toward boundary
149
+ lambda_forget = (1.0 - retention) * self._config.forgetting_drift_scale
150
+
151
+ # Step 6: Combined temperature
152
+ # Forgetting increases effective temperature -> more noise -> faster drift
153
+ t_combined = fl_state.langevin_temperature * (1.0 + lambda_forget)
154
+
155
+ # Step 7: Combined weight
156
+ weight = fl_state.lifecycle_weight * self._ebbinghaus.lifecycle_weight(zone)
157
+
158
+ # Step 8: Is forgotten?
159
+ is_forgotten = zone == "forgotten"
160
+
161
+ return EbbinghausCouplingState(
162
+ fact_id=fact_id,
163
+ retention_score=retention,
164
+ memory_strength=strength,
165
+ lifecycle_zone=zone,
166
+ effective_temperature=t_combined,
167
+ lifecycle_weight=weight,
168
+ forgetting_drift=lambda_forget,
169
+ is_forgotten=is_forgotten,
170
+ consolidation_signal=fl_state.consolidation_signal,
171
+ )