The Core Mental Model
The Core Mental Model
This handbook builds a clean mental model of modern foundation models without requiring advanced mathematics. It focuses on the concepts that matter for architecture, model selection, agent design, context engineering, and AI economics.
When the model is used inside an agentic system:
Training vs Inference
Training
Training is the process of creating the model's learned capability.
Training changes the model's parameters.
The goal is not to build a searchable database of documents. The goal is to optimize the network so that useful patterns, relationships, language structures, and higher-order capabilities emerge in the learned weights.
Inference
Inference happens after training, when the trained model is used.
Inference normally uses the existing learned weights rather than changing them.
Inference Is Not the Same as Reasoning
Simple inference
Complex inference
“Compare three financing structures, identify structural risks, and recommend the most defensible option.”
Tokens, Parameters & Embeddings
Tokenization
Models do not directly process human language as sentences. Text is first converted into tokens.
Each token maps to a numerical token ID.
Tokenizer Design vs Tokenization Operation
The tokenizer vocabulary/mapping is effectively fixed for a trained model family. But tokenization itself happens every time the model is used:
Training Sequences vs RAG Chunks
The word “chunking” can create confusion.
During Training
- Huge corpus → tokens → training sequences → model training
During RAG
- Document → chunks → embeddings → retrieval index
Parameters and Weights
A modern neural network contains a very large number of learnable numerical values. These are called parameters. A major subset of those parameters are weights.
w1 = 0.72 w2 = -1.14 w3 = 0.08
Real models contain billions or trillions of such values.
What Weights Do
A neural network repeatedly performs mathematical transformations. Very simplified:
During training:
Parameters Are Capacity, Not Guaranteed Intelligence
A larger parameter count gives a model more representational capacity, but more parameters do not automatically produce a better model.
A smaller but better-trained model can outperform a larger poorly trained one.
Weights and Probability
At generation time, learned weights transform the current representations into a probability distribution over possible next tokens.
Example
Training adjusts the weights so that good continuations become more probable across many examples.
A good model is not merely “more confident.” It should be accurate, calibrated, and context-sensitive.
Architecture vs Parameters
The architecture is designed first. Parameters are learned within that architecture.
Useful analogy
Embeddings
Tokens are numerical IDs, but neural networks need continuous numerical representations. A token maps to a vector:
Example
The values are high-dimensional learned numbers.
Vector Space
A vector space is the high-dimensional geometry in which representations exist.
Do not imagine a literal database containing one fixed coordinate for every human concept.
Instead:
Semantically related concepts can develop related representations.
Vector Space Is Contextual
A token's initial embedding is not its final meaning.
Example
“bank” in —
- “I deposited money at the bank.”
“bank” in —
- “We sat on the river bank.”
The initial token representation enters the network, but contextual processing transforms it differently.
Transformers & Attention
Transformer Architecture
The Transformer architecture was a major breakthrough because it enabled models to process relationships across sequences efficiently and scale extremely well.
The key mechanism inside Transformers is attention.
Why Transformers Mattered So Much
Transformers enabled a combination of:
The capability leap came from the combination:
Attention
Which pieces of available information are most relevant to the representation currently being processed?
Example
When processing “he”, the model should strongly relate it to “Roy”, not “laptop”.
Query, Key, Value
The intuitive mental model:
What am I looking for?
What information do I represent?
What information do I carry?
When processing “he”
Q("he") ≈ "Who does this pronoun refer to?"
Other tokens provide keys:
K("Roy")
K("laptop")
K("study")
The query is compared with keys. More relevant keys receive higher attention weight, and their values contribute more strongly to the updated representation.
Self-Attention
Self-attention means tokens inside the same sequence attend to one another.
This helps capture:
- subject-object relationships;
- pronoun references;
- causality;
- grammar;
- semantic relationships;
- long-distance dependencies.
Multi-Head Attention
Models use multiple attention heads.
one relationship pattern
another relationship pattern
long-range dependency
entity relationship
These roles are not manually assigned in a simple human-readable way; they emerge during training.
Is Self-Attention a Loop?
It is iterative across layers, but not a dynamic loop that runs until the model decides meaning is “finished”.
More accurately:
The number of Transformer layers is fixed by the model architecture.
Three Kinds of Repetition
Transformer depth
Within one forward pass:
Fixed by architecture.
Autoregressive generation
Continues until a stopping condition.
Reasoning / test-time compute
Some reasoning models use more computation for difficult tasks.
Easy task
- little reasoning compute
Hard task
- more reasoning compute
This is different from network depth.
Autoregressive Generation
Language models typically generate output one token at a time.
Stopping conditions may include:
- end-of-sequence token;
- max output length;
- tool call;
- runtime stop condition.
Context Engineering
Context
Context is the information actually available to the model during a particular inference. It may include:
Context Window
The context window is the maximum working capacity available for the current inference.
Analogy
Everything actively needed for inference must fit on the desk.
Large Context Does Not Mean Perfect Recall
A model may support a huge context window, but that does not mean every token is used equally well.
Large context ≠ perfect attention ≠ perfect retrieval ≠ perfect reasoning
Very large context can increase:
- noise;
- cost;
- latency;
- attention dilution;
- retrieval difficulty.
Context Engineering
A good system does not simply maximize context size.
Bad
- 900,000 tokens → “find what matters”
Better
- retrieve relevant evidence → compress state → remove noise → provide focused context
This improves reliability and cost.
Long Coding Sessions and Context Growth
Long technical chats accumulate:
If everything is repeatedly carried forward:
This is why modular development and structured state matter.
Why Modular Code Helps LLMs
Modularity is not only software hygiene. It is also context-efficiency architecture.
Instead of
- 10,000-line monolith
Prefer
- data_ingestion/
- compute/
- validation/
- reporting/
- api_adapter/
Then a validation task can receive only:
This reduces irrelevant context.
JSON as Structured State
JSON is useful for:
- state;
- contracts;
- schemas;
- configuration;
- structured outputs;
- metadata.
{
"module": "payroll_compute",
"input_contract": "...",
"output_contract": "...",
"immutable_rules": [],
"known_dependencies": []
}
It can be more efficient than reconstructing long conversational history.
Do not convert everything into JSON.
Code should remain code. Narrative methodology can remain prose. JSON is best where explicit structure matters.
Max Output
Max output is the maximum number of output tokens a model may generate in one response. This is separate from the context window.
A model can have a large context window while still imposing a much smaller maximum output length.
Memory & Retrieval
Memory
Memory is information intentionally preserved for future use.
Memory may include:
- durable preferences;
- long-lived decisions;
- recurring facts;
- stable operational information.
Memory Is Not Automatically in Context
Memory exists ≠ Model currently sees it
Relevant memory must be retrieved and injected into the current context.
Retrieval
Retrieval selects relevant stored information for the current task. Sources may include:
The goal is not to retrieve everything.
RAG
RAG stands for Retrieval-Augmented Generation. Typical pipeline:
RAG gives the model access to knowledge outside its learned weights.
RAG vs Model Training
Training
- data → tokens → optimization → weights change
RAG
- documents → chunks → embeddings → storage → retrieval at inference
Training changes the model. RAG changes the information available to the model at runtime.
RAG vs Memory
The mechanisms may look similar technically, but their semantics differ.
Example memory
- “User prefers architecture-first explanations.”
Example RAG source
- “Company payroll policy version 3.2”
Both can be retrieved into context, but they represent different categories of truth.
Embedding Models
Embedding models are not primarily chat models. They transform input into vectors:
Used for:
- semantic search;
- similarity;
- clustering;
- retrieval.
They are central to many RAG systems.
Multimodality
Multimodality
A multimodal model can process more than one type of input or output modality.
How Images Enter a Model
A model does not “see” an image in the human sense.
Those representations become numerical vectors that can participate in attention and reasoning.
Cross-Modal Alignment
Multimodal systems must connect representations across modalities.
This lets the model connect a user's text request to visual regions in a screenshot.
Audio Follows the Same Principle
Different modalities become representations that can participate in a shared reasoning process.
Shared Representation Space
A multimodal system attempts to align related concepts across modalities.
The vectors do not need to be identical; they need enough alignment for cross-modal reasoning.
Attention in Multimodal Models
Attention is not limited to text. A multimodal system may need to decide:
- Which text matters?
- Which visual region matters?
- Which audio segment matters?
- How do they relate?
Structured Data vs Multimodal Data
When structured data is available, structured access is usually preferable.
Do not ask a model to read a screenshot of a spreadsheet if a clean JSON/API exists.
Multimodal reasoning is most valuable where the world is inherently unstructured.
Truth, Agents & Model Selection
Model Knowledge Is Not a Source of Truth
Training gives a model general knowledge, but learned model knowledge may be:
- incomplete;
- outdated;
- probabilistic;
- difficult to trace;
- occasionally wrong.
Healthy architecture
Model vs Agent
A model is not an agent.
An agent system adds:
Model Selection Is an Architectural Choice
Most system builders do not modify frontier-model weights. They select the model that best fits the workload.
Practical questions become:
- Is the data clean?
- Is the context efficient?
- Is reasoning needed?
- Which model class is sufficient?
- How expensive is each inference?
- How many calls happen per task?
- Can deterministic code replace model work?
Model Quality Is Multidimensional
Do not ask only: “Which model is smartest?”
Ask instead:
- Reasoning quality?
- Instruction following?
- Tool discipline?
- Structured output reliability?
- Context performance?
- Coding?
- Vision?
- Latency?
- Cost?
- Stability?
- Hallucination rate?
Dense vs Mixture-of-Experts
A dense model activates most of its parameters for each token. A Mixture-of-Experts (MoE) model contains many expert blocks, but only some are activated for each token.
This matters for compute efficiency and model economics.
Open-Weight vs Closed Models
Closed Models
- weights remain controlled by provider
- accessed through API/service
Open-Weight Models
- weights can be downloaded/self-hosted
- subject to license
Trade-offs
Cloud
- easy access
- frontier capability
- usage billing
- provider-controlled
Local / Open-Weight
- more control
- privacy
- hardware requirement
- operational burden
Economics & Synthesis
Context and Cost
Context is not free. In agent systems, one human request may create multiple model calls.
Example
Each model call may carry part of the context again.
Context Efficiency Is an Economic Discipline
Poor architecture
Better architecture
Practical System Formula
Economically
AI VALUE ≈ Decision Quality × Reliability × Speed ÷ Cost
A technically impressive system can still be economically poor.
The Complete Semantic Map
Every concept in this handbook fits into one composite pipeline — the core generative path, surrounded by the systems that make it contextual, grounded, and multimodal.
Around that core
Final Distinctions to Lock In
Keep this table mentally available.
| Concept | Practical Meaning |
|---|---|
| Token | Unit of model input/output |
| Tokenizer | Converts text into token IDs |
| Embedding | Numerical vector representation |
| Vector Space | Geometry of learned representations |
| Parameter | Learnable numerical value |
| Weight | Major learned parameter controlling transformations |
| Transformer | Neural architecture processing representations |
| Attention | Dynamic relevance weighting |
| Query | What information is being sought |
| Key | What a representation offers for matching |
| Value | Information contributed after matching |
| Self-Attention | Tokens attending to other tokens in the same sequence |
| Multi-Head Attention | Multiple relationship patterns processed in parallel |
| Context | Information available in the current inference |
| Context Window | Maximum working-context capacity |
| Max Output | Maximum generation length |
| Memory | Information retained for later |
| Retrieval | Selecting relevant stored information |
| RAG | Retrieval of external canonical knowledge |
| Multimodal | Processing multiple modalities |
| Training | Learning model parameters |
| Inference | Using the trained model |
| Reasoning | Problem-solving computation during inference |
| Agent | Model plus tools, state, memory, loop, and permissions |
What You Do Not Need to Master
You do not need to derive advanced Transformer mathematics to make strong architecture decisions.
You do not need to calculate attention equations manually.
You do not need to train a frontier foundation model.
What you do need is functional understanding of:
- what the model knows
- what the model does not know
- what context it receives
- how attention uses that context
- how retrieval changes that context
- what memory preserves
- what deterministic systems should handle
- when reasoning is needed
- how model calls create cost
Architectural Principles
A model is a probabilistic intelligence engine, not a database.
Training changes weights; inference uses weights.
Parameters provide capacity; training quality determines how well capacity is used.
Embeddings create numerical representations; meaning becomes contextual through Transformer processing.
Attention determines what information matters relative to the current representation.
Context capacity is not the same as context quality.
Memory is useful only when relevant information is retrieved into context.
RAG complements model knowledge with external source-of-truth knowledge.
Structured data should be preferred over visual interpretation when available.
Model quality alone does not determine system quality.
Context engineering is both a reliability discipline and a cost discipline.
The best model is not necessarily the best model for every task.
Deterministic logic should stay deterministic.
Reasoning should be used where ambiguity genuinely exists.
AI architecture is also economic architecture.
Closing Mental Model
The model is powerful because learned weights create a high-dimensional transformation system capable of extracting relationships from context.
Further Reading
These sources are useful for going deeper into the mechanisms summarized in this handbook:
- Attention Is All You Need (Transformer paper)https://arxiv.org/abs/1706.03762
- Anthropic — Model Context & Long Context Guidehttps://docs.claude.com/en/docs/build-with-claude/context-windows
- Anthropic — Prompt Engineering Overviewhttps://docs.claude.com/en/docs/build-with-claude/prompt-engineering/overview
- OpenAI — Tokenizerhttps://platform.openai.com/tokenizer
- Hugging Face — Transformers Documentationhttps://huggingface.co/docs/transformers/index
- Google — Mixture-of-Experts Explainerhttps://research.google/blog/mixture-of-experts-with-expert-choice-routing/
- Pinecone — Retrieval-Augmented Generation Guidehttps://www.pinecone.io/learn/retrieval-augmented-generation/
- Anthropic — Building Effective Agentshttps://www.anthropic.com/research/building-effective-agents