Skip to main content

Module rpe

Module rpe 

Source
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_ratio

Where:

  • 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.