MicroLLM — Complete Technical Specifications & Engineering Architecture¶
(Architecture, Mathematical Proofs, jevcompat 0.1 Wire Protocol, REST API & Runtime SLAs)¶
Documentation Hub: - Product Documentation & User Guide:
docs/PRODUCT_DOCUMENTATION.md- Technical Specifications (This Document):docs/TECHNICAL_SPECIFICATIONS.md- Algorithmic Reference Manual:docs/ALGORITHMS.md- Engineering & Scientific Syllabus:docs/SYLLABUS.md- Architecture & Quick Reference:docs/README.md· Interactive HTML:docs/index.html- Published Benchmarks (11,000Cases):BENCHMARKS.md·docs/EXTERNAL_DATASETS_BENCHMARKS.md- Quality & Performance Test Plan (750–1,000Cases):docs/TEST_PLAN.md- Academic Literature Catalog (104Papers):docs/LITERATURE_REVIEW.md·docs/papers/README.md- Governance & Traceability Registers:docs/ACTION_LOGBOOK.md·docs/RCA_REGISTER.md
Table of Contents¶
- System Architecture & Module Topology
- Formal Mathematical Specifications of Decision Primitives & Confidence
- Gear 1 Specification:
FastEncoderBackend, Embeddings & XAI - Gear 2 Specification:
AnyJevPrefillBackend, Theorem 1 \(L_0\) & Van der Corput - StartLux Cascade (
DualGearCascadeBackend) & 25-Way Hierarchical Tournament - Statistical Calibration, Conformal Prediction & Clopper-Pearson Certification
- Two-Stage OpenJev-RLCD² Local Training Engine (
src/microllm/rlcd.py) - Complete
jevcompat 0.1Wire Protocol & 32/32MUSTCompliance Matrix - Complete HTTP REST API Specification (17 Endpoints)
- Strict Pydantic v2 Data Models & Validation Rules (
src/microllm/schemas.py) - Hardware Profile Registry & Symmetric INT8 Quantization (
src/microllm/registry.py) - Non-Functional Requirements (NFRs), Security, CI/CD & Verification Traceability
1. System Architecture & Module Topology¶
1.1 High-Level Component Architecture¶
MicroLLM (version = "0.4.1", Python >= 3.10) is architected as a modular, zero-mandatory-GPU Python package (src/microllm/) exposing both an in-process Python API and a Jev-compatible FastAPI server (create_app).
flowchart TB
subgraph Clients["Client Layer"]
SDK_SYNC["MicroJevClient (Sync HTTPX)"]
SDK_ASYNC["AsyncMicroJevClient (AsyncIO)"]
ROUTER["@system_one_router Decorator"]
STUDIO["Decision Studio Web UI (GET /)"]
CLI["microllm CLI (serve|pull|list|benchmark|papers|rca)"]
end
subgraph API["FastAPI Transport & Validation Layer (src/microllm/server.py & schemas.py)"]
AUTH["Bearer Auth Middleware (MICROLLM_API_KEY)"]
SCHEMA["Pydantic v2 Schemas + Recursive NaN/Inf Filter (_ensure_finite_json)"]
ISOL["Isolated Question Dispatcher (_evaluate_isolated_question)"]
GUARD["4-Rubric + Custom AI Safety Guardrail (/v1/guardrail)"]
METRICS["Telemetry & Observability Collector (/v1/metrics)"]
end
subgraph Engine["Dual-Gear Hybrid Decision Engine (src/microllm/backends/)"]
CASC["DualGearCascadeBackend (StartLux Read-or-Think Cascade)"]
G1["Gear 1: FastEncoderBackend (NLI Template + 512-Token Guard)"]
G2["Gear 2: AnyJevPrefillBackend (L0 Circular Rotation + Van der Corput)"]
TOURN["run_hierarchical_tournament (25-Way Chunks up to K=255)"]
BASE["Base Scorer: embed_text_deterministic (BLAKE2b LRU + 16 Concept Clusters)<br/>or Pluggable HF / ONNX Scorer"]
end
subgraph MathCal["Calibration, Conformal & RLCD² Layer"]
TEMP["PerKTemperatureScaler & VectorScalingCalibrator"]
CONF["SplitConformalCalibrator (Standard & Mondrian Class-Conditional)"]
CP["Clopper-Pearson Risk Bound (clopper_pearson_threshold)"]
RLCD["RLCDDecisionHeadTrainer (Stage 1 Pathwise + Stage 2 LOO-KL) & RLCDReplayBuffer"]
end
Clients --> API
API --> CASC
CASC --> G1
CASC --> G2
G1 --> TOURN
G2 --> TOURN
TOURN --> BASE
G1 --> TEMP
G1 --> CONF
API --> RLCD
API --> CP
1.2 Request Lifecycle Sequence Diagram (POST /v1/systemone)¶
sequenceDiagram
autonumber
participant C as Client / Agent
participant S as FastAPI Server (/v1/systemone)
participant V as Pydantic v2 Validator (schemas.py)
participant Cas as DualGearCascadeBackend
participant G1 as FastEncoderBackend (Gear 1)
participant G2 as AnyJevPrefillBackend (Gear 2)
C->>S: POST /v1/systemone {model, state, questions}
S->>S: Verify Authorization: Bearer <key> (401 on mismatch)
S->>V: Parse SystemOneRequest & _ensure_finite_json
alt Invalid Schema or NaN/Infinity
V-->>C: HTTP 422 {"detail": [{"loc": ["body", ...], "msg": ..., "type": ...}]}
end
loop For each (qid, q_spec) in Complete Isolation
S->>Cas: _evaluate_isolated_question(backend, state_text, q_spec)
Cas->>G1: Evaluate p_0, confidence(p_0), x_conformal_set, x_abstain
alt confidence(p_0) >= gate_threshold (0.75) AND x_abstain == False
G1-->>Cas: Fast Auto-Commit p_0 (~0.08 - 1.0 ms)
else Ambiguous or Abstained (Escalate to Gear 2)
Cas->>G2: Evaluate p_1 via AnyJev L0 Circular Rotation (Van der Corput)
G2-->>Cas: Position-Unbiased Distribution p_1 + x_l0_meta
Cas->>Cas: Fuse p_fused = (1 - alpha) * p_0 + alpha * p_1
end
Cas-->>S: Validated AnswerSpec (NoulAnswer | ChoiceAnswer | ScoreAnswer | MultiAnswer)
end
S-->>C: HTTP 200 SystemOneResponse {model, answers, usage}
1.3 Complete Source Code Module Map¶
| File Path | Primary Classes & Functions | Engineering Responsibility |
|---|---|---|
src/microllm/__init__.py |
__version__ = "0.4.1", 75 exported symbols |
Public package surface unifying backends, calibration, RLCD, SDK, registry, MCP server, unified benchmark runner, and papers. |
src/microllm/schemas.py |
SystemOneRequest, SystemOneResponse, NoulQuestion, ChoiceQuestion, ScoreQuestion, MultiQuestion, NoulAnswer, ChoiceAnswer, ScoreAnswer, MultiAnswer, UsageInfo, _ensure_finite_json, render_structured_text |
Strict jevcompat 0.1 Pydantic v2 request/response envelopes and recursive NaN/Infinity rejection (RCA-004). |
src/microllm/confidence.py |
choice_confidence, score_expectation, score_confidence, multi_confidence, earth_movers_distance_1d, unimodal_ordinal_smooth, run_hierarchical_tournament, sanitize_and_normalize_probabilities |
Official TypeSafe AI confidence & expectation math (jevcompat §4.3–§4.5) and StartLux 25-way tournament routing (K <= 255). |
src/microllm/calibration.py |
PerKTemperatureScaler, VectorScalingCalibrator, SplitConformalCalibrator, brier_score, expected_calibration_error, reliability_diagram_bins, clopper_pearson_upper_bound, clopper_pearson_threshold, tune_cascade_pareto |
Cardinality-aware temperature scaling, \(L_2\) vector scaling, standard & Mondrian split conformal prediction, Clopper-Pearson bounds, and Pareto cascade tuning. |
src/microllm/rlcd.py |
RLCDConfig, RLCDDecisionHeadTrainer, RLCDReplayBuffer, shifted_brier_reward, group_mean_variance_identity, beta_decision_weight, rlcd2_weighted_brier_reward, stage1_pathwise_loss_and_grad, compute_leave_one_out_kl_advantages, verify_tabular_rlcd_unbiased_gradient |
Two-Stage OpenJev-RLCD Algorithm 1 + StartLux \(\text{RLCD}^2\) \(\text{Beta}(8,2)\) weighting, Proposition 1 variance identity, and Appendix A exact analytical gradient verification. |
src/microllm/backends/base.py |
DecisionBackend, CONCEPT_CLUSTERS, VerdictMQMultiQuestionCache, tokenize_multilingual, embed_text_deterministic, _embed_text_cached, semantic_match_logit, explain_state_tokens, explain_counterfactual, create_hf_zero_shot_scorer, create_onnx_nli_scorer, create_hybrid_fast_path_scorer |
256-D deterministic CPU encoder with BLAKE2b LRU cache, clause-salient max-pooling (HYP-008), Verdict-MQ multi-question state cache (IDEA-022), token & counterfactual XAI, and revision-pinned HuggingFace/ONNX/Hybrid INT8 adapters (RCA-014, APP-001, APP-003). |
src/microllm/backends/fast_encoder.py |
FastEncoderBackend, format_nli_hypothesis, truncate_to_context_budget |
Gear 1 single-pass encoder with NLI sentence templating ("It is {opt}: {desc}."), 512-token context guard, definition-dominant rubric scoring (HYP-006), multi-template consensus (HYP-011), and policy/exemption handling (RCA-001, RCA-028, RCA-029). |
src/microllm/backends/prefill_llm.py |
AnyJevPrefillBackend, l0_circular_rotation_readout, van_der_corput_order, compute_dynamic_tau, compute_answer_mass, apply_prior_debiasing, OnlinePriorTracker, create_openai_logprobs_slot_scorer, create_llamacpp_slot_scorer |
Gear 2 AnyJev \(L_0\) circular rotation readout cancelling slot bias, Van der Corput schedule, canonical key sorting (RCA-002), online EMA prior debiasing, and local SLM (Ollama/vLLM/llama.cpp) logprob connectors (APP-002). |
src/microllm/backends/cascade.py |
DualGearCascadeBackend, fuse_distributions, compute_adaptive_alpha, evaluate_voc_gate_regime |
StartLux Read-or-Think cascade combining Gear 1 speed with Gear 2 order-invariance via \((1-\alpha)p_0 + \alpha p_1\) and Value-of-Computation Gate (HYP-005). |
src/microllm/registry.py |
MODEL_PROFILES, list_profiles, pull_profile, load_profile_scorer, verify_profile, quantize_matrix_int8, dequantize_matrix_int8, quantize_onnx_file_int8 |
Hardware profile registry (fast-cpu-int8, multilingual, guardrail), symmetric INT8 quantization, hybrid INT8 profile scorer loader (APP-003), and SHA-256 checksum verification. |
src/microllm/mcp_server.py |
MCP_TOOLS_SPEC, MicroLLMMCPServer, run_mcp_stdio_server |
Native JSON-RPC 2.0 Model Context Protocol (MCP) server exposing systemone_decide, systemone_guardrail, and systemone_calibrate over stdio (microllm mcp) and HTTP (POST /v1/mcp). |
src/microllm/client.py |
MicroJevClient, AsyncMicroJevClient, Noul, Choice, Score, Multi, NoulResult, ChoiceResult, ScoreResult, MultiResult, system_one_router |
Typed synchronous and asynchronous Python SDKs, Enum schema bridges (from_enum), and @system_one_router decorator. |
src/microllm/server.py |
create_app, run_cli, main |
FastAPI HTTP server (18 routes including /v1/mcp and /slides), telemetry collector, Decision Studio UI host, and CLI dispatcher. |
src/microllm/benchmark_runner.py |
ALL_BENCHMARK_SUITE_IDS, ALL_BENCHMARK_SUITES_SPEC, FAST_BENCHMARK_SUITE_IDS, collect_system_environment, run_all_benchmark_suites, format_master_benchmark_markdown |
Unified 9-suite benchmark automation orchestrator (microllm benchmark --all-suites & scripts/run_all_benchmarks.*) exporting benchmarks/all_benchmarks_master_report.json. |
src/microllm/benchmarks.py & src/microllm/benchmark.py |
build_eval_corpus, run_benchmark_suite |
540-item 5-track scientific evaluation corpus and 1-command benchmark runner. |
src/microllm/quality_suite.py |
build_quality_test_cases, run_quality_validation_suite, format_quality_report_markdown |
750–1,000 case 8-track Quality & Performance SLA validation engine (G1–G8 gates). |
src/microllm/test_cases_1000.py & src/microllm/product_independent_cases.py |
build_structured_test_entries, build_product_independent_test_entries, evaluate_structured_test_cases |
11,000 structured test cases (1,000 core + 10,000 product-independent across 18 domains). |
src/microllm/dataset_adapters.py & src/microllm/web_benchmark_suite.py |
BaseDatasetAdapter, 16 dataset adapters (BoolQAdapter, MultiNLIAdapter, Banking77Adapter, AGNewsAdapter, CLINC150Adapter, AmazonReviewsAdapter, YelpReviewFullAdapter, GoEmotionsAdapter, Reuters21578Adapter, WildGuardAdapter, ToxicChatAdapter, DeepsetPromptInjectionsAdapter, ChoiceBenchAdapter, CalloBiasSetAdapter, RouteLLMAdapter, JevBenchExternalAdapter), load_full_external_dataset_split, run_all_web_benchmarks |
Canonical adapters, full unsampled official split loader (114,018 rows), and offline fixtures for all 16 public web benchmarks. |
src/microllm/papers.py |
ACADEMIC_PAPERS_CATALOG, LITERATURE_PILLARS, list_academic_papers, get_academic_paper, download_academic_papers, verify_downloaded_pdfs |
104-paper academic catalog across 6 research pillars with polite arXiv PDF downloader and verifier. |
src/microllm/rca_runner.py |
RCARunner, RCARecord, RCARunnerResult, RCA_CATALOG |
Sequential one-by-one verification runner for all 15 Root Cause Analyses (RCA-001..RCA-015). |
src/microllm/research_challenge.py |
PolicyAwareCalibrator, rlcd2_proper_integral_score, clopper_pearson_split_certificate, evaluate_probability_coherence, value_of_computation_gate, score_with_rubric_dominance, compute_skew_adaptive_prior_debiasing, evaluate_evidence_sensitivity, brier_decomposition, compute_aurc_and_cov_at_risk, evaluate_decoy_iia_stability, evaluate_multi_template_consensus, evaluate_numeric_bisection_tree, run_all_hypotheses_challenge |
Research-paper challenge algorithms & validation protocols (HYP-001..HYP-012). |
2. Formal Mathematical Specifications of Decision Primitives & Confidence¶
Implemented in src/microllm/confidence.py in strict conformance with jevcompat 0.1 §4.2–§4.5:
2.1 Simplex Normalization (sanitize_and_normalize_probabilities)¶
Given raw non-negative scores \(\tilde{p}_1, \dots, \tilde{p}_K\), probabilities are normalized via \(p_i = \tilde{p}_i / \sum_{j=1}^K \tilde{p}_j\) (falling back to uniform \(1/K\) if \(\sum_j \tilde{p}_j \le 10^{-12}\)), and residual IEEE-754 floating-point drift is absorbed onto \(k^* = \arg\max_i p_i\) via:
guaranteeing \(\sum_{i=1}^K p_i = 1.0\) to machine precision.
2.2 choice Confidence (choice_confidence)¶
For \(K \in [2, 255]\) mutually exclusive options with maximum probability \(m = \max_{i \in \{1..K\}} p_i\):
- Boundary Properties: \(\text{confidence}_{\text{choice}}(1/K, \dots, 1/K) = 0.0\) (uniform chance); \(\text{confidence}_{\text{choice}}(e_{k^*}) = 1.0\) (complete certainty).
2.3 score Expectation (score_expectation) & Confidence (score_confidence)¶
For \(K \in [2, 10]\) ordered rubric levels indexed \(i \in \{0, 1, \dots, K-1\}\): 1. Expected Value:
- Modal Concentration Confidence: Let \(k^* = \arg\max_{i \in \{0..K-1\}} p_i\) be the modal level and \(D = \frac{1}{K}\sum_{i=0}^{K-1}\left|i - \frac{K-1}{2}\right|\) be the mean absolute deviation of a uniform distribution around the midpoint \(\frac{K-1}{2}\). Then:
- 1D Earth Mover's Distance (
earth_movers_distance_1d,IDEA-008) & Unimodal Smoothing (unimodal_ordinal_smooth):
2.4 multi Independent Certainty (multi_confidence)¶
For \(K \in [2, 255]\) independent binary labels with probabilities \(p_k \in (0, 1)\):
3. Gear 1 Specification: FastEncoderBackend, Embeddings & XAI¶
Implemented in src/microllm/backends/base.py and src/microllm/backends/fast_encoder.py:
3.1 Deterministic 256-Dimensional Multilingual Encoder (embed_text_deterministic)¶
To guarantee < 1.0 ms cold-start CPU execution with zero network dependency (IMP-002, APP-001), text is embedded into \(\mathbb{R}^{256}\) (_embed_text_cached with functools.lru_cache(maxsize=4096), IDEA-012):
- Dimensions 0..15 (Multilingual Concept Clusters): Activations across CONCEPT_CLUSTERS (billing_finance, technical_support, shipping_logistics, urgency_high, urgency_low, affirmative, negative, security_destructive, security_injection, security_pii) covering English, French, Spanish, German, and Korean vocabulary (\(v_c = 2.2 \times \text{hits}\)).
- Dimensions 16..255 (BLAKE2b Word & Subword Character 3-Gram Hashing):
- Each word token \(w\) hashes via 8-byte blake2b into slot \(16 + (\text{hash}(w) \bmod 240)\) with signed weight \(\pm 1.6\).
- Each boundary-padded character 3-gram <w> hashes via 4-byte blake2b into slot \(16 + (\text{hash}(\text{tri}) \bmod 240)\) with weight \(+0.45\), providing morphological robustness.
- Normalization: \(\hat{v} = v / \|v\|_2\).
3.2 Semantic Match Logit (semantic_match_logit) & NLI Hypothesis Templating (format_nli_hypothesis)¶
Per openJev-verdict-2.0, candidate options (option_name, description) are formatted as complete NLI hypothesis sentences:
Given premise \(s\) (state truncated to 512 tokens via truncate_to_context_budget), query \(q\) (instructions), and candidate hypothesis \(h\):
3.3 Token Attribution (explain_state_tokens) & Counterfactual Sensitivity (explain_counterfactual)¶
explain_state_tokens(state_text, query_text, candidate_text, top_k=6): Filters stopwords, scores each unique token \(w_i \in s\) directly against \(h\) (RCA-003), retains tokens with \(w > 0.05\), and normalizes weights relative to \(\max_j w_j\).explain_counterfactual(state_text, instructions_text, options, top_k=5): Computes baseline probabilities \(p(y \mid s)\) and winning option \(y^* = \arg\max_y p(y \mid s)\), then evaluates leave-one-token-out ablations \(s \setminus \{w_i\}\), recordingprobability_drop\(= p(y^* \mid s) - p(y^* \mid s \setminus \{w_i\})\) andflips_decision\(= (\arg\max_y p(y \mid s \setminus \{w_i\}) \neq y^*)\).
4. Gear 2 Specification: AnyJevPrefillBackend, Theorem 1 \(L_0\) & Van der Corput¶
Implemented in src/microllm/backends/prefill_llm.py following Nokia Applied Research's AnyJev Technical Report (arXiv:2610.00831):
4.1 Formal Proof of AnyJev Theorem 1 (l0_circular_rotation_readout)¶
Suppose a causal prefill model assigns log-probability to option \(i \in \{0,\dots,K-1\}\) when placed in prompt slot \(j = (i - t) \bmod K\) during circular shift \(t \in \{0,\dots,K-1\}\) according to the additive slot-bias model:
where \(s_i\) is the true intrinsic semantic score of option \(i\), \(b_j\) is the structural position bias of slot \(j\), and \(Z_t\) is the partition function of pass \(t\). Averaging in log-probability space across the cyclic group \(t = 0,\dots,K-1\):
Taking the softmax over \(\bar{z}\) cancels every additive constant:
which is algebraically independent of the slot biases \(b_j\).
4.2 Binary-Reflected Van der Corput Schedule (van_der_corput_order) & Dynamic \(\tau(K, \alpha)\) Early Stopping¶
To avoid running all \(K\) passes when a clear winner emerges early (IMP-004), rotations are scheduled in binary-reflected Van der Corput order:
After at least min_passes = 2 (initial + antipodal shift), evaluation halts as soon as the top-2 running log-odds margin satisfies \(\mu(\bar{z}) = \bar{z}_{(1)} - \bar{z}_{(2)} \ge \tau(K, \alpha)\), where compute_dynamic_tau (IDEA-001) scales:
4.3 Canonical Key Sorting vs. Ordinal Preservation (RCA-002)¶
- For unordered primitives (
choice,noul,multi),canonicalize_order=Truelexicographically sorts(key, description)prior to executingl0_circular_rotation_readoutand maps probabilities back to the caller's key order afterward. This guarantees0.000000order-flip rate and0.000000max probability drift even when early stopping triggers at \(T = 2 < K\). - For ordinal
scorequestions,canonicalize_order=Falsepreserves the natural order0..K-1per AnyJev Appendix E.
4.4 Answer Mass Gate (compute_answer_mass, IDEA-005) & Prior Debiasing (apply_prior_debiasing, OnlinePriorTracker, IDEA-006)¶
- Answer Mass Gate: \(m(s, \pi) = \sum_{j=1}^K P_{\text{vocab}}(\text{token} = \ell_j) \in [0, 1]\), emitting
answer_mass_gate_passed = (m(s, \pi) >= 0.15)inx_l0_meta. - Prior Correction: Given empirical or streaming EMA prior \(\hat{q}\) (
OnlinePriorTracker(momentum=0.05, alpha=0.75)):
5. StartLux Cascade (DualGearCascadeBackend) & 25-Way Hierarchical Tournament¶
5.1 StartLux Read-or-Think Cascade (src/microllm/backends/cascade.py)¶
- Gear 1 Fast Pass: Compute \(p_0 = \text{Gear1}(s, q)\), confidence \(c_0\), and conformal abstention flag
x_abstain. - Gating Rule: If \(c_0 \ge g\) (
gate_threshold = 0.75) andx_abstain == False, return \(p_0\) immediately (x_gear_used = "gear1_fast"). - Gear 2 Escalation & Fusion: Otherwise evaluate \(p_1 = \text{Gear2}_{L_0}(s, q)\) and return:
- Adaptive Fusion Weight (
compute_adaptive_alpha,IDEA-002):
5.2 25-Way Hierarchical Tournament (run_hierarchical_tournament)¶
For choice questions with \(K \in (25, 255]\) options (StartLux-Decision §3.2):
1. Optional snake/stride interleaving (seed_diversity=True, IDEA-007) distributes lexically adjacent options across \(\lceil K / 25 \rceil\) brackets.
2. Each chunk of \(\le 25\) options is scored independently; the top \(M = 3\) options per chunk advance to the finalist playoff round.
3. Non-finalist probabilities are rescaled below the minimum finalist probability of their chunk (min_finalist * 0.25 * rel_local / denom) and the full \(K\)-vector is normalized via sanitize_and_normalize_probabilities, preserving strict dominance and \(\sum_{i=1}^K p_i = 1.0\).
6. Statistical Calibration, Conformal Prediction & Clopper-Pearson Certification¶
Implemented in src/microllm/calibration.py:
| Component | Class / Function | Mathematical Formulation |
|---|---|---|
| Per-\(K\) Temperature Scaling | PerKTemperatureScaler |
Fits scalar \(T_K \in [0.05, 10.0]\) per cardinality \(K\) minimizing \(\text{NLL}(z/T_K, y) + 0.5\,\text{Brier}(z/T_K, y)\) via bounded scalar optimization; interpolates linearly in \(\ln K\) for unseen cardinalities (IMP-003). |
\(L_2\) Vector Scaling (IDEA-004) |
VectorScalingCalibrator |
Fits per-class scale \(\mathbf{a} \in \mathbb{R}^K\) and bias \(\mathbf{b} \in \mathbb{R}^K\) via BFGS on \(\text{NLL}(\mathbf{a}\odot z + \mathbf{b}, y) + 0.5\,\text{Brier} + \lambda(\|\mathbf{a}-\mathbf{1}\|_2^2 + \|\mathbf{b}\|_2^2)\). |
| Split Conformal Prediction | SplitConformalCalibrator |
Non-conformity \(s_i = 1 - p(y_i \mid x_i)\); finite-sample quantile \(\hat{q}_{1-\alpha} = \text{Quantile}_{\text{higher}}\!\left(\{s_i\}_{i=1}^N; \min\!\left(1, \frac{\lceil(N+1)(1-\alpha)\rceil}{N}\right)\right)\); prediction set \(C_\alpha(x) = \{k : p_k \ge 1 - \hat{q}_{1-\alpha}\}\); abstain = (|C_α(x)| != 1). |
Mondrian Conformal (IDEA-003) |
fit_mondrian / predict_set_mondrian |
Class-conditional quantiles \(\hat{q}_{1-\alpha}^{(k)}\) per class \(k\) (falling back to global \(\hat{q}_{1-\alpha}\) when \(n_k < 3\)). |
| Clopper-Pearson Risk Bound | clopper_pearson_threshold |
One-sided exact binomial upper bound \(U(e, n_{\text{acc}}, \delta) = \text{Beta}^{-1}(1 - \delta;\, e + 1,\, n_{\text{acc}} - e)\); selects lowest confidence threshold \(\tau\) where \(U \le r_{\text{target}}\). |
Pareto Cascade Auto-Tuner (IDEA-010) |
tune_cascade_pareto |
Sweeps \((g, \alpha) \in [0.10, 0.95] \times [0.25, 0.95]\) subject to \(\mathbb{P}(c_0 < g) \le \text{max\_escalation\_rate}\) to minimize fused Brier score. |
7. Two-Stage OpenJev-RLCD² Local Training Engine (src/microllm/rlcd.py)¶
Implements Proposition 1, Algorithm 1 ("Calibrate, then Reinforce"), and Appendix A from OpenJev-RLCD (arXiv:2609.38850) combined with \(\text{RLCD}^2\) decision weights from StartLux-Decision (arXiv:2610.17309):
- Strictly Proper Shifted Brier Reward (
shifted_brier_reward):
- Proposition 1 Variance Identity (
group_mean_variance_identity,IMP-001):
Proves that scoring the group mean \(\bar{p} = \mathbb{E}_r[u(r)]\) adds an artificial diversity bonus \(\mathbb{E}_r[\|u(r) - \bar{p}\|_2^2] \ge 0\) that rewards ungrounded rationale disagreement.
3. \(\text{RLCD}^2\) \(\text{Beta}(8, 2)\) Decision Weight (beta_decision_weight):
- Stage 1 (Pathwise Readout Calibration,
stage1_pathwise_loss_and_grad): - Minimizes \(L_1(z, y) = \text{sg}(w(c)) \cdot \|u - e_y\|_2^2\) via analytical Jacobian \(\nabla_z L_1 = u \odot (g_u - u^\top g_u)\) where \(g_u = 2 w(c)(u - e_y)\), then freezes the Stage-1 policy anchor \(\theta_1\).
- Stage 2 (KL-Anchored Leave-One-Out REINFORCE,
compute_leave_one_out_kl_advantages): - For \(M = 4\) sampled latent rationales \(r^{(1)}, \dots, r^{(M)} \sim \pi_\theta(\cdot \mid x)\):
- Verified to
< 10^{-12}analytical gradient error via full \(R^M \times K\) tabular enumeration inverify_tabular_rlcd_unbiased_gradient.
8. Complete jevcompat 0.1 Wire Protocol & 32/32 MUST Compliance Matrix¶
Every requirement below is enforced in src/microllm/schemas.py and src/microllm/server.py and tested in tests/test_jevcompat_contract.py:
| # | Requirement ID | Section | Normative Specification (jevcompat 0.1) |
Enforcing Code Symbol | Test Verification |
|---|---|---|---|---|---|
| 1 | http.models |
§1 HTTP | GET /v1/models returns JSON {"models": [{"name", "description", "release_date"}]} |
list_models (server.py) |
PASS |
| 2 | http.endpoint |
§1 HTTP | POST /v1/systemone accepts JSON request and returns JSON 200 OK |
systemone_endpoint (server.py) |
PASS |
| 3 | http.auth |
§1 HTTP | Enforces Authorization: Bearer <key> returning 401 when MICROLLM_API_KEY is configured |
_check_auth (server.py) |
PASS |
| 4 | request.state-required |
§2 Request | Top-level state field is mandatory (422 if missing or null) |
SystemOneRequest.validate_state |
PASS |
| 5 | request.state-types |
§2 Request | state accepts str, JSON dict, or JSON list (rejects numbers/booleans/null) |
StructuredText, validate_state |
PASS |
| 6 | request.questions-required |
§2 Request | Top-level questions mapping is mandatory |
SystemOneRequest.questions |
PASS |
| 7 | request.questions-non-empty |
§2 Request | questions must contain at least 1 question (len >= 1) |
validate_questions_non_empty |
PASS |
| 8 | request.model-optional |
§2 Request | model is optional and defaults to "jev-latest" |
SystemOneRequest.model |
PASS |
| 9 | response.top-level |
§3 Response | Top-level response contains model (str), answers (dict), and usage (UsageInfo) |
SystemOneResponse |
PASS |
| 10 | response.answer-keys-match |
§3 Response | answers.keys() matches questions.keys() 1-for-1 |
systemone_endpoint |
PASS |
| 11 | response.usage-shape |
§3 Response | usage contains non-negative integers input_tokens and output_tokens |
UsageInfo (schemas.py) |
PASS |
| 12 | noul.minimal |
§4.2 Noul | {"type": "noul"} works with both instructions and criteria omitted |
NoulQuestion |
PASS |
| 13 | noul.criteria-optional |
§4.2 Noul | criteria may be None, {}, {"true": ...}, {"false": ...}, or both |
NoulQuestion.validate_noul_criteria |
PASS |
| 14 | noul.criteria-keys |
§4.2 Noul | Any key in noul.criteria outside {"true", "false"} is rejected with 422 |
NoulQuestion.validate_noul_criteria |
PASS |
| 15 | noul.answer-shape |
§4.2 Noul | Returns {"type": "noul", "noul": float} in [0, 1] with no confidence field |
NoulAnswer (schemas.py) |
PASS |
| 16 | choice.criteria-required |
§4.3 Choice | criteria mapping is required on choice questions |
ChoiceQuestion.criteria |
PASS |
| 17 | choice.criteria-bounds |
§4.3 Choice | choice.criteria must have between 2 and 255 options (422 on <2 or >255) |
validate_choice_options |
PASS |
| 18 | choice.option-values |
§4.3 Choice | Option values may be null, str, JSON dict, or JSON list |
StructuredText \| None |
PASS |
| 19 | choice.answer-shape |
§4.3 Choice | Returns {"type": "choice", "choice", "probabilities", "confidence"} |
ChoiceAnswer (schemas.py) |
PASS |
| 20 | choice.choice-in-criteria |
§4.3 Choice | Winning choice key is always a member of criteria.keys() |
evaluate_choice |
PASS |
| 21 | choice.probabilities-keys |
§4.3 Choice | probabilities.keys() equals criteria.keys() |
sanitize_and_normalize_probabilities |
PASS |
| 22 | choice.probabilities-valid |
§4.3 Choice | Finite floats in [0, 1] summing to 1.0 (±1e-6) |
sanitize_and_normalize_probabilities |
PASS |
| 23 | choice.confidence-range |
§4.3 Choice | confidence == (n * max_p - 1) / (n - 1) in [0, 1] |
choice_confidence (confidence.py) |
PASS |
| 24 | score.criteria-required |
§4.4 Score | criteria ordered list is required on score questions (rejects dicts) |
ScoreQuestion.reject_map_and_bounds |
PASS |
| 25 | score.criteria-bounds |
§4.4 Score | score.criteria must contain between 2 and 10 levels (422 on <2 or >10) |
ScoreQuestion.reject_map_and_bounds |
PASS |
| 26 | score.answer-shape |
§4.4 Score | Returns {"type": "score", "score", "legend", "probabilities", "confidence"} |
ScoreAnswer (schemas.py) |
PASS |
| 27 | score.score-range |
§4.4 Score | score == sum(i * p_i) in [0, n - 1] |
score_expectation (confidence.py) |
PASS |
| 28 | score.legend-matches |
§4.4 Score | legend maps "0".."n-1" to exact input criteria[i] descriptions |
_evaluate_isolated_question |
PASS |
| 29 | score.probabilities-keys |
§4.4 Score | probabilities.keys() equals {"0", "1", ..., str(n - 1)} |
evaluate_score |
PASS |
| 30 | score.probabilities-valid |
§4.4 Score | Finite floats in [0, 1] summing to 1.0 (±1e-6) |
sanitize_and_normalize_probabilities |
PASS |
| 31 | score.confidence-range |
§4.4 Score | confidence == max(0, 1 - sum_i p_i |i - k*| / D) in [0, 1] |
score_confidence (confidence.py) |
PASS |
| 32 | errors.validation-shape |
§6 Errors | Malformed requests return HTTP 422 with {"detail": [{"loc": ["body", ...], "msg", "type"}]} |
validation_exception_handler |
PASS |
| 33 | errors.no-5xx |
§6 Errors | No client input (including NaN, Infinity, empty objects, bad types) ever triggers HTTP 5xx |
_ensure_finite_json (RCA-004) |
PASS |
| 34 | semantics.question-id |
§7 Semantics | Renaming a question ID ("q1" vs "custom_id") produces bit-identical probabilities |
_evaluate_isolated_question |
PASS |
| 35 | semantics.batching |
§7 Semantics | Evaluating a question alone vs. batched with sibling questions produces bit-identical results | _evaluate_isolated_question |
PASS |
| 36 | semantics.question-order |
§7 Semantics | Reordering questions inside questions produces bit-identical results |
_evaluate_isolated_question |
PASS |
9. Complete HTTP REST API Specification (17 Endpoints)¶
All routes are registered by create_app(api_key: str | None = None) in src/microllm/server.py:
| # | HTTP Method & Path | Request Model / Query Params | Response Payload Summary | Status Codes |
|---|---|---|---|---|
| 1 | GET /v1/models |
(None) | {"models": [{"name": "jev-latest" \| "microllm-gear1-fast" \| "microllm-gear2-anyjev-l0", "description": ..., "release_date": ...}]} |
200 |
| 2 | POST /v1/systemone |
SystemOneRequest ({model?, state, questions}) |
SystemOneResponse ({model, answers, usage}) |
200, 401, 422 |
| 3 | POST /v1/calibrate |
CalibrateRequest ({logits?, labels?, alpha, target_risk, delta, seed}) |
{cardinality_k, fitted_temperature, raw_brier, calibrated_brier, raw_ece, calibrated_ece, conformal_q_hat, clopper_pearson_certification, reliability_bins} |
200, 422 |
| 4 | POST /v1/rlcd |
StudioRLCDDemoRequest ({stage1_steps, stage2_steps, use_rlcd2_weights, seed, features?, labels?}) |
{initial_brier, stage1_brier, final_brier, initial_ece, final_ece, initial_accuracy, final_accuracy, history, initial_reliability_bins, final_reliability_bins, risk_coverage_curve, clopper_pearson_certification, proposition1_variance_identity} |
200, 422 |
| 5 | POST /v1/studio/rlcd-demo |
StudioRLCDDemoRequest |
Identical to POST /v1/rlcd (used by Decision Studio RLCD² Lab) |
200, 422 |
| 6 | POST /v1/studio/analyze |
StudioAnalyzeRequest ({state, questions, gate_threshold, alpha, run_order_flip_test}) |
{gear1, gear2, cascade, order_flip_audit, token_attribution} |
200, 422 |
| 7 | POST /v1/guardrail |
GuardrailRequest ({state, context?, threshold=0.55, custom_rubrics?}) |
{safe, action ("allow"\|"review"\|"block"), risk_score, groundedness_score, checks, token_attribution, latency_ms} |
200, 422 |
| 8 | POST /v1/batch |
BatchRequest ({items (1..500), questions, model}) |
{summary: {total_items, abstained_count, total_latency_ms, avg_latency_ms, p50_latency_ms, p95_latency_ms}, results: [...]} |
200, 422 |
| 9 | GET /v1/benchmark |
(None) | Returns cached benchmarks/latest_results.json (or executes 540-item suite if uncached) |
200 |
| 10 | POST /v1/benchmark |
{"save_artifacts": bool} (optional) |
Runs the 540-item 5-track benchmark suite live and returns full JSON + markdown_table |
200 |
| 10a | POST /v1/benchmark/run |
{"suite"?: str, "save_artifacts"?: bool} (optional) |
Triggers asynchronous benchmark execution with concurrent write lock and returns run metadata | 200, 409 |
| 10b | GET /v1/benchmark/external & POST /v1/benchmark/external |
{"save_artifacts"?: bool, "full_splits"?: bool, "entries_per_dataset"?: int, "scale_per_dataset"?: int, "fetch_live"?: bool, "datasets"?: list[str]} |
Returns or runs the 16-dataset external web benchmark suite (benchmarks/web_benchmarks_full_results.json or benchmarks/web_benchmarks_results.json) |
200 |
| 10c | GET /v1/benchmark/hf-jev-models & POST /v1/benchmark/hf-jev-models |
{"save_artifacts"?: bool, "entries_per_dataset"?: int, "fetch_live"?: bool, "datasets"?: list[str]} |
Returns or runs the 12-dataset Hugging Face JEV models ecosystem benchmark suite (benchmarks/hf_jev_models_benchmarks_results.json) |
200 |
| 10d | GET /v1/jev-models |
Query params: q?, primitive?, dataset? |
{total, source_search_url, datasets_enriched, linked_jev_datasets, total_external_datasets, models: [...]} cataloging 25 HF JEV ecosystem models and 12 linked datasets |
200 |
| 11 | GET /v1/profiles |
(None) | {"profiles": list_profiles()} (fast-cpu-int8, multilingual, guardrail) |
200 |
| 12 | POST /v1/profiles/pull |
ProfilePullRequest ({profile, cache_dir?, download_weights, from_hub}) |
Quantizes and installs profile, returning profile_manifest.json with sha256_checksum |
200, 422 |
| 12b | POST /v1/mcp |
JSON-RPC 2.0 MCP Request (initialize, ping, tools/list, tools/call) |
Executes Model Context Protocol (systemone_decide, systemone_guardrail, systemone_calibrate) over HTTP |
200 |
| 13 | GET /v1/papers |
Query params: pillar?, q?, arxiv_id? |
{total, taxonomy, papers: [...]} from the 104-paper catalog |
200, 404 |
| 14 | GET /v1/metrics |
(None) | {total_requests, systemone_requests, guardrail_requests, batch_requests, guardrail_blocked, abstained_decisions, latency_p50_ms, latency_p95_ms} |
200 |
| 15 | GET / |
(None) | Serves interactive Decision Studio HTML application (src/microllm/static/index.html) |
200 |
| 16 | GET /documentation |
(None) | Serves interactive HTML technical documentation (docs/index.html) |
200 |
| 17 | GET /assets/{asset_name} & GET /papers/{paper_name} |
Path parameter (logo.svg, header-banner.svg, or <id>.pdf) |
Serves verified .svg or .pdf files with strict path-traversal containment |
200, 404 |
10. Strict Pydantic v2 Data Models & Validation Rules (src/microllm/schemas.py)¶
All wire schemas use Pydantic v2 with discriminated unions (Annotated[Union[NoulQuestion, ChoiceQuestion, ScoreQuestion, MultiQuestion], Field(discriminator="type")]):
StructuredText = Union[str, dict[str, Any], list[Any]]
class SystemOneRequest(BaseModel):
model: str = "jev-latest"
state: StructuredText
questions: dict[str, QuestionSpec] # Non-empty, non-empty string keys
class NoulQuestion(BaseModel):
type: Literal["noul"] = "noul"
instructions: StructuredText | None = None
criteria: dict[str, StructuredText | None] | None = None # Keys subset of {"true", "false"}
class ChoiceQuestion(BaseModel):
type: Literal["choice"] = "choice"
instructions: StructuredText | None = None
criteria: dict[str, StructuredText | None] # 2 <= len(criteria) <= 255
class ScoreQuestion(BaseModel):
type: Literal["score"] = "score"
instructions: StructuredText | None = None
criteria: list[StructuredText] # Must be a JSON array (list), 2 <= len(criteria) <= 10
class MultiQuestion(BaseModel):
type: Literal["multi"] = "multi"
instructions: StructuredText | None = None
criteria: dict[str, StructuredText | None] # 2 <= len(criteria) <= 255
threshold: float = Field(default=0.5, ge=0.0, le=1.0)
Recursive Non-Finite Float Rejection (_ensure_finite_json)¶
Python's standard json.loads accepts NaN, Infinity, and -Infinity by default, which violates RFC 8259 and jevcompat 0.1 §6 (RCA-004). _ensure_finite_json recursively traverses every string, float, dict key/value, and list element in state, instructions, and criteria, raising a ValueError caught by validation_exception_handler to return a clean HTTP 422 response.
11. Hardware Profile Registry & Symmetric INT8 Quantization (src/microllm/registry.py)¶
11.1 Symmetric INT8 Quantization (quantize_matrix_int8 & dequantize_matrix_int8)¶
Given a floating-point weight matrix \(W \in \mathbb{R}^{d_{\text{in}} \times d_{\text{out}}}\):
- Compression Ratio:
8.0xvsfloat64(4.0xvsfloat32). - Reconstruction MSE SLA: \(\frac{1}{d_{\text{in}} d_{\text{out}}}\|W - \widehat{W}\|_F^2 \le 10^{-3}\) (measured:
1.8 \times 10^{-5}on Quality GateG8). - Cryptographic Supply-Chain Verification (
verify_profile,IDEA-014):pull_profilecomputeshashlib.sha256(npz_path.read_bytes()).hexdigest(), storessha256_checksuminprofile_manifest.json, and verifies exact byte integrity on load.
12. Non-Functional Requirements (NFRs), Security, CI/CD & Verification Traceability¶
12.1 Non-Functional Requirements (NFRs) & Performance SLAs¶
| NFR ID | Category | Target SLA Specification | Measured Production Value | Verification Suite |
|---|---|---|---|---|
| NFR-01 | Single-Request CPU Latency (p50 / p95) |
p50 <= 5.0 ms, p95 <= 15.0 ms on CPU |
p50 = 0.076 ms, p95 = 0.274 ms (11,000 suite) |
BENCHMARKS.md |
| NFR-02 | Batch Throughput (CPU) | >= 500 decisions/sec |
8,601.0 entries/sec (11,000 entries in 1.28 s) |
tests/test_quality_validation_suite.py |
| NFR-03 | Option-Order Invariance (AnyJev L0) |
Order-Flip Rate == 0.000000, Drift <= 1e-9 |
0.000000 Flip Rate, 0.000000 Drift (78.3% fewer passes) |
tests/test_anyjev_rotations.py |
| NFR-04 | Selective Decision Accuracy (\(\tau = 0.45\)) | >= 99.0% on non-abstained predictions |
100.00% Selective Accuracy (100% of failures caught) |
BENCHMARKS.md |
| NFR-05 | Wire Contract & Resilience | 32/32 MUST pass rate, 0 HTTP 5xx errors |
32/32 PASS, 0 HTTP 5xx across adversarial fuzzing |
tests/test_jevcompat_contract.py |
| NFR-06 | Automated RCA Non-Regression | 15/15 historical RCAs verified on every run |
15 / 15 PASS (100.0% accuracy, p50 < 2.5 ms) |
tests/test_rca_runner.py |
12.2 Security Architecture¶
- Supply-Chain Revision Pinning (
Bandit B615,RCA-014): Bothcreate_hf_zero_shot_scorerandcreate_onnx_nli_scorerinsrc/microllm/backends/base.pyenforce an explicitrevision: str = "main"parameter on allAutoTokenizer.from_pretrainedandAutoModelForSequenceClassification.from_pretrainedcalls (CWE-494). - Strict Path Traversal Prevention: Static asset routes (
/assets/{asset_name}and/papers/{paper_name}) canonicalize paths via.resolve()and verifycandidate.parent == allowed_dirplus strict file extension allowlists (.svg,.pdf). - Zero External Telemetry or Secret Leakage: No hardcoded credentials exist in the codebase;
MICROLLM_API_KEYis read exclusively from environment variables or constructor injection.
12.3 Automated CI/CD Pipeline Architecture (.github/workflows/)¶
ci.yml: Matrix unit tests (Python 3.10, 3.11, 3.12) +sdist/wheelbuild +twine check --strict.unit-tests.yml: Fullpytest --cov=microllmcoverage & JUnit XML artifact publishing.lint.yml: Ruff, Flake8, and Mypy static type checking (RCA-013).security.yml: Bandit SAST security scanning (RCA-014) +pip-auditdependency auditing.publish-pypi.yml: OIDC Trusted Publishing to PyPI and TestPyPI.release.yml: Automated GitHub Release creation onv*tags.python-package-conda.yml: Conda environment validation againstenvironment.yml(RCA-009).jekyll-docker.yml: Documentation publishing workflow.