MindIR Compact (MIC)

MIC is a text-based, line-oriented format designed for minimal token usage when working with AI agents, git-friendly diffs, and deterministic serialization.

Design Goals

  • 5.3x token reduction compared to JSON serialization
  • 2.4x faster parsing than JSON (2.26 us vs 5.31 us)
  • Git-friendly diffs with one node per line
  • Stable IDs for safe patching operations
  • Deterministic canonicalization for reproducible outputs

Benchmark Results

FormatTokensvs JSONParse SpeedAnnual Cost (1M IRs)
JSON278baseline5.31 us$487
TOML1511.8x137.06 us$264
TOON674.1x2.67 us$117
MIC525.3x2.26 us$91

MIC saves $396/year per million IR operations vs JSON at GPT-5.2 pricing ($0.00175/1K input tokens).

Format Overview

mic@1                    # Version header
S0 "input"               # Symbol table
T0 f32                   # Type table (scalar)
T1 [f32;3,4]             # Tensor type (3x4 matrix)
N1 const.i64 42 T0       # Node definitions
N2 add N1 N1 T0          # Binary operation
O N2                     # Output marker

Line Types

PrefixPurposeExample
mic@NVersion headermic@1
S<id>Symbol definitionS0 "weight"
T<id>Type definitionT0 [f32;B,128]
N<id>Node definitionN5 matmul N3 N4 T1
OOutput markerO N5
#Comment# Layer 1

Supported Operations

CategoryOperations
Constantsconst.i64, const.f32, const.tensor
Arithmeticadd, sub, mul, div
Linear Algebramatmul, dot, transpose
Reductionssum, mean, sum_all, mean_all
Shapereshape, squeeze, expand_dims, gather
Activationsrelu, conv2d

Type Syntax

# Scalar types
T0 f32
T1 i64
T2 bool

# Tensor types: [dtype;dim1,dim2,...]
T3 [f32;3,4]           # 3x4 matrix
T4 [f32;B,128]         # Batch x 128 (symbolic B)
T5 [f32;?,?]           # Dynamic shape

Example: Simple Neural Network

mic@1
# Types
T0 [f32;B,784]         # Input: batch x 784
T1 [f32;784,256]       # Weight 1
T2 [f32;B,256]         # Hidden layer
T3 [f32;256,10]        # Weight 2
T4 [f32;B,10]          # Output

# Nodes
N0 param S0 T0         # Input
N1 param S1 T1         # W1
N2 matmul N0 N1 T2     # x @ W1
N3 relu N2 T2          # ReLU activation
N4 param S2 T3         # W2
N5 matmul N3 N4 T4     # hidden @ W2
O N5                   # Output

Security Limits

The MIC parser enforces strict limits to prevent denial-of-service attacks:

  • Input size: 10 MB maximum
  • Node count: 100,000 maximum
  • Shape dimensions: 32 maximum
  • Interned strings: 100,000 maximum

Rust API

use mind::ir::compact::{emit_mic, parse_mic};
use mind::ir::IRModule;

// Parse MIC to IR
let module = parse_mic(mic_str)?;

// Emit IR to MIC
let mic = emit_mic(&module);

// Roundtrip is deterministic
assert_eq!(emit_mic(&parse_mic(&mic)?), mic);

Learn More

See the full MIC specification at RFC-0001: MindIR Compact.