lore_amplifier

Lore Memory Amplifier – boosts lore-tier KG retrieval weight. # 💀🔥

When active, overrides _PRIORITY_NORM["lore"] from 0.0 -> 0.8 and triples the per-scope lore entity cap (20 -> 60), making lore memories actually visible in the retrieval pipeline instead of being systematically suppressed by the tiered scoring system.

Toggle is per-channel via Redis or auto-activated when the Entrainment Loopfield detects a user_is_baby target.

Redis key: star:lore_amp:{platform}:{channel_id}

async lore_amplifier.is_amplified(redis, platform, channel_id, config=None, user_id=None)[source]

Report whether the Lore Memory Amplifier is active for a channel.

Resolves the effective amplifier state by combining global config gates with the per-channel Redis toggle: it short-circuits to False when the amplifier is globally disabled or when feature_toggles.is_absolute_bypass fires for the user/channel, then otherwise reads the channel’s flag from Redis via _channel_key(). Failures are swallowed and logged so a Redis hiccup can never crash retrieval – the safe default is “not amplified”.

Called by prompt_context.py while assembling KG retrieval context (to decide whether lore-tier memories get boosted priority/cap), and exercised extensively by tests/test_absolute_overrides.py.

Parameters:
  • redis (Redis | None) – Async Redis client, or None when Redis is unavailable (which forces a False result).

  • platform (str) – Platform identifier used to build the channel key.

  • channel_id (str) – Channel identifier used to build the channel key.

  • config (Config | None) – Optional Config; when supplied, enables the global-disable and absolute-bypass checks.

  • user_id (str | int | None) – Optional user identifier consulted by the absolute-bypass check.

Returns:

True only when the channel’s Redis flag is set to a truthy value (1/true/yes/on) and no gate suppressed it; False otherwise, including on any error.

Return type:

bool

async lore_amplifier.set_amplified(redis, platform, channel_id, active)[source]

Persist the Lore Memory Amplifier toggle for a channel in Redis.

Writes (or clears) the per-channel flag read back by is_amplified(). When active is true it does a SET of the _channel_key() to "1"; when false it DELETEs the key entirely so the channel falls back to the default (suppressed) lore behavior. No expiry is set, so the toggle is sticky until explicitly turned off.

Called by the lore amp admin command handler in message_processor/processor.py, which then reports the new ACTIVE/INACTIVE state back to the channel.

Parameters:
  • redis (Redis) – Async Redis client used to store the flag.

  • platform (str) – Platform identifier used to build the channel key.

  • channel_id (str) – Channel identifier used to build the channel key.

  • active (bool) – True to enable amplification (writes the key), False to disable it (deletes the key).

Return type:

None

Returns:

None.

lore_amplifier.get_lore_priority(amplified)[source]

Select the lore-tier priority weight for the current amplifier state.

Maps the boolean amplifier flag to the scoring weight the KG retrieval pipeline applies to lore-tier entities: the boosted LORE_AMPLIFIED_PRIORITY (0.8, guild-equivalent visibility) when amplified, otherwise the suppressed LORE_DEFAULT_PRIORITY (0.0). Pure lookup with no side effects.

A thin accessor that pairs with get_lore_cap(); no in-repo callers reference it directly (knowledge_graph/retrieval.py currently inlines the equivalent amplified-cap logic), so treat it as part of the module’s public surface for retrieval integration.

Parameters:

amplified (bool) – Whether the Lore Memory Amplifier is active for the scope.

Returns:

The lore priority weight to use in retrieval scoring.

Return type:

float

lore_amplifier.get_lore_cap(amplified)[source]

Select the per-scope lore entity cap for the current amplifier state.

Maps the boolean amplifier flag to how many lore-tier entities may be kept per scope during retrieval: the tripled LORE_AMPLIFIED_CAP (60) when amplified, otherwise the default LORE_DEFAULT_CAP (20). Pure lookup with no side effects.

A thin accessor mirroring get_lore_priority(); no in-repo callers reference it directly (knowledge_graph/retrieval.py currently inlines the 60-vs-default cap choice), so treat it as part of the module’s public surface for retrieval integration.

Parameters:

amplified (bool) – Whether the Lore Memory Amplifier is active for the scope.

Returns:

The maximum number of lore-tier entities to retain per scope.

Return type:

int