Internals
dmf
Deterministic Memory Framework package.
AnalysisReport
dataclass
NLP feature envelope for a single conversation interaction.
Produced by the NLP Engine and consumed by the Scoring Engine. All
fields are mandatory except `raw_metadata`, which defaults to an empty
dict to avoid mutable default argument issues (PEP 557).
Attributes
----------
info_density : float
Information Density ($ID$) — ratio of semantic lemmas
(NOUN, VERB, ADJ, PROPN) to total token count. Range: [0.0, 1.0].
sentiment_abs : float
Absolute VADER compound sentiment score ($|S|$). Range: [0.0, 1.0].
entity_count : int
Count of named entities ($E$) recognised by spaCy's standard NER
(PERSON, ORG, GPE, …). Non-negative integer.
is_system_prompt : bool
True when this report describes the system prompt interaction.
Drives the `analyze_system_prompt` branch in NLPConfig.
latency_ms : float
Wall-clock time taken by the NLP pipeline to produce this report,
in milliseconds. Populated from ExecutionLatencyTimer.
semantic_divergence : float
Geometric divergence ($D$) of this interaction's embedding from the
sliding-window centroid: D = 1 − cosine_similarity(vector, centroid).
Range: [0.0, 2.0]. 0.0 = perfectly aligned with context; 2.0 =
diametrically opposed. Defaults to 0.0 for the first interaction
(no prior context) and for skipped system-prompt interactions.
Populated by InteractionPipeline; NLPEngine alone leaves
it at the default.
survival_score : float | None
Continuous Survival Score Ω ∈ (0, 1) computed by ScoringEngine
None until ``ScoringEngine.calculate_score`` has been called on
this report. Stamped in-place by the engine immediately after
rounding so callers always have the authoritative value on the
report itself.
status : SurvivalStatus | None
Categorical tier derived from Ω after scoring:
HEALTHY (Ω > 0.6), UNSTABLE (0.3 < Ω ≤ 0.6), CRITICAL (Ω ≤ 0.3).
None until ``ScoringEngine.calculate_score`` stamps it. None is
the correct sentinel for "not yet scored" — defaulting to CRITICAL
would conflate unscored reports with genuinely low-value ones.
raw_metadata : dict[str, Any]
Audit-level detail: POS tag counts, raw token list, intermediate
scores, and any other data needed for post-execution inspection.
Defaults to an empty dict when not supplied.
provenance : InteractionProvenance
Structured provenance metadata kept separate from raw NLP audit
detail. Defaults to an empty ``InteractionProvenance``.
signals : InteractionSignals
Structured conversational/pragmatic cues kept separate from the raw
audit trail so downstream policy can consume a stable schema.
topic_identity : str | None
Stable topic field extracted from the interaction when enough
structure is available. Used for memory-level conflict policies.
topic_value : str | None
Value expressed for ``topic_identity`` in this interaction, when a
stable value can be extracted.
is_query_like : bool
True when the interaction is primarily a query/request rather than
memory content. This is derived in the language adapter so memory
policy can stay language-agnostic.
is_ack_like : bool
True when the interaction is primarily an acknowledgement or light
reformulation rather than a new memory-bearing statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_density
|
float
|
See the function signature and surrounding type hints. |
required |
sentiment_abs
|
float
|
See the function signature and surrounding type hints. |
required |
entity_count
|
int
|
See the function signature and surrounding type hints. |
required |
is_system_prompt
|
bool
|
See the function signature and surrounding type hints. |
required |
latency_ms
|
float
|
See the function signature and surrounding type hints. |
required |
semantic_divergence
|
float
|
See the function signature and surrounding type hints. |
0.0
|
survival_score
|
float | None
|
See the function signature and surrounding type hints. |
None
|
status
|
SurvivalStatus | None
|
See the function signature and surrounding type hints. |
None
|
raw_metadata
|
dict[str, Any]
|
See the function signature and surrounding type hints. |
dict()
|
provenance
|
InteractionProvenance
|
See the function signature and surrounding type hints. |
InteractionProvenance()
|
signals
|
InteractionSignals
|
See the function signature and surrounding type hints. |
InteractionSignals()
|
topic_identity
|
str | None
|
See the function signature and surrounding type hints. |
None
|
topic_value
|
str | None
|
See the function signature and surrounding type hints. |
None
|
is_query_like
|
bool
|
See the function signature and surrounding type hints. |
False
|
is_ack_like
|
bool
|
See the function signature and surrounding type hints. |
False
|
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/models/analysis.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
to_dict()
Return a plain dictionary representation of this report.
Uses dataclasses.asdict() for a deep copy — safe to mutate the
result without affecting the original report. Enum fields are
converted to their ``.value`` string so the output is directly
JSON-serialisable without a custom encoder.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
See the return type annotation. |
Source code in dmf/models/analysis.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
to_json()
Return a JSON string representation of this report.
Produces human-readable output (indent=2) suitable for structured
logging and metadata persistence.
The output is guaranteed to be parseable by json.loads().
Returns:
| Type | Description |
|---|---|
str
|
See the return type annotation. |
Source code in dmf/models/analysis.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
ChromaLTMHook
Persistent vector LTM store with raw-record retrieval via ChromaDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
Chroma collection used for raw records. |
DEFAULT_LTM_COLLECTION_NAME
|
persist_directory
|
Path | str
|
Directory where Chroma persists local state. |
DEFAULT_LTM_CHROMA_PATH
|
distance_threshold
|
float
|
Maximum cosine distance accepted for recall hits. |
DEFAULT_LTM_DISTANCE_THRESHOLD
|
vector_config
|
VectorConfig | None
|
Optional embedding configuration for lazy indexing. |
None
|
embed_text
|
Callable[[str], ndarray] | None
|
Optional embedding function override. |
None
|
cards_enabled
|
bool
|
Whether to index projected auxiliary cards. |
False
|
cards_path
|
Path | str | None
|
Optional JSONL audit path for projected cards. |
None
|
card_store
|
JsonlMemoryCardStore | None
|
Optional prebuilt JSONL card store. |
None
|
cards_collection_name
|
str
|
Chroma collection used for projected cards. |
DEFAULT_LTM_CARDS_COLLECTION_NAME
|
Returns:
| Type | Description |
|---|---|
|
Chroma-backed LTM hook instance. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the persistence directory cannot be created. |
Warning
Chroma cosine distance is lower-is-better. The public
similarity_score exposed by hits is derived as 1.0 - distance
only for deterministic ordering diagnostics.
Source code in dmf/memory/chroma_ltm.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
card_store
property
Auxiliary JSONL card audit store, when configured.
Returns:
| Type | Description |
|---|---|
JsonlMemoryCardStore | None
|
Configured card store or |
archive(entry)
Index one evicted raw interaction record into ChromaDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
MemoryEntry
|
Working-memory entry selected for archival. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If raw-record or card metadata cannot be serialised. |
Source code in dmf/memory/chroma_ltm.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
clear()
Delete all indexed records from the raw-record collection.
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in dmf/memory/chroma_ltm.py
348 349 350 351 352 353 354 355 356 357 358 359 | |
count()
Return the number of indexed raw records in the collection.
Returns:
| Type | Description |
|---|---|
int
|
Indexed raw-record count. |
Source code in dmf/memory/chroma_ltm.py
337 338 339 340 341 342 343 344 345 346 | |
count_cards()
Return the number of indexed card records.
Returns:
| Type | Description |
|---|---|
int
|
Indexed card count, or 0 when cards are disabled. |
Source code in dmf/memory/chroma_ltm.py
295 296 297 298 299 300 301 302 303 304 305 306 | |
read_all()
Return all archived raw records ordered by interaction_id ascending.
Fetches every document from the main collection using
include=["metadatas"] and deserialises each entry via
_deserialize_raw_record. Records that fail deserialisation are
silently skipped.
Returns:
| Type | Description |
|---|---|
list[RawLTMRecord]
|
Deserialisable raw records sorted by interaction id. |
Warning
Malformed records are skipped to keep recall resilient to partial writes or older metadata schemas.
Source code in dmf/memory/chroma_ltm.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
search_cards(query_vector, k=5)
Retrieve the top-k most relevant card hits by vector similarity.
Each returned :class:RawRecallHit points to the raw source record
that the matching card was projected from. If the source record is no
longer present in the main collection the card hit is silently skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_vector
|
list[float]
|
Query embedding in the same vector space as indexed cards. |
required |
k
|
int
|
Maximum number of card hits requested. |
5
|
Returns:
| Type | Description |
|---|---|
list[RawRecallHit]
|
Raw hits corresponding to the source records of matching cards. |
Source code in dmf/memory/chroma_ltm.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
search_raw(query_vector, k=5)
Retrieve the top-k most relevant raw records by vector similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_vector
|
list[float]
|
Query embedding in the same vector space as indexed raw records. |
required |
k
|
int
|
Maximum number of raw hits requested. |
5
|
Returns:
| Type | Description |
|---|---|
list[RawRecallHit]
|
Raw hits under the configured distance threshold. |
Source code in dmf/memory/chroma_ltm.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
EmbeddingEngine
Converts text to L2-normalised dense vectors via FastEmbed.
The underlying TextEmbedding model is loaded lazily on the first call
to get_embedding(), not at construction time. Only configuration is
stored initially so heavy I/O is deferred until the engine is used.
Attributes
----------
_config : VectorConfig
Immutable configuration (model name, expected dimension, cache path).
_model : TextEmbedding | None
FastEmbed model instance. None until the first get_embedding() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
VectorConfig
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/analysis/embedding_engine.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
get_embedding(text)
Return the L2-normalised embedding vector for text.
Triggers model loading on the first invocation; subsequent calls
reuse the already-loaded model with no additional I/O.
Parameters
----------
text : str
Raw text to embed.
Returns
-------
np.ndarray
1-D array of shape (vector_dim,) with unit L2 norm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/analysis/embedding_engine.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
FileLTMHook
Append-only JSONL archive for raw long-term-memory records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_path
|
Path | str
|
Filesystem path for the raw-record JSONL archive. |
required |
cards_enabled
|
bool
|
Whether to project auxiliary memory cards on archive. |
False
|
cards_path
|
Path | str | None
|
Optional JSONL path for auxiliary cards. |
None
|
card_store
|
JsonlMemoryCardStore | None
|
Optional prebuilt card store. Takes precedence over
|
None
|
Returns:
| Type | Description |
|---|---|
|
File-backed LTM hook instance. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the archive parent directory cannot be created. |
Warning
search_raw intentionally returns an empty list. This backend is
archival-only; semantic retrieval requires a vector-backed hook.
Source code in dmf/memory/ltm_engine.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
card_store
property
Auxiliary JSONL card audit store, when configured.
Returns:
| Type | Description |
|---|---|
JsonlMemoryCardStore | None
|
Configured card store or |
path
property
Filesystem path of the JSONL archive.
Returns:
| Type | Description |
|---|---|
Path
|
Configured raw-record archive path. |
archive(entry)
Append one raw record and optional auxiliary cards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
MemoryEntry
|
Working-memory entry selected for archival. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the archive cannot be written. |
TypeError
|
If the raw record cannot be JSON-serialised. |
Source code in dmf/memory/ltm_engine.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
read_all()
Return all archived raw records in insertion order.
Reads the JSONL archive line by line and deserialises each record. Returns an empty list when the archive file does not yet exist.
Returns:
| Type | Description |
|---|---|
list[RawLTMRecord]
|
Raw records in file order. |
Raises:
| Type | Description |
|---|---|
OSError
|
If the archive exists but cannot be read. |
JSONDecodeError
|
If a non-empty line is not valid JSON. |
KeyError
|
If a raw-record payload is missing required fields. |
Source code in dmf/memory/ltm_engine.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
search_raw(query_vector, k=DEFAULT_LTM_RECALL_LIMIT)
Return no raw search hits for this archival-only backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_vector
|
list[float]
|
Ignored query embedding. |
required |
k
|
int
|
Ignored hit limit. |
DEFAULT_LTM_RECALL_LIMIT
|
Returns:
| Type | Description |
|---|---|
list[RawRecallHit]
|
Empty list. |
Source code in dmf/memory/ltm_engine.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
InteractionMatrix
Sliding-window container for recent interaction embedding vectors.
Backed by a ``collections.deque`` with ``maxlen=config.window_size``.
When the window is full, appending a new vector automatically evicts
the oldest entry (FIFO) — no manual bookkeeping required.
The centroid is maintained as a **stateful, L2-normalised** attribute
(``_current_centroid``) that is recomputed only inside ``add_vector``
after the deque is updated. ``get_centroid()`` is therefore an O(1)
read with no recomputation. L2 normalisation projects the mean vector
back onto the unit hypersphere, ensuring that divergence comparisons
remain pure angular measurements.
Attributes
----------
_config : VectorConfig
Immutable configuration (only ``window_size`` is used here).
_vectors : deque[np.ndarray]
Bounded deque of the most recent embedding vectors.
_current_centroid : np.ndarray | None
Cached, L2-normalised centroid of the current window. None when
the window is empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
VectorConfig
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/analysis/geometry.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
is_empty
property
True when the window contains no vectors.
Returns:
| Type | Description |
|---|---|
bool
|
See the return type annotation. |
size
property
Number of vectors currently in the sliding window.
Returns:
| Type | Description |
|---|---|
int
|
See the return type annotation. |
window_size
property
Maximum capacity of the sliding window (from config).
Returns:
| Type | Description |
|---|---|
int
|
See the return type annotation. |
add_vector(vector)
Append vector to the window and return its divergence score.
Execution order (critical for correctness):
1. Compute divergence D against the **previous** centroid — this
measures how far the new interaction departs from the existing
context *before* it becomes part of that context.
2. Append the new vector to the deque (may evict the oldest).
3. Recompute and L2-normalise the centroid from the updated window.
On the very first call (empty window) divergence is defined as
0.0 because there is no prior context to diverge from.
Parameters
----------
vector : np.ndarray
L2-normalised embedding vector for the new interaction.
Returns
-------
float
Semantic divergence D ∈ [0.0, 2.0].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
ndarray
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/analysis/geometry.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
from_dmf_config(config)
classmethod
Construct an InteractionMatrix from a universal DMFConfig.
Uses ``nlp.vector_dim`` and ``capacity.window_size`` from the TOML.
Translation map
---------------
==================== ====================== ===================
TOML key DMFConfig path VectorConfig field
==================== ====================== ===================
nlp.vector_dim config.nlp.vector_dim vector_dim
capacity.window_size config.capacity.window_size window_size
==================== ====================== ===================
Parameters
----------
config : DMFConfig
Fully populated config object returned by ``load_dmf_config()``.
Returns
-------
InteractionMatrix
Fully initialised instance with an empty sliding window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DMFConfig
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/analysis/geometry.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
get_centroid()
Return the cached, L2-normalised centroid (O(1) read).
Returns
-------
np.ndarray | None
Unit-length centroid of the current window, or None when the
window is empty.
Source code in dmf/analysis/geometry.py
261 262 263 264 265 266 267 268 269 270 271 272 273 | |
remove_vector(vector)
Remove a specific vector from the sliding window by object identity.
Comparison uses Python's ``is`` operator (object identity), not
element-wise numpy equality. This is safe because the same
``np.ndarray`` object is stored on both the ``MemoryEntry`` and
this deque — ``add_vector`` receives the reference and appends it
directly without copying.
If the vector is no longer in the window (evicted by FIFO overflow
because more than ``window_size`` interactions arrived since it was
added), this is a no-op and returns ``False``.
After removal the centroid is recomputed from the remaining vectors.
If the window becomes empty, the centroid is reset to ``None``.
Parameters
----------
vector : np.ndarray
The exact array object to remove (identity comparison).
Returns
-------
bool
``True`` if the vector was found and removed; ``False`` if it
was not in the current window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
ndarray
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/analysis/geometry.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
InteractionPipeline
Full-pipeline coordinator for a single conversation session.
Owns one instance each of NLPEngine, EmbeddingEngine, and
InteractionMatrix for the lifetime of the session. Callers interact
only through analyze_interaction(); the internal routing is opaque.
Attributes
----------
_nlp_config : NLPConfig
Immutable NLP configuration forwarded to NLPEngine.
_vector_config : VectorConfig
Immutable vector configuration forwarded to EmbeddingEngine and
InteractionMatrix.
_nlp_engine : NLPEngine
Extracts ID, |S|, E from raw text via spaCy + VADER.
_embedding_engine : EmbeddingEngine
Converts text to an L2-normalised dense vector.
FastEmbed model is loaded lazily on the first get_embedding() call.
_interaction_matrix : InteractionMatrix
Maintains the sliding-window centroid and computes D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nlp_config
|
NLPConfig
|
See the function signature and surrounding type hints. |
required |
vector_config
|
VectorConfig
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/runtime/pipeline.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
analyze_interaction(text, is_system=False, provenance=None)
Process text through the full pipeline and return an enriched report.
Steps
-----
1. NLP extraction (always runs, except for gated system prompts).
2. Early return if the interaction was skipped by NLPEngine gating:
``semantic_divergence`` remains at its default of 0.0.
3. Embedding: convert text to a unit vector via FastEmbed.
4. Geometry: compute divergence D and update the sliding window.
5. Stamp ``semantic_divergence`` onto the report and return.
Parameters
----------
text : str
Raw interaction text (user message, assistant turn, etc.).
is_system : bool
True when processing the system prompt. Combined with
``NLPConfig.analyze_system_prompt``, controls whether the
system prompt is gated or fully analysed.
provenance : InteractionProvenance | None
Optional structured provenance metadata supplied by the caller.
The pipeline copies it onto the returned report without adding
adapter-specific heuristics.
Returns
-------
AnalysisReport
Fully enriched report with ID, |S|, E, D, latency_ms, and
raw_metadata populated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
See the function signature and surrounding type hints. |
required |
is_system
|
bool
|
See the function signature and surrounding type hints. |
False
|
provenance
|
InteractionProvenance | None
|
See the function signature and surrounding type hints. |
None
|
Source code in dmf/runtime/pipeline.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
analyze_interaction_with_vector(text, is_system=False, provenance=None)
Process text and also return the canonical embedding used.
This is the public boundary for callers that need both the enriched
``AnalysisReport`` and the exact vector stamped into the session
geometry. It avoids re-embedding the same text out-of-band.
Returns
-------
tuple[AnalysisReport, np.ndarray | None]
``(report, vector)`` for normal turns; ``vector`` is ``None``
when the interaction was skipped by system-prompt gating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
See the function signature and surrounding type hints. |
required |
is_system
|
bool
|
See the function signature and surrounding type hints. |
False
|
provenance
|
InteractionProvenance | None
|
See the function signature and surrounding type hints. |
None
|
Source code in dmf/runtime/pipeline.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
from_dmf_config(config, *, analyze_system_prompt=None)
classmethod
Construct an InteractionPipeline from the universal DMFConfig.
Parameters
----------
config : DMFConfig
Fully populated config object returned by ``load_dmf_config()``.
analyze_system_prompt : bool | None
Optional override for ``NLPConfig.analyze_system_prompt``.
When ``None``, the ``NLPConfig`` default is preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DMFConfig
|
See the function signature and surrounding type hints. |
required |
analyze_system_prompt
|
bool | None
|
See the function signature and surrounding type hints. |
None
|
Returns:
| Type | Description |
|---|---|
InteractionPipeline
|
See the return type annotation. |
Source code in dmf/runtime/pipeline.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
NLPEngine
Deterministic NLP feature extractor for DMF interactions.
Loads a spaCy model and VADER once at construction time and reuses
them across all calls, avoiding per-interaction model loading.
Attributes are prefixed with _ to signal they are implementation
details; callers interact only through analyze_interaction().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
NLPConfig
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/analysis/nlp_engine.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
analyze_interaction(text, is_system=False)
Extract NLP features from a single interaction text.
When is_system=True and config.analyze_system_prompt=False, the
system prompt is intentionally skipped and neutral weights (0.0)
are returned. This prevents the system prompt's style (e.g.
"be assertive") from polluting content-based scoring.
Parameters
----------
text : str
Raw interaction content to analyse.
is_system : bool
True if this text comes from the system prompt role.
Returns
-------
AnalysisReport
Populated with ID, |S|, E, latency_ms, and raw_metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
See the function signature and surrounding type hints. |
required |
is_system
|
bool
|
See the function signature and surrounding type hints. |
False
|
Source code in dmf/analysis/nlp_engine.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
ScoringEngine
Computes the Survival Score Ω for a single AnalysisReport.
Constructed once with an immutable ScoringConfig and reused across
all interactions in a session.
Attributes
----------
_config : ScoringConfig
Immutable weight and sigmoid parameters. Read once at construction
time and never mutated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ScoringConfig
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Source code in dmf/analysis/scoring_engine.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
calculate_score(report, text='')
Compute the Survival Score Ω for report.
Steps
-----
1. Normalise entity count: E_norm = min(E, E_cap) / E_cap.
2. Compute weighted content logit.
3. Compute weighted operational logit from conversational signals.
4. Compute provenance logit from structured provenance metadata.
5. Apply a single shifted sigmoid to the total logit.
6. Social Floor: if Ω < social_threshold and *text* is a social
cue, boost Ω to at least min_social_score.
7. Round to 4 decimal places.
8. Stamp *report* in-place: set ``report.survival_score = Ω`` and
classify ``report.status`` using runtime thresholds so the report
always carries its own authoritative score and tier.
Parameters
----------
report : AnalysisReport
Fully populated report carrying ID, |S|, E, and D.
text : str
Original interaction text. Required for Social Floor
detection (keyword matching). When empty the Social Floor
is skipped, preserving backward compatibility.
Returns
-------
float
Survival Score Ω ∈ (0, 1), rounded to 4 decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
AnalysisReport
|
See the function signature and surrounding type hints. |
required |
text
|
str
|
See the function signature and surrounding type hints. |
''
|
Source code in dmf/analysis/scoring_engine.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
from_dmf_config(config)
classmethod
Construct a ScoringEngine from a universal DMFConfig.
Translates the human-readable TOML field names (``alpha_density``,
``beta_entities``, …) to the internal ``ScoringConfig`` Greek-letter
fields, preserving the existing constructor signature and all tests.
Translation map
---------------
======================== ======================== ===================
TOML key DMFConfig path ScoringConfig field
======================== ======================== ===================
scoring_weights.alpha_density scoring.alpha_density alpha
scoring_weights.beta_entities scoring.beta_entities gamma
scoring_weights.gamma_sentiment scoring.gamma_sentiment beta
scoring_weights.delta_technical scoring.delta_technical delta
scoring_weights.sigmoid_midpoint scoring.sigmoid_midpoint x0
scoring_weights.entity_cap scoring.entity_cap e_cap
scoring_weights.social_threshold scoring.social_threshold social_threshold
scoring_weights.min_social_score scoring.min_social_score min_social_score
======================== ======================== ===================
Note: ``beta_entities`` maps to ``ScoringConfig.gamma`` (entity
weight) and ``gamma_sentiment`` maps to ``ScoringConfig.beta``
(sentiment weight). The TOML uses signal-descriptive names;
the internal config uses Greek letters matching the formula.
Parameters
----------
config : DMFConfig
Fully populated config object returned by ``load_dmf_config()``.
Returns
-------
ScoringEngine
Fully initialised instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DMFConfig
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/analysis/scoring_engine.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
TemporalMemory
Active context window manager with temporal decay and eviction.
Parameters
----------
decay_config : DecayConfig | None
Immutable decay/budget parameters. Defaults to ``DecayConfig()``.
vector_config : VectorConfig | None
Immutable geometry parameters. Defaults to ``VectorConfig()``.
ltm_hook : LTMHook | None
Archive sink for evicted entries. Defaults to ``NullLTMHook()``
(silent discard). Pass a recording or concrete LTM hook for
testing or production use.
Attributes
----------
queue : deque[MemoryEntry]
Working-memory entries ordered oldest → newest. Length is
unbounded; ``token_budget`` is enforced by ``prune_to_budget``.
matrix : InteractionMatrix
Sliding-window centroid tracker. Receives the same vectors as
the queue so divergence calculations reflect recent context.
config : DecayConfig
Immutable decay and budget configuration.
No local summary is maintained. Historical context is recovered only
through raw-LTM recall.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decay_config
|
DecayConfig | None
|
See the function signature and surrounding type hints. |
None
|
pruning_priority_config
|
PruningPriorityConfig | None
|
See the function signature and surrounding type hints. |
None
|
vector_config
|
VectorConfig | None
|
See the function signature and surrounding type hints. |
None
|
ltm_hook
|
LTMHook | None
|
See the function signature and surrounding type hints. |
None
|
nlp_engine
|
NLPEngine | None
|
See the function signature and surrounding type hints. |
None
|
Returns:
| Type | Description |
|---|---|
|
Instance of this class. |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised by class validation or initialization. |
ValueError
|
Raised by class validation or initialization. |
Source code in dmf/memory/temporal_memory.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 | |
is_empty
property
True when the working memory queue contains no entries.
Returns:
| Type | Description |
|---|---|
bool
|
See the return type annotation. |
ltm_hook
property
The configured LTM archive hook.
Returns:
| Type | Description |
|---|---|
LTMHook
|
See the return type annotation. |
next_id
property
The interaction_id that will be assigned to the next insertion.
Returns:
| Type | Description |
|---|---|
int
|
See the return type annotation. |
size
property
Number of entries currently in the working memory queue.
Returns:
| Type | Description |
|---|---|
int
|
See the return type annotation. |
add_interaction(text, report, vector)
Insert a new interaction and enforce cleanup policies.
Execution order
---------------
1. Tokenise ``text`` via tiktoken (cached on entry).
2. Assign monotonic ``interaction_id``, increment ``_next_id``.
3. Update ``InteractionMatrix`` with the new vector.
4. Construct ``MemoryEntry``, append to queue.
5. Increment turn counter.
6. If turn counter is a multiple of ``pruning_frequency``:
run ``periodic_cleanup`` (hard-kill sweep).
7. If ``get_total_tokens() > token_budget``:
run ``prune_to_budget`` (pressure eviction).
The returned entry is guaranteed to be in the queue at the time
of return. In extreme cases where the entry's own Ω is very low
and a cascading eviction empties all other candidates, the entry
may theoretically be evicted in the same call — this is correct
behaviour and is guarded against in the test suite.
Returns
-------
MemoryEntry
The newly created entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
See the function signature and surrounding type hints. |
required |
report
|
AnalysisReport
|
See the function signature and surrounding type hints. |
required |
vector
|
ndarray
|
See the function signature and surrounding type hints. |
required |
Source code in dmf/memory/temporal_memory.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
contextualize_raw_recall_hits(hits, *, active_guard=None)
Run recall-time NLP on raw recall hits.
Storage returns raw records only. Conversational interpretation
belongs to the active-memory orchestration layer so the current
NLP engine can be applied consistently to recalled content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hits
|
list[RawRecallHit]
|
See the function signature and surrounding type hints. |
required |
active_guard
|
_ActiveContextGuard | None
|
See the function signature and surrounding type hints. |
None
|
Returns:
| Type | Description |
|---|---|
list[ContextualizedRecallCandidate]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |
from_dmf_config(config, ltm_hook=None, nlp_engine=None)
classmethod
Construct a TemporalMemory from a universal DMFConfig.
This factory bridges the TOML-loaded ``DMFConfig`` to
the typed internal dataclasses (``DecayConfig``, ``VectorConfig``)
without changing the existing constructor signature or breaking any
existing test.
Translation map
---------------
====================== ======================== =====================
TOML key DMFConfig path DecayConfig / VectorConfig field
====================== ======================== =====================
temporal_decay.lambda_base decay.lambda_base lambda_decay
temporal_decay.inertia_strength decay.inertia_strength inertia_strength
temporal_decay.hard_kill_threshold decay.hard_kill_threshold hard_kill_threshold
memory_tiers.critical_max tiers.critical_max critical_threshold
memory_tiers.healthy_min tiers.healthy_min healthy_threshold
capacity.token_budget capacity.token_budget token_budget
capacity.pruning_frequency_x capacity.pruning_frequency_x pruning_frequency
pruning_priority.rho_* pruning_priority.* PruningPriorityConfig
nlp.vector_dim nlp.vector_dim VectorConfig.vector_dim
capacity.window_size capacity.window_size VectorConfig.window_size
ltm.enabled + storage_type="file" ltm.* → FileLTMHook(storage_path)
ltm.enabled + storage_type="chroma" ltm.* → ChromaLTMHook(...)
ltm.enabled + storage_type="null" ltm.* → NullLTMHook
ltm.enabled=false ltm.* → NullLTMHook
====================== ======================== =====================
Parameters
----------
config : DMFConfig
Fully populated config object returned by ``load_dmf_config()``.
ltm_hook : LTMHook | None
Archive sink for evicted entries. Defaults to ``NullLTMHook()``.
nlp_engine : NLPEngine | None
Optional NLP engine reused for recall-time contextualization of
raw LTM hits.
Returns
-------
TemporalMemory
Fully initialised instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DMFConfig
|
See the function signature and surrounding type hints. |
required |
ltm_hook
|
LTMHook | None
|
See the function signature and surrounding type hints. |
None
|
nlp_engine
|
NLPEngine | None
|
See the function signature and surrounding type hints. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when validation fails or an invariant is violated. |
Source code in dmf/memory/temporal_memory.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
get_active_raw_records()
Return visible active entries as raw records for retrieval.
Structured retrieval can use these records alongside archived LTM
records. This keeps still-active memories searchable without changing
the raw-LTM archival contract.
Returns:
| Type | Description |
|---|---|
list[RawLTMRecord]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |
get_context_metrics()
Return a snapshot of the latest context reconstruction metrics.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 | |
get_effective_state()
Return the decay-adjusted state of every entry in the queue.
For each entry computes:
Δn = (_next_id − 1) − entry.interaction_id
Ω_eff = calculate_effective_score(Ω, Δn, λ, η)
The most recently added entry always has Δn = 0 → Ω_eff = Ω.
Returns
-------
list[dict[str, Any]]
One dict per entry, ordered oldest → newest. Keys:
``interaction_id``, ``text``, ``omega``, ``omega_eff``,
``delta_n``, ``token_count``, ``status_effective``,
``timestamp``.
Source code in dmf/memory/temporal_memory.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
get_full_context(query_vector=None)
Assemble the complete context string for LLM prompt injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_vector
|
ndarray | None
|
See the function signature and surrounding type hints. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
get_raw_recall_hits(query_vector, k=None, *, active_guard=None)
Fetch raw recall hits from the configured LTM hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_vector
|
ndarray
|
See the function signature and surrounding type hints. |
required |
k
|
int | None
|
See the function signature and surrounding type hints. |
None
|
active_guard
|
_ActiveContextGuard | None
|
See the function signature and surrounding type hints. |
None
|
Returns:
| Type | Description |
|---|---|
list[RawRecallHit]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |
get_recall_diagnostics()
Return a snapshot of the latest recall diagnostics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 | |
get_total_tokens()
Return the total token count across all entries in the queue.
O(N) sum over pre-calculated integers — no tokenisation on hot path.
Returns:
| Type | Description |
|---|---|
int
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
588 589 590 591 592 593 594 595 596 597 598 599 | |
periodic_cleanup()
Hard-kill sweep: evict any entry with Ω_eff < hard_kill_threshold.
Unlike ``prune_to_budget``, this sweep applies to **all** entries
including HEALTHY messages that have organically decayed to near-zero.
It runs every ``config.pruning_frequency`` turns (triggered by
``add_interaction``).
A HEALTHY message (Ω = 0.85) reaches the default hard-kill floor
(0.05) at Δn ≈ 141 turns. The periodic sweep removes these stale
entries from active memory before they accumulate and inflate the
token budget.
Returns
-------
list[MemoryEntry]
All entries evicted in this sweep, in queue order.
Source code in dmf/memory/temporal_memory.py
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 | |
prune_to_budget()
Evict lowest-priority entries until total tokens ≤ token_budget.
Eviction policy
---------------
1. Compute the full priority list via ``_get_pruning_candidates``.
2. Remove the head of the list (oldest CRITICAL, else oldest
UNSTABLE) from the queue.
3. Sync ``InteractionMatrix`` by removing the same vector object.
4. Archive the evicted entry via ``LTMHook.archive``.
5. Repeat until ``get_total_tokens() ≤ config.token_budget`` or
no candidates remain.
If only HEALTHY messages remain and the budget is still exceeded,
the loop exits without evicting them. This is intentional —
HEALTHY messages are protected by design. The budget deficit is
logged via the return value for the caller to handle.
Returns
-------
list[MemoryEntry]
All entries evicted in this call, in eviction order.
Source code in dmf/memory/temporal_memory.py
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 | |
rerank_contextualized_recall_candidates(candidates)
Apply deterministic selection and suppression to raw recall candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
list[ContextualizedRecallCandidate]
|
See the function signature and surrounding type hints. |
required |
Returns:
| Type | Description |
|---|---|
list[ContextualizedRecallCandidate]
|
See the return type annotation. |
Source code in dmf/memory/temporal_memory.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | |