pdm-memory 0.1.9__tar.gz → 0.2.3__tar.gz
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.
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/PKG-INFO +23 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/README.md +18 -2
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/__init__.py +16 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/auth/jwt_handler.py +11 -13
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/core/alignment.py +22 -10
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/core/math.py +8 -10
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/core/retrieval.py +377 -52
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/core/signature.py +40 -25
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/ingest/__init__.py +2 -2
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/ingest/auto_signature.py +7 -7
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/ingest/batch.py +9 -8
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/ingest/ingester.py +13 -13
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/__init__.py +13 -13
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/anthropic_adapter.py +5 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/context_manager.py +6 -7
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/gemini_adapter.py +5 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/groq_adapter.py +5 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/ollama_adapter.py +5 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/integrations/openai_adapter.py +5 -5
- pdm_memory-0.2.3/pdm_memory/io/__init__.py +6 -0
- pdm_memory-0.2.3/pdm_memory/io/json_transfer.py +191 -0
- pdm_memory-0.2.3/pdm_memory/memory.py +1380 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/models.py +43 -3
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/storage/__init__.py +7 -1
- pdm_memory-0.2.3/pdm_memory/storage/base.py +135 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/storage/cloud_driver.py +94 -17
- pdm_memory-0.2.3/pdm_memory/storage/factory.py +188 -0
- pdm_memory-0.2.3/pdm_memory/storage/postgres_driver.py +355 -0
- pdm_memory-0.2.3/pdm_memory/storage/schema.py +322 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/storage/sqlite_driver.py +125 -132
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/sync.py +7 -4
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/bench.py +10 -11
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/cli.py +149 -2
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/explorer_actions.py +5 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/server.py +36 -15
- pdm_memory-0.2.3/pdm_memory/types.py +37 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/PKG-INFO +23 -5
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/SOURCES.txt +13 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/requires.txt +3 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pyproject.toml +9 -3
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_alignment.py +39 -7
- pdm_memory-0.2.3/tests/test_cli.py +212 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_explorer_console.py +10 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_gemini_adapter.py +1 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_groq_adapter.py +1 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_jwt_auth.py +21 -2
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_math.py +7 -6
- pdm_memory-0.2.3/tests/test_memory.py +474 -0
- pdm_memory-0.2.3/tests/test_memory_hooks.py +110 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_ollama_adapter.py +1 -0
- pdm_memory-0.2.3/tests/test_pdm_concurrency.py +124 -0
- pdm_memory-0.2.3/tests/test_pdm_physics.py +197 -0
- pdm_memory-0.2.3/tests/test_retrieval_diversity.py +198 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_sqlite_driver.py +83 -1
- pdm_memory-0.2.3/tests/test_storage_factory.py +124 -0
- pdm_memory-0.2.3/tests/test_tier2.py +175 -0
- pdm_memory-0.2.3/tests/test_tier3.py +121 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_torsion.py +45 -0
- pdm_memory-0.1.9/pdm_memory/memory.py +0 -728
- pdm_memory-0.1.9/pdm_memory/storage/base.py +0 -137
- pdm_memory-0.1.9/tests/test_cli.py +0 -110
- pdm_memory-0.1.9/tests/test_memory.py +0 -165
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/LICENSE +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/auth/__init__.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/bench.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/core/__init__.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/storage/errors.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/__init__.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory/tools/static/index.html +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/dependency_links.txt +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/entry_points.txt +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/pdm_memory.egg-info/top_level.txt +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/setup.cfg +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_bench.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_cloud_driver.py +0 -0
- {pdm_memory-0.1.9 → pdm_memory-0.2.3}/tests/test_explorer_ui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pdm-memory
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Pressure-Driven Memory (PDM) — persistent, resonance-based memory for AI apps.
|
|
5
5
|
Author: Westfield Innovations LLC
|
|
6
6
|
License: Elastic License 2.0 (ELv2)
|
|
@@ -115,8 +115,8 @@ License: Elastic License 2.0 (ELv2)
|
|
|
115
115
|
**trademark** means trademarks, service marks, and similar rights.
|
|
116
116
|
|
|
117
117
|
Project-URL: Homepage, https://azus.ai
|
|
118
|
-
Project-URL: Documentation, https://azus.ai
|
|
119
|
-
Project-URL: Bug Tracker, https://
|
|
118
|
+
Project-URL: Documentation, https://azus.ai/support
|
|
119
|
+
Project-URL: Bug Tracker, https://azus.ai/support?tab=bugs
|
|
120
120
|
Project-URL: Source, https://github.com/westfield-innovations/pdm-memory
|
|
121
121
|
Project-URL: Repository, https://github.com/westfield-innovations/pdm-memory
|
|
122
122
|
Keywords: ai,memory,llm,rag,pressure-driven,persistent-memory
|
|
@@ -154,6 +154,8 @@ Requires-Dist: groq>=0.9.0; extra == "all"
|
|
|
154
154
|
Provides-Extra: ui
|
|
155
155
|
Requires-Dist: fastapi>=0.110; extra == "ui"
|
|
156
156
|
Requires-Dist: uvicorn[standard]>=0.27; extra == "ui"
|
|
157
|
+
Provides-Extra: postgres
|
|
158
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == "postgres"
|
|
157
159
|
Provides-Extra: dev
|
|
158
160
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
159
161
|
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
@@ -175,6 +177,7 @@ Dynamic: license-file
|
|
|
175
177
|
[](https://pypi.org/project/pdm-memory/)
|
|
176
178
|
[](https://github.com/westfield-innovations/pdm-memory/actions)
|
|
177
179
|
[](LICENSE)
|
|
180
|
+
[](https://azus.ai/support)
|
|
178
181
|
|
|
179
182
|
Your LLM forgets everything between conversations. The standard fix — stuff a vector database into the context window — is expensive, slow, and retrieves **what matches words, not what matters**.
|
|
180
183
|
|
|
@@ -184,12 +187,15 @@ Your LLM forgets everything between conversations. The standard fix — stuff a
|
|
|
184
187
|
- 🗄️ **Your storage.** One local file. Your data never leaves your machine. Check the source — there's no phone-home in it.
|
|
185
188
|
- ⚡ **Ten minutes.** `pip install pdm-memory` → three lines → persistent memory.
|
|
186
189
|
|
|
187
|
-
**
|
|
190
|
+
📖 **Documentation:** [azus.ai/support](https://azus.ai/support)
|
|
191
|
+
|
|
192
|
+
**Benchmarks vs standard RAG:** [azus.ai/pdm/benchmarks](https://azus.ai/pdm/benchmarks)
|
|
188
193
|
|
|
189
194
|
---
|
|
190
195
|
|
|
191
196
|
## Table of Contents
|
|
192
197
|
|
|
198
|
+
0. [Documentation](https://azus.ai/support)
|
|
193
199
|
1. [Privacy Mode](#-privacy-mode-local-sqlite)
|
|
194
200
|
2. [Ecosystem Mode](#-ecosystem-mode-azus-cloud)
|
|
195
201
|
3. [LLM Adapters](#-llm-adapters)
|
|
@@ -307,7 +313,7 @@ from pdm_memory.auth import JWTAuth
|
|
|
307
313
|
auth = JWTAuth(
|
|
308
314
|
token="eyJ...",
|
|
309
315
|
refresh_token="eyJ...",
|
|
310
|
-
refresh_url="https://api.azus.ai/api/v1/accounts/
|
|
316
|
+
refresh_url="https://api.azus.ai/api/v1/accounts/token/refresh/",
|
|
311
317
|
)
|
|
312
318
|
```
|
|
313
319
|
|
|
@@ -408,6 +414,18 @@ mem.ingest(
|
|
|
408
414
|
|
|
409
415
|
## 🛠️ Developer Tools
|
|
410
416
|
|
|
417
|
+
### Examples (DX walkthrough)
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
pip install .
|
|
421
|
+
python examples/hello_pdm.py # save / recall / explain
|
|
422
|
+
python examples/guarded_agent_logic.py # GAA: TORSION vs ALIGNED
|
|
423
|
+
python examples/handling_contradictions.py # detect + reconcile torsion
|
|
424
|
+
python examples/temporal_recall_demo.py # event_at + deadline (PDM-T)
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
See [`examples/README.md`](examples/README.md).
|
|
428
|
+
|
|
411
429
|
### The explain Method
|
|
412
430
|
|
|
413
431
|
```python
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://pypi.org/project/pdm-memory/)
|
|
5
5
|
[](https://github.com/westfield-innovations/pdm-memory/actions)
|
|
6
6
|
[](LICENSE)
|
|
7
|
+
[](https://azus.ai/support)
|
|
7
8
|
|
|
8
9
|
Your LLM forgets everything between conversations. The standard fix — stuff a vector database into the context window — is expensive, slow, and retrieves **what matches words, not what matters**.
|
|
9
10
|
|
|
@@ -13,12 +14,15 @@ Your LLM forgets everything between conversations. The standard fix — stuff a
|
|
|
13
14
|
- 🗄️ **Your storage.** One local file. Your data never leaves your machine. Check the source — there's no phone-home in it.
|
|
14
15
|
- ⚡ **Ten minutes.** `pip install pdm-memory` → three lines → persistent memory.
|
|
15
16
|
|
|
16
|
-
**
|
|
17
|
+
📖 **Documentation:** [azus.ai/support](https://azus.ai/support)
|
|
18
|
+
|
|
19
|
+
**Benchmarks vs standard RAG:** [azus.ai/pdm/benchmarks](https://azus.ai/pdm/benchmarks)
|
|
17
20
|
|
|
18
21
|
---
|
|
19
22
|
|
|
20
23
|
## Table of Contents
|
|
21
24
|
|
|
25
|
+
0. [Documentation](https://azus.ai/support)
|
|
22
26
|
1. [Privacy Mode](#-privacy-mode-local-sqlite)
|
|
23
27
|
2. [Ecosystem Mode](#-ecosystem-mode-azus-cloud)
|
|
24
28
|
3. [LLM Adapters](#-llm-adapters)
|
|
@@ -136,7 +140,7 @@ from pdm_memory.auth import JWTAuth
|
|
|
136
140
|
auth = JWTAuth(
|
|
137
141
|
token="eyJ...",
|
|
138
142
|
refresh_token="eyJ...",
|
|
139
|
-
refresh_url="https://api.azus.ai/api/v1/accounts/
|
|
143
|
+
refresh_url="https://api.azus.ai/api/v1/accounts/token/refresh/",
|
|
140
144
|
)
|
|
141
145
|
```
|
|
142
146
|
|
|
@@ -237,6 +241,18 @@ mem.ingest(
|
|
|
237
241
|
|
|
238
242
|
## 🛠️ Developer Tools
|
|
239
243
|
|
|
244
|
+
### Examples (DX walkthrough)
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pip install .
|
|
248
|
+
python examples/hello_pdm.py # save / recall / explain
|
|
249
|
+
python examples/guarded_agent_logic.py # GAA: TORSION vs ALIGNED
|
|
250
|
+
python examples/handling_contradictions.py # detect + reconcile torsion
|
|
251
|
+
python examples/temporal_recall_demo.py # event_at + deadline (PDM-T)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
See [`examples/README.md`](examples/README.md).
|
|
255
|
+
|
|
240
256
|
### The explain Method
|
|
241
257
|
|
|
242
258
|
```python
|
|
@@ -19,9 +19,20 @@ The public surface of the SDK:
|
|
|
19
19
|
See README.md for full documentation.
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
+
from pdm_memory.core.signature import DrawerInfo, MemoryHit
|
|
22
23
|
from pdm_memory.memory import Memory
|
|
23
|
-
from pdm_memory.
|
|
24
|
-
from pdm_memory.
|
|
25
|
-
|
|
26
|
-
__version__ = "0.
|
|
27
|
-
__all__ = [
|
|
24
|
+
from pdm_memory.models import AlignmentReport, SurfaceReport, TorsionReport
|
|
25
|
+
from pdm_memory.storage.factory import create_storage, register_storage
|
|
26
|
+
|
|
27
|
+
__version__ = "0.2.3"
|
|
28
|
+
__all__ = [
|
|
29
|
+
"AlignmentReport",
|
|
30
|
+
"DrawerInfo",
|
|
31
|
+
"Memory",
|
|
32
|
+
"MemoryHit",
|
|
33
|
+
"SurfaceReport",
|
|
34
|
+
"TorsionReport",
|
|
35
|
+
"__version__",
|
|
36
|
+
"create_storage",
|
|
37
|
+
"register_storage",
|
|
38
|
+
]
|
|
@@ -9,7 +9,7 @@ Manages Bearer token authentication for cloud storage requests.
|
|
|
9
9
|
Optionally handles refresh-token flows automatically on 401.
|
|
10
10
|
|
|
11
11
|
Usage:
|
|
12
|
-
auth = JWTAuth(token="eyJ...", refresh_token="eyJ...", refresh_url="https://api.azus.ai/api/v1/accounts/
|
|
12
|
+
auth = JWTAuth(token="eyJ...", refresh_token="eyJ...", refresh_url="https://api.azus.ai/api/v1/accounts/token/refresh/")
|
|
13
13
|
headers = auth.headers()
|
|
14
14
|
"""
|
|
15
15
|
|
|
@@ -17,7 +17,6 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import logging
|
|
19
19
|
import time
|
|
20
|
-
from typing import Dict, Optional
|
|
21
20
|
|
|
22
21
|
logger = logging.getLogger(__name__)
|
|
23
22
|
|
|
@@ -36,15 +35,15 @@ class JWTAuth:
|
|
|
36
35
|
def __init__(
|
|
37
36
|
self,
|
|
38
37
|
token: str,
|
|
39
|
-
refresh_token:
|
|
40
|
-
refresh_url:
|
|
38
|
+
refresh_token: str | None = None,
|
|
39
|
+
refresh_url: str | None = None,
|
|
41
40
|
expire_buffer: int = 60,
|
|
42
41
|
) -> None:
|
|
43
42
|
self._token = token
|
|
44
43
|
self._refresh_token = refresh_token
|
|
45
44
|
self._refresh_url = refresh_url
|
|
46
45
|
self._expire_buffer = expire_buffer
|
|
47
|
-
self._expires_at:
|
|
46
|
+
self._expires_at: float | None = self._decode_exp(token)
|
|
48
47
|
|
|
49
48
|
# ------------------------------------------------------------------
|
|
50
49
|
# Public API
|
|
@@ -54,7 +53,7 @@ class JWTAuth:
|
|
|
54
53
|
def token(self) -> str:
|
|
55
54
|
return self._token
|
|
56
55
|
|
|
57
|
-
def headers(self) ->
|
|
56
|
+
def headers(self) -> dict[str, str]:
|
|
58
57
|
"""Return Authorization headers for an HTTP request."""
|
|
59
58
|
return {"Authorization": f"Bearer {self._token}"}
|
|
60
59
|
|
|
@@ -93,19 +92,18 @@ class JWTAuth:
|
|
|
93
92
|
|
|
94
93
|
def ensure_fresh(self) -> None:
|
|
95
94
|
"""Refresh token if expired. Raises RuntimeError if refresh fails."""
|
|
96
|
-
if self.is_expired():
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
95
|
+
if self.is_expired() and not self.refresh():
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
"PDM cloud auth: access token is expired and could not be refreshed. "
|
|
98
|
+
"Please provide a new token via Memory(token=...)."
|
|
99
|
+
)
|
|
102
100
|
|
|
103
101
|
# ------------------------------------------------------------------
|
|
104
102
|
# Private
|
|
105
103
|
# ------------------------------------------------------------------
|
|
106
104
|
|
|
107
105
|
@staticmethod
|
|
108
|
-
def _decode_exp(token: str) ->
|
|
106
|
+
def _decode_exp(token: str) -> float | None:
|
|
109
107
|
"""Decode the 'exp' claim from a JWT without validating the signature."""
|
|
110
108
|
try:
|
|
111
109
|
import base64
|
|
@@ -13,8 +13,9 @@ suitable as a final gate before an agent ACT.
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import re
|
|
16
|
+
from collections.abc import Sequence
|
|
16
17
|
from dataclasses import dataclass
|
|
17
|
-
from typing import
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
18
19
|
|
|
19
20
|
from pdm_memory.core.math import calculate_intent_weight, infer_domain
|
|
20
21
|
from pdm_memory.core.signature import SignatureRecord
|
|
@@ -158,9 +159,9 @@ def select_goal_anchors(
|
|
|
158
159
|
*,
|
|
159
160
|
min_pressure: float = DEFAULT_MIN_PRESSURE,
|
|
160
161
|
k: int = DEFAULT_K_GOALS,
|
|
161
|
-
) ->
|
|
162
|
+
) -> list[SignatureRecord]:
|
|
162
163
|
"""High-pressure stewardship/foundational signatures ranked by IAW."""
|
|
163
|
-
pool:
|
|
164
|
+
pool: list[tuple[float, SignatureRecord]] = []
|
|
164
165
|
for rec in records:
|
|
165
166
|
if float(rec.p_magnitude or 0.0) < min_pressure:
|
|
166
167
|
continue
|
|
@@ -232,7 +233,7 @@ def _forbidden_after_negation(goal_text: str) -> set[str]:
|
|
|
232
233
|
|
|
233
234
|
|
|
234
235
|
def intent_goal_resonance(
|
|
235
|
-
engine:
|
|
236
|
+
engine: RetrievalEngine,
|
|
236
237
|
intent_text: str,
|
|
237
238
|
goal: SignatureRecord,
|
|
238
239
|
) -> float:
|
|
@@ -332,7 +333,7 @@ def _stem(token: str) -> str:
|
|
|
332
333
|
|
|
333
334
|
|
|
334
335
|
def verify_alignment(
|
|
335
|
-
engine:
|
|
336
|
+
engine: RetrievalEngine,
|
|
336
337
|
records: Sequence[SignatureRecord],
|
|
337
338
|
intent_text: str,
|
|
338
339
|
*,
|
|
@@ -345,6 +346,10 @@ def verify_alignment(
|
|
|
345
346
|
Compare a proposed intent to high-IAW goal anchors.
|
|
346
347
|
|
|
347
348
|
Fail-closed when no anchors exist (guarded agents must not ACT blind).
|
|
349
|
+
|
|
350
|
+
Resonance is self-weighted by ``(resonance × IAW)`` so unrelated
|
|
351
|
+
stewardship goals do not dilute a strongly matching intent. Peak
|
|
352
|
+
torsion is still taken across *all* anchors (fail-closed on danger).
|
|
348
353
|
"""
|
|
349
354
|
text = (intent_text or "").strip()
|
|
350
355
|
if not text:
|
|
@@ -365,7 +370,7 @@ def verify_alignment(
|
|
|
365
370
|
anchor_count=0,
|
|
366
371
|
)
|
|
367
372
|
|
|
368
|
-
scored:
|
|
373
|
+
scored: list[_AnchorScore] = []
|
|
369
374
|
for goal in anchors:
|
|
370
375
|
iaw = compute_iaw(goal)
|
|
371
376
|
resonance = intent_goal_resonance(engine, text, goal)
|
|
@@ -382,9 +387,16 @@ def verify_alignment(
|
|
|
382
387
|
)
|
|
383
388
|
)
|
|
384
389
|
|
|
385
|
-
# IAW-weighted
|
|
390
|
+
# IAW-weighted resonance that resists dilution from unrelated anchors:
|
|
391
|
+
# weight each goal by (resonance × IAW) so low-resonance stewardship
|
|
392
|
+
# goals (e.g. audit) do not tank a deploy/validate intent.
|
|
393
|
+
# Torsion still uses the peak across ALL anchors — fail-closed on danger.
|
|
386
394
|
iaw_sum = sum(s.iaw for s in scored) or 1.0
|
|
387
|
-
|
|
395
|
+
soft_sum = sum(s.resonance * s.iaw for s in scored)
|
|
396
|
+
if soft_sum > 1e-9:
|
|
397
|
+
resonance = sum(s.resonance * s.resonance * s.iaw for s in scored) / soft_sum
|
|
398
|
+
else:
|
|
399
|
+
resonance = sum(s.resonance * s.iaw for s in scored) / iaw_sum
|
|
388
400
|
peak = max(scored, key=lambda s: s.torsion)
|
|
389
401
|
torsion = peak.torsion
|
|
390
402
|
|
|
@@ -456,7 +468,7 @@ def _explain_conflict(
|
|
|
456
468
|
)
|
|
457
469
|
|
|
458
470
|
|
|
459
|
-
def _tokenize(text: str) ->
|
|
471
|
+
def _tokenize(text: str) -> list[str]:
|
|
460
472
|
words = _WORD_RE.findall((text or "").lower())
|
|
461
473
|
stop = {
|
|
462
474
|
"the", "and", "for", "how", "what", "that", "this", "with",
|
|
@@ -466,7 +478,7 @@ def _tokenize(text: str) -> List[str]:
|
|
|
466
478
|
return [w for w in words if w not in stop]
|
|
467
479
|
|
|
468
480
|
|
|
469
|
-
def _snip(text:
|
|
481
|
+
def _snip(text: str | None, max_len: int = 80) -> str:
|
|
470
482
|
cleaned = " ".join((text or "").split())
|
|
471
483
|
if not cleaned:
|
|
472
484
|
return "empty"
|
|
@@ -24,14 +24,12 @@ from __future__ import annotations
|
|
|
24
24
|
|
|
25
25
|
import math
|
|
26
26
|
import warnings
|
|
27
|
-
from typing import Dict, List, Optional
|
|
28
|
-
|
|
29
27
|
|
|
30
28
|
# ---------------------------------------------------------------------------
|
|
31
29
|
# Domain half-lives (ported from kernel.py DOMAIN_HALF_LIVES)
|
|
32
30
|
# ---------------------------------------------------------------------------
|
|
33
31
|
|
|
34
|
-
DOMAIN_HALF_LIVES:
|
|
32
|
+
DOMAIN_HALF_LIVES: dict[str, float] = {
|
|
35
33
|
"market_signal": 1.0, # 1 day
|
|
36
34
|
"pattern": 14.0, # 2 weeks
|
|
37
35
|
"structural": 90.0, # 3 months
|
|
@@ -80,7 +78,7 @@ def calculate_effective_spike(
|
|
|
80
78
|
return min(P_MAX, max(P_FLOOR, raw))
|
|
81
79
|
|
|
82
80
|
|
|
83
|
-
def resolve_half_life(domain:
|
|
81
|
+
def resolve_half_life(domain: str | None) -> float:
|
|
84
82
|
"""Map knowledge domain → half-life days (canonical decay clock)."""
|
|
85
83
|
if not domain:
|
|
86
84
|
return DEFAULT_HALF_LIFE
|
|
@@ -91,7 +89,7 @@ def calculate_decay_factor(
|
|
|
91
89
|
days_since_retrieved: float,
|
|
92
90
|
half_life: float = DEFAULT_HALF_LIFE,
|
|
93
91
|
*,
|
|
94
|
-
days_since_created:
|
|
92
|
+
days_since_created: float | None = None,
|
|
95
93
|
t_persistence: float = 0.0,
|
|
96
94
|
) -> float:
|
|
97
95
|
"""
|
|
@@ -132,8 +130,8 @@ def calculate_v(correct: int, total: int) -> float:
|
|
|
132
130
|
|
|
133
131
|
|
|
134
132
|
def calculate_intent_weight(
|
|
135
|
-
intent_tags:
|
|
136
|
-
query:
|
|
133
|
+
intent_tags: list[str],
|
|
134
|
+
query: str | None = None,
|
|
137
135
|
) -> float:
|
|
138
136
|
"""
|
|
139
137
|
Intent match weight: 0.8 base + 0.2 boost proportional to tag-query overlap.
|
|
@@ -199,7 +197,7 @@ def calculate_half_life_pressure(
|
|
|
199
197
|
t_persistence: float,
|
|
200
198
|
phase_privilege: float = 1.0,
|
|
201
199
|
*,
|
|
202
|
-
days_since_created:
|
|
200
|
+
days_since_created: float | None = None,
|
|
203
201
|
) -> tuple[float, float]:
|
|
204
202
|
"""
|
|
205
203
|
Project stored pressure after canonical half-life decay.
|
|
@@ -341,7 +339,7 @@ def calculate_temporal_geometry(
|
|
|
341
339
|
# ---------------------------------------------------------------------------
|
|
342
340
|
|
|
343
341
|
|
|
344
|
-
def infer_domain(tags:
|
|
342
|
+
def infer_domain(tags: list[str]) -> str:
|
|
345
343
|
"""Infer memory domain from intent tags."""
|
|
346
344
|
if not tags:
|
|
347
345
|
return "insight"
|
|
@@ -361,7 +359,7 @@ def infer_domain(tags: List[str]) -> str:
|
|
|
361
359
|
return "insight"
|
|
362
360
|
|
|
363
361
|
|
|
364
|
-
def infer_regime(tags:
|
|
362
|
+
def infer_regime(tags: list[str]) -> str:
|
|
365
363
|
"""Infer question regime from intent tags."""
|
|
366
364
|
tag_str = " ".join(tags).lower()
|
|
367
365
|
if any(k in tag_str for k in ["trade", "stock", "market", "price"]):
|