mixle.experimental.typed_runtime.context_attention moduleΒΆ

Node-, token-, and compute-bounded attention over materialized context tokens.

class AttentionCandidate(node_id, key, value, position, token_ids, tokenizer_id, materialized_content_hash)[source]

Bases: object

One graph node with retrieval vectors and content-bound materialized token IDs.

Parameters:
property measured_token_count: int

Token work derived from the materialized token-ID sequence.

class ContextAttentionConfig(tokenizer_id, exact_near_tokens=4096, exact_near_nodes=64, retrieved_nodes=32, maximum_active_tokens=8192, maximum_active_nodes=96, maximum_scored_nodes=4096, maximum_attention_elements=1000000, temperature=1.0)[source]

Bases: object

Hard bounds and the tokenizer identity used by materialized token sequences.

Parameters:
  • tokenizer_id (str)

  • exact_near_tokens (int)

  • exact_near_nodes (int)

  • retrieved_nodes (int)

  • maximum_active_tokens (int)

  • maximum_active_nodes (int)

  • maximum_scored_nodes (int)

  • maximum_attention_elements (int)

  • temperature (float)

class ContextAttentionReceipt(tokenizer_id, source_nodes, source_horizon_tokens, maximum_scored_nodes, maximum_attention_elements, maximum_active_nodes, maximum_active_tokens, scored_nodes, scoring_elements, exact_node_ids, retrieved_node_ids, active_nodes, active_tokens, active_token_counts, excluded_unverified_generated, similarities)[source]

Bases: object

Selected nodes plus measured, independently bounded token and vector work.

Parameters:
  • tokenizer_id (str)

  • source_nodes (int)

  • source_horizon_tokens (int | None)

  • maximum_scored_nodes (int)

  • maximum_attention_elements (int)

  • maximum_active_nodes (int)

  • maximum_active_tokens (int)

  • scored_nodes (int)

  • scoring_elements (int)

  • exact_node_ids (tuple[str, ...])

  • retrieved_node_ids (tuple[str, ...])

  • active_nodes (int)

  • active_tokens (int)

  • active_token_counts (tuple[tuple[str, int], ...])

  • excluded_unverified_generated (tuple[str, ...])

  • similarities (dict[str, float])

as_dict()[source]

Return a JSON-compatible attention receipt.

Return type:

dict[str, Any]

class ContextAttentionResult(value, receipt)[source]

Bases: object

Attended value and selection receipt.

Parameters:
  • value (ndarray)

  • receipt (ContextAttentionReceipt)

bounded_context_attention(query, candidates, graph, config, *, source_horizon_tokens=None)[source]

Attend to recent/retrieved nodes under hard node, token, and vector-work caps.

Parameters:
  • query (Any)

  • candidates (tuple[AttentionCandidate, ...])

  • graph (ContextGraph)

  • config (ContextAttentionConfig)

  • source_horizon_tokens (int | None)

Return type:

ContextAttentionResult