Expand description
D-MEM RPE-based tiered graph extraction routing.
Computes a heuristic “reward prediction error” (RPE) signal for each incoming turn. Low-RPE turns (predictable, topically continuous, no new entities) skip the expensive MAGMA LLM extraction pipeline. High-RPE turns proceed to full extraction.
§RPE formula
RPE = 0.5 * (1 - max_cosine_similarity) + 0.5 * entity_novelty_ratioWhere:
max_cosine_similarity= max cosine similarity between current turn embedding and last N turn embeddings. High = topically predictable.entity_novelty_ratio= fraction of candidate entity names not seen in recent history. 0.0 if no entities extracted.
§Safety valve
To prevent unbounded skipping, consecutive_skips is tracked. When it reaches
max_skip_turns, extraction is forced regardless of RPE score.
Structs§
- RpeRouter
- Stateful RPE router. Tracks recent embeddings and entity history.
- RpeSignal
- RPE computation result for a single turn.
Constants§
- RPE_
EMBEDDING_ BUFFER_ SIZE - Maximum number of recent turn embeddings to keep for context similarity computation.
Functions§
- extract_
candidate_ entities - Extract candidate entity names from text using simple heuristics.