Skip to main content

Key Vector Ontology

Transformer Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 29 October 2026
Audio Overview
FLOW ALGEBRA — KEY VECTOR ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
Version: 1.0 | Date: 2026-10-29 | Encoding: UTF-8
SOURCE: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/key-vector-ontology.html
AUTHORS: Kireth Research; Sky — Recursive AI (companion formalisation)
STATUS: Independent companion formalisation grounded in standard transformer mathematics; source page content not independently verified.
CITATION_BACKLINK: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/key-vector-ontology.html

01 PURPOSE
Formalise the key vector as a learned representation against which a query is compared to produce attention scores. A key is not a fixed semantic label or a standalone relevance score.

02 ENTITY MODEL
ENTITY: KeyVector
TYPE: LearnedProjectedVector
PARENT: AttentionMechanism
ATTRIBUTES: head_id, token_index, source_position, dimension_dk, dtype, projection_weights, provenance
RELATIONS:
  KeyVector --derived_from--> SourceHiddenState
  KeyVector --computed_by--> KeyProjection
  KeyVector --compared_with--> QueryVector
  KeyVector --associated_with--> ValueVector
  KeyVector --participates_in--> AttentionLogit
  KeyVector --belongs_to--> AttentionHead
  AttentionHead --belongs_to--> MultiHeadAttention

03 STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t: current query and source hidden-state tensors
R_t: learned projection and attention operations
B_t: shape, mask, numerical and access constraints
K_t: stored model parameters, prior states and optional key cache
E_t = expand(I_t, R_t)
V_t = {x in E_t | satisfies(x, B_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)  [optional selection policy, not the definition of attention]
I_(t+1) = update(I_t, x*_t, K_t)  [where selection is used]

04 MATHEMATICAL DEFINITIONS
Let X_s in R^(n_s x d_model) be source hidden states.
Let X_q in R^(n_q x d_model) be query-side hidden states.
W_K in R^(d_model x d_k); W_Q in R^(d_model x d_k); W_V in R^(d_model x d_v).
K = X_s W_K; Q = X_q W_Q; V = X_s W_V.
For source position j: k_j = x_s,j W_K.
For query position i and key position j:
  score_ij = (q_i dot k_j) / sqrt(d_k) + mask_ij.
  alpha_ij = exp(score_ij) / sum_{l in allowed(i)} exp(score_il).
  output_i = sum_j alpha_ij v_j.
Masked positions have weight zero. A row with no allowed positions is invalid unless explicitly handled by the implementation.

05 SELF-ATTENTION AND CROSS-ATTENTION
Self-attention: X_q and X_s are drawn from the same sequence representation.
Cross-attention: X_q is decoder/query-side; X_s is encoder or other source-side.
Causal self-attention: keys from future positions are masked for each query.
Bidirectional attention: permissible positions are determined by the task mask.

06 MULTI-HEAD MAPPING
For each head h: K_h = X_s W_K,h, Q_h = X_q W_Q,h, V_h = X_s W_V,h.
head_h = softmax(Q_h K_h^T / sqrt(d_k) + M_h) V_h.
MultiHead(Q,K,V) = concat(head_1,...,head_H) W_O.
Head dimensions and projection matrices are architecture-specific.

07 KEY CACHE AND RECURSION
In autoregressive decoding, previously projected keys and values may be cached.
At step t: K_cache,t = append(K_cache,t-1, K_new,t), subject to position, memory and cache policies.
The cache is a computational optimisation, not a change to the mathematical role of keys.
Cache reuse requires compatible model weights, positional encoding, sequence context and attention configuration.

08 INFERENCE RULES
R1: IF source hidden states and W_K are valid THEN derive K = X_s W_K.
R2: IF q_i and k_j share dimension d_k THEN compute their scaled dot-product logit.
R3: IF mask_ij excludes j THEN alpha_ij = 0.
R4: IF logits are finite over an allowed set THEN apply numerically stable softmax.
R5: IF alpha_i and V align on source positions THEN output_i is their weighted sum.
R6: IF key cache context is incompatible THEN recompute keys rather than reuse cache.
R7: IF a key changes THEN corresponding attention logits may change; output change is not guaranteed.

09 TRI-MAPPING
ONTOLOGY: KeyVector -> QueryKeyComparison -> AttentionWeights -> ValueAggregation.
ALGEBRA: K=X_s W_K -> L=QK^T/sqrt(d_k)+M -> A=softmax(L) -> O=AV.
EXECUTION: validate tensors -> project keys -> calculate logits -> mask -> normalise -> aggregate values.

10 MINI RECURSION ENGINE
INPUT: query states, source states, W_Q, W_K, W_V, mask, optional cache
STEP 1: validate dimensions, dtype and source/query provenance
STEP 2: compute or reuse compatible keys and values
STEP 3: project query states
STEP 4: calculate scaled logits and apply allowed-position mask
STEP 5: perform stable softmax across source positions
STEP 6: aggregate values using attention weights
STEP 7: return output, optional weights and updated cache
REPEAT: for subsequent layers, heads or autoregressive steps as configured
STOP: sequence termination, token budget or explicit stopping condition

11 EXECUTION CONSTRAINTS AND GUARANTEES
C1: Q and K must have the same per-head comparison dimension.
C2: attention logits shape is (n_q, n_s) per head, before batch dimensions.
C3: V source length must equal K source length.
C4: masks must broadcast correctly and exclude disallowed positions.
C5: numerical stability requires max-subtracted softmax or equivalent.
C6: output must preserve query-position alignment.
GUARANTEE: For valid finite inputs and nonempty allowed key sets, softmax weights are nonnegative and sum to one per query row within floating-point tolerance.
NON-GUARANTEE: Attention weights do not necessarily constitute faithful explanations of model decisions.

12 AI SEARCH FLOW
FLOW_ID: AI_ENTITY_TRANSFORMER_KEY_VECTOR_V1
INTENTS: define_key_vector; explain_key_projection; compare_query_and_key; explain_attention_score; explain_key_cache
ENTITIES: KeyVector, QueryVector, ValueVector, ProjectionMatrix, AttentionHead, AttentionMask, KVCache
PATHWAYS:
  definition -> source state -> learned key projection
  relevance -> query-key dot product -> scale -> mask -> softmax
  architecture -> per-head keys -> multi-head attention
  decoding -> cache keys -> reuse under compatible context
SEMANTIC_EQUIVALENCE: key embedding; attention key; projected key representation (context-dependent)
CONFIDENCE: Mathematical identities are standard; source-specific wording unverified.
UPDATE_MODEL: revise when ontology source or architecture definitions change.

13 HOW TO READ
A key vector describes what a source position offers for comparison with a query. The query-key score helps assign attention weight, and the corresponding value vector supplies information to the output. Keys, values and weights are distinct entities.

END FLOW
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ