FLOW ALGEBRA — CONTEXT WINDOW ONTOLOGY (2)
Semantic Library | AI Core | Entity Graph | Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/context-window-ontology-2.html
Status: Companion formalisation from established transformer principles; source-page specification not independently verified.
Encoding: UTF-8 | Language: en-GB
FLOW "ContextWindowOntology2" v1.0
AUTHORS:
Research framework: Kireth Research / Semantic Library
Formalisation assistance: Sky — Recursive AI
SOURCE:
https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/context-window-ontology-2.html
CITATION_BACKLINK: source URL above
PURPOSE:
Formalise the finite token-accessible context of transformer inference,
including position indexing, truncation, masking, cache management,
effective context and output-budget constraints.
STATE_MODEL:
S_t = (I_t, R_t, B_t, K_t)
I_t = tokenised input and retained dialogue state
R_t = attention, positional, truncation and retrieval rules
B_t = model limits, memory budget, security and task boundaries
K_t = model parameters, retained KV cache and available context metadata
E_t = expand(I_t, R_t)
V_t = {x in E_t | valid(x, B_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)
I_(t+1) = update(I_t, x*_t)
ENTITIES:
ContextWindow: bounded accessible sequence of token positions
ContextCapacity: maximum supported sequence length for a configuration
PromptTokens: tokens supplied for current processing
GeneratedTokens: autoregressively produced tokens
TokenPosition: index assigned to an element of a token sequence
AttentionMask: allowed/disallowed token dependencies
SlidingWindow: bounded recent-token attention span
KVCache: stored key/value tensors for reusable prior positions
ContextTruncation: removal of tokens to meet capacity constraints
ContextCompression: representation of prior content in fewer tokens
RetrievedContext: selected external content inserted into a prompt
EffectiveContext: information actually usable for a task
PositionEncoding: positional information supplied to attention
OutputBudget: reserved maximum generated tokens
RELATIONSHIPS:
ContextWindow HAS_CAPACITY ContextCapacity
ContextWindow CONTAINS PromptTokens
ContextWindow MAY_CONTAIN GeneratedTokens
TokenPosition INDEXES PromptTokens
AttentionMask RESTRICTS TokenDependencies
SlidingWindow RESTRICTS AccessiblePositions
KVCache STORES ProjectedKeysAndValues
ContextTruncation REMOVES OldOrSelectedTokens
ContextCompression SUMMARISES PriorContext
RetrievedContext AUGMENTS PromptTokens
PositionEncoding REPRESENTS TokenPosition
FORMAL_OPERATORS:
L_max = configured context capacity in tokens
N_in = number of prompt tokens
N_out = number of generated tokens in current sequence
N_total = N_in + N_out
FeasibleFullContext := N_total <= L_max
RemainingBudget := max(0, L_max - N_in)
GenerationLimit := min(requested_output_limit, RemainingBudget)
NOTE: Some APIs enforce separate prompt/output caps or reserve tokens;
the above is a simplified shared-window model, not universal.
For causal full attention at generation position t:
Accessible(t) = {j | 0 <= j <= t and j retained}
For causal sliding window of width w:
Accessible_w(t) = {j | max(0,t-w+1) <= j <= t}
For attention scores s_(t,j):
alpha_(t,j) = softmax_j(s_(t,j) + M_(t,j))
M_(t,j) = 0 if j accessible, else -infinity
output_t = sum_j alpha_(t,j) * V_j
For full self-attention, score matrix size scales as O(n^2);
actual memory/compute depends on attention implementation.
OPERATIONS:
tokenise(text) -> token_ids
allocate_budget(prompt, expected_output, L_max) -> feasible_plan
retain(sequence, policy, capacity) -> retained_sequence
truncate(sequence, priority_policy) -> shortened_sequence
compress(history, summary_policy) -> compressed_context
retrieve(query, corpus, budget) -> retrieved_context
build_mask(positions, attention_policy) -> attention_mask
append_token(sequence, token) -> next_sequence
update_cache(KVCache, next_token) -> KVCache_next
validate_positions(sequence, encoding_limit) -> bool
INFERENCE_RULES:
R1: If N_in + N_out exceeds L_max, reduce input, output, or both.
R2: Truncation can remove facts required for later inference.
R3: Compression is lossy unless the relevant information is preserved.
R4: A nominally supported context length does not guarantee equal
retrieval accuracy at every position.
R5: KV caching accelerates reuse of past projections but does not
inherently increase the model's supported context capacity.
R6: Sliding-window attention limits direct token-to-token visibility;
higher-layer propagation may still carry indirect information.
R7: External retrieval contributes only content actually inserted
into the accessible prompt or otherwise exposed to the model.
R8: Context capacity, attention span and effective usable context
are distinct concepts.
MINI_RECURSION_ENGINE:
initialise prompt, context_policy, capacity, output_limit
repeat while generation_allowed:
validate token budget and positional constraints
select retained/retrieved context under policy
construct attention mask and available KV state
compute next-token distribution
choose next token subject to validity constraints
append token; update cache and state
stop on end condition or exhausted budget
TRI_MAPPING:
Entity: ContextWindow
Structure: ordered token sequence + capacity + attention policy
Operation: retain -> mask -> attend -> generate -> update
Entity: SlidingWindow
Structure: current position + window width
Operation: discard inaccessible direct attention positions
Entity: KVCache
Structure: per-layer, per-head key/value tensors
Operation: reuse retained projections and append new entries
HOW_TO_READ:
ContextWindow is the model's bounded token-accessible workspace.
ContextCapacity is a configured maximum, not a guarantee of recall.
AttentionMask determines direct visibility between positions.
EffectiveContext depends on model behaviour and task demands.
EXECUTION_CONSTRAINTS:
Require valid token IDs and positional indices.
Never claim unlimited context from a sliding window or cache.
Track input/output limits separately where the API requires them.
Respect truncation provenance and security boundaries.
Preserve important instructions and citations when compressing.
Avoid claiming perfect long-context retrieval or lossless summaries.
EXECUTION_GUARANTEE:
If tokenisation, budget accounting and masks are correctly implemented,
the pipeline can enforce configured length and visibility constraints.
This does not guarantee factual correctness, faithful recall,
deterministic sampling or adequate task performance.
AI_SEARCH_FLOW:
intent: locate definitions, constraints and relationships of context windows
aliases: [context length, token window, attention span, context capacity]
entry_entity: ContextWindow
pathways:
- ContextWindow -> ContextCapacity -> OutputBudget
- ContextWindow -> AttentionMask -> SlidingWindow
- ContextWindow -> KVCache -> TokenPosition
- ContextWindow -> ContextTruncation -> ContextCompression
- ContextWindow -> RetrievedContext -> EffectiveContext
retrieval_priority: exact entity > related mechanism > implementation note
confidence: conditional on model architecture and configured API limits
semantic_equivalence:
context window != KV cache
context capacity != effective recall
sliding-window attention != full-context attention
UPDATE_MODEL:
Version changes should record architecture-specific limits,
attention policy, position encoding and truncation strategy.
END FLOW
Download Code
Copy to Clipboard