Skip to main content

Module injection

Module injection 

Source
Expand description

Engine-native injection attention (selection policy for context injection). Engine-native injection attention: retrieval shaped for context injection rather than raw search.

Plain top-k recall is the wrong contract for injecting memories into a model’s context: the most similar memories to a conversation are echoes of that conversation, top-k always returns k items however weak the tail, and near-duplicates (a distilled fact and the turn it came from) co-rank. This module owns the selection policy that client hooks previously approximated with heuristics:

  • Session provenance: memories originating from the querying session are never returned, they are in that context by construction.
  • A working-memory ledger (exclude_ids) supplied by the client, holding what was already delivered within the current context lifetime.
  • A relevance knee instead of a fixed floor: the candidate list is cut at the largest score gap, so weak tails vanish without a magic constant.
  • Maximal Marginal Relevance over embeddings, so each selected item adds information the previous ones did not.
  • Type quotas: distilled knowledge first, verbatim episodic capped, action notes never (they exist for distillation and session resume).
  • User-pinned scope:always memories bypass every quality gate.
  • Outcome learning: record_injection_outcome tracks shown vs used per memory; chronically ignored memories are demoted at selection time and used ones are reinforced.

Structs§

InjectionCandidate
One injection-ready memory with its selection metadata.
InjectionConfig
Tunables for injection attention selection.
InjectionQuery
A request for injection-ready context.

Enums§

SelectionReason
Why an item was selected, for introspection and client display.

Constants§

ATTR_INJECTION_SHOWN
Attribute key: how many times this memory was injected into a context.
ATTR_INJECTION_USED
Attribute key: how many times an injected memory was drawn on by the reply that followed.