diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..b1d2c0a --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,24 @@ +name: validate-corpus + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: pip + cache-dependency-path: requirements-dev.txt + - name: Install validation dependencies + run: python -m pip install -r requirements-dev.txt + - name: Validate schemas, records, and references + run: python tools/validate.py diff --git a/data/claims/deepseek-v2-uses-deepseekmoe.yaml b/data/claims/deepseek-v2-uses-deepseekmoe.yaml new file mode 100644 index 0000000..f8944e3 --- /dev/null +++ b/data/claims/deepseek-v2-uses-deepseekmoe.yaml @@ -0,0 +1,9 @@ +id: claim:deepseek-v2-uses-deepseekmoe +type: claim +subject: release:deepseek-v2 +predicate: uses_technique +object: technique:deepseek-moe +status: confirmed_primary +evidence: + - source: source:deepseek-v2-paper + locator: Abstract diff --git a/data/claims/deepseek-v2-uses-mla.yaml b/data/claims/deepseek-v2-uses-mla.yaml new file mode 100644 index 0000000..52bb7a4 --- /dev/null +++ b/data/claims/deepseek-v2-uses-mla.yaml @@ -0,0 +1,9 @@ +id: claim:deepseek-v2-uses-mla +type: claim +subject: release:deepseek-v2 +predicate: uses_technique +object: technique:multi-head-latent-attention +status: confirmed_primary +evidence: + - source: source:deepseek-v2-paper + locator: Abstract diff --git a/data/claims/deepseek-v3-total-parameters.yaml b/data/claims/deepseek-v3-total-parameters.yaml new file mode 100644 index 0000000..9d44bb7 --- /dev/null +++ b/data/claims/deepseek-v3-total-parameters.yaml @@ -0,0 +1,9 @@ +id: claim:deepseek-v3-total-parameters +type: claim +subject: release:deepseek-v3 +predicate: total_parameters +value: 671000000000 +status: confirmed_primary +evidence: + - source: source:deepseek-v3-report + locator: Abstract diff --git a/data/claims/deepseek-v3-uses-deepseekmoe.yaml b/data/claims/deepseek-v3-uses-deepseekmoe.yaml new file mode 100644 index 0000000..dfd01f6 --- /dev/null +++ b/data/claims/deepseek-v3-uses-deepseekmoe.yaml @@ -0,0 +1,9 @@ +id: claim:deepseek-v3-uses-deepseekmoe +type: claim +subject: release:deepseek-v3 +predicate: uses_technique +object: technique:deepseek-moe +status: confirmed_primary +evidence: + - source: source:deepseek-v3-report + locator: Abstract diff --git a/data/claims/deepseek-v3-uses-mla.yaml b/data/claims/deepseek-v3-uses-mla.yaml new file mode 100644 index 0000000..3a53fb5 --- /dev/null +++ b/data/claims/deepseek-v3-uses-mla.yaml @@ -0,0 +1,9 @@ +id: claim:deepseek-v3-uses-mla +type: claim +subject: release:deepseek-v3 +predicate: uses_technique +object: technique:multi-head-latent-attention +status: confirmed_primary +evidence: + - source: source:deepseek-v3-report + locator: Abstract diff --git a/data/claims/deepseekmoe-extends-sparse-moe.yaml b/data/claims/deepseekmoe-extends-sparse-moe.yaml new file mode 100644 index 0000000..95fe441 --- /dev/null +++ b/data/claims/deepseekmoe-extends-sparse-moe.yaml @@ -0,0 +1,9 @@ +id: claim:deepseekmoe-extends-sparse-moe +type: claim +subject: technique:deepseek-moe +predicate: extends +object: technique:sparse-mixture-of-experts +status: confirmed_primary +evidence: + - source: source:deepseekmoe-paper + locator: Abstract diff --git a/data/claims/gqa-generalizes-mqa.yaml b/data/claims/gqa-generalizes-mqa.yaml new file mode 100644 index 0000000..0cec1a5 --- /dev/null +++ b/data/claims/gqa-generalizes-mqa.yaml @@ -0,0 +1,9 @@ +id: claim:gqa-generalizes-mqa +type: claim +subject: technique:grouped-query-attention +predicate: generalizes +object: technique:multi-query-attention +status: confirmed_primary +evidence: + - source: source:gqa-paper + locator: Abstract diff --git a/data/claims/llama-2-parameter-range.yaml b/data/claims/llama-2-parameter-range.yaml new file mode 100644 index 0000000..fb700a1 --- /dev/null +++ b/data/claims/llama-2-parameter-range.yaml @@ -0,0 +1,11 @@ +id: claim:llama-2-parameter-range +type: claim +subject: release:llama-2 +predicate: parameter_range +value: + minimum: 7000000000 + maximum: 70000000000 +status: confirmed_primary +evidence: + - source: source:llama-2-paper + locator: Abstract diff --git a/data/claims/llama-2-release-of-family.yaml b/data/claims/llama-2-release-of-family.yaml new file mode 100644 index 0000000..c79f7f1 --- /dev/null +++ b/data/claims/llama-2-release-of-family.yaml @@ -0,0 +1,9 @@ +id: claim:llama-2-release-of-family +type: claim +subject: release:llama-2 +predicate: release_of +object: family:llama +status: confirmed_primary +evidence: + - source: source:llama-2-paper + locator: Abstract diff --git a/data/claims/llama-3-context-window.yaml b/data/claims/llama-3-context-window.yaml new file mode 100644 index 0000000..76c9cd4 --- /dev/null +++ b/data/claims/llama-3-context-window.yaml @@ -0,0 +1,9 @@ +id: claim:llama-3-context-window +type: claim +subject: release:llama-3 +predicate: context_window_tokens +value: 128000 +status: confirmed_primary +evidence: + - source: source:llama-3-paper + locator: Abstract diff --git a/data/claims/llama-3-largest-model-parameters.yaml b/data/claims/llama-3-largest-model-parameters.yaml new file mode 100644 index 0000000..64b831a --- /dev/null +++ b/data/claims/llama-3-largest-model-parameters.yaml @@ -0,0 +1,9 @@ +id: claim:llama-3-largest-model-parameters +type: claim +subject: release:llama-3 +predicate: largest_model_parameters +value: 405000000000 +status: confirmed_primary +evidence: + - source: source:llama-3-paper + locator: Abstract diff --git a/data/claims/llama-3-release-of-family.yaml b/data/claims/llama-3-release-of-family.yaml new file mode 100644 index 0000000..3b4239c --- /dev/null +++ b/data/claims/llama-3-release-of-family.yaml @@ -0,0 +1,9 @@ +id: claim:llama-3-release-of-family +type: claim +subject: release:llama-3 +predicate: release_of +object: family:llama +status: confirmed_primary +evidence: + - source: source:llama-3-paper + locator: Abstract diff --git a/data/claims/mqa-variant-of-mha.yaml b/data/claims/mqa-variant-of-mha.yaml new file mode 100644 index 0000000..404bc3c --- /dev/null +++ b/data/claims/mqa-variant-of-mha.yaml @@ -0,0 +1,9 @@ +id: claim:mqa-variant-of-mha +type: claim +subject: technique:multi-query-attention +predicate: variant_of_technique +object: technique:multi-head-attention +status: confirmed_primary +evidence: + - source: source:multi-query-attention + locator: Abstract diff --git a/data/families/deepseek.yaml b/data/families/deepseek.yaml new file mode 100644 index 0000000..d40ce88 --- /dev/null +++ b/data/families/deepseek.yaml @@ -0,0 +1,4 @@ +id: family:deepseek +type: model_family +name: DeepSeek +status: draft diff --git a/data/families/llama.yaml b/data/families/llama.yaml new file mode 100644 index 0000000..ade7ab3 --- /dev/null +++ b/data/families/llama.yaml @@ -0,0 +1,4 @@ +id: family:llama +type: model_family +name: Llama +status: draft diff --git a/data/relationships/deepseek-v2-uses-deepseekmoe.yaml b/data/relationships/deepseek-v2-uses-deepseekmoe.yaml new file mode 100644 index 0000000..a37caaa --- /dev/null +++ b/data/relationships/deepseek-v2-uses-deepseekmoe.yaml @@ -0,0 +1,7 @@ +id: relationship:deepseek-v2-uses-deepseekmoe +type: relationship +subject: release:deepseek-v2 +predicate: uses_technique +object: technique:deepseek-moe +claim_refs: + - claim:deepseek-v2-uses-deepseekmoe diff --git a/data/relationships/deepseek-v2-uses-mla.yaml b/data/relationships/deepseek-v2-uses-mla.yaml new file mode 100644 index 0000000..05fa862 --- /dev/null +++ b/data/relationships/deepseek-v2-uses-mla.yaml @@ -0,0 +1,7 @@ +id: relationship:deepseek-v2-uses-mla +type: relationship +subject: release:deepseek-v2 +predicate: uses_technique +object: technique:multi-head-latent-attention +claim_refs: + - claim:deepseek-v2-uses-mla diff --git a/data/relationships/deepseek-v3-uses-deepseekmoe.yaml b/data/relationships/deepseek-v3-uses-deepseekmoe.yaml new file mode 100644 index 0000000..4866d54 --- /dev/null +++ b/data/relationships/deepseek-v3-uses-deepseekmoe.yaml @@ -0,0 +1,7 @@ +id: relationship:deepseek-v3-uses-deepseekmoe +type: relationship +subject: release:deepseek-v3 +predicate: uses_technique +object: technique:deepseek-moe +claim_refs: + - claim:deepseek-v3-uses-deepseekmoe diff --git a/data/relationships/deepseek-v3-uses-mla.yaml b/data/relationships/deepseek-v3-uses-mla.yaml new file mode 100644 index 0000000..a075678 --- /dev/null +++ b/data/relationships/deepseek-v3-uses-mla.yaml @@ -0,0 +1,7 @@ +id: relationship:deepseek-v3-uses-mla +type: relationship +subject: release:deepseek-v3 +predicate: uses_technique +object: technique:multi-head-latent-attention +claim_refs: + - claim:deepseek-v3-uses-mla diff --git a/data/relationships/llama-2-release-of-llama.yaml b/data/relationships/llama-2-release-of-llama.yaml new file mode 100644 index 0000000..57b6787 --- /dev/null +++ b/data/relationships/llama-2-release-of-llama.yaml @@ -0,0 +1,7 @@ +id: relationship:llama-2-release-of-llama +type: relationship +subject: release:llama-2 +predicate: release_of +object: family:llama +claim_refs: + - claim:llama-2-release-of-family diff --git a/data/relationships/llama-3-release-of-llama.yaml b/data/relationships/llama-3-release-of-llama.yaml new file mode 100644 index 0000000..7b67d73 --- /dev/null +++ b/data/relationships/llama-3-release-of-llama.yaml @@ -0,0 +1,7 @@ +id: relationship:llama-3-release-of-llama +type: relationship +subject: release:llama-3 +predicate: release_of +object: family:llama +claim_refs: + - claim:llama-3-release-of-family diff --git a/data/relationships/mha-precedes-mqa.yaml b/data/relationships/mha-precedes-mqa.yaml new file mode 100644 index 0000000..dc50792 --- /dev/null +++ b/data/relationships/mha-precedes-mqa.yaml @@ -0,0 +1,7 @@ +id: relationship:mha-precedes-mqa +type: relationship +subject: technique:multi-head-attention +predicate: conceptual_predecessor_of +object: technique:multi-query-attention +claim_refs: + - claim:mqa-variant-of-mha diff --git a/data/relationships/mqa-precedes-gqa.yaml b/data/relationships/mqa-precedes-gqa.yaml new file mode 100644 index 0000000..998c63b --- /dev/null +++ b/data/relationships/mqa-precedes-gqa.yaml @@ -0,0 +1,7 @@ +id: relationship:mqa-precedes-gqa +type: relationship +subject: technique:multi-query-attention +predicate: conceptual_predecessor_of +object: technique:grouped-query-attention +claim_refs: + - claim:gqa-generalizes-mqa diff --git a/data/relationships/sparse-moe-precedes-deepseekmoe.yaml b/data/relationships/sparse-moe-precedes-deepseekmoe.yaml new file mode 100644 index 0000000..6625aa9 --- /dev/null +++ b/data/relationships/sparse-moe-precedes-deepseekmoe.yaml @@ -0,0 +1,7 @@ +id: relationship:sparse-moe-precedes-deepseekmoe +type: relationship +subject: technique:sparse-mixture-of-experts +predicate: conceptual_predecessor_of +object: technique:deepseek-moe +claim_refs: + - claim:deepseekmoe-extends-sparse-moe diff --git a/data/releases/deepseek-v2.yaml b/data/releases/deepseek-v2.yaml new file mode 100644 index 0000000..41cab65 --- /dev/null +++ b/data/releases/deepseek-v2.yaml @@ -0,0 +1,4 @@ +id: release:deepseek-v2 +type: model_release +name: DeepSeek-V2 +status: draft diff --git a/data/releases/deepseek-v3.yaml b/data/releases/deepseek-v3.yaml new file mode 100644 index 0000000..537f160 --- /dev/null +++ b/data/releases/deepseek-v3.yaml @@ -0,0 +1,4 @@ +id: release:deepseek-v3 +type: model_release +name: DeepSeek-V3 +status: draft diff --git a/data/releases/llama-2.yaml b/data/releases/llama-2.yaml new file mode 100644 index 0000000..4a24913 --- /dev/null +++ b/data/releases/llama-2.yaml @@ -0,0 +1,4 @@ +id: release:llama-2 +type: model_release +name: Llama 2 +status: draft diff --git a/data/releases/llama-3.yaml b/data/releases/llama-3.yaml new file mode 100644 index 0000000..790558c --- /dev/null +++ b/data/releases/llama-3.yaml @@ -0,0 +1,4 @@ +id: release:llama-3 +type: model_release +name: Llama 3 +status: draft diff --git a/data/sources/deepseek-v2-paper.yaml b/data/sources/deepseek-v2-paper.yaml new file mode 100644 index 0000000..c9a9e06 --- /dev/null +++ b/data/sources/deepseek-v2-paper.yaml @@ -0,0 +1,8 @@ +id: source:deepseek-v2-paper +type: source +title: "DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model" +source_type: technical_report +url: https://arxiv.org/abs/2405.04434 +publisher: arXiv +published_at: '2024-05-07' +retrieved_at: '2026-09-29T06:10:00Z' diff --git a/data/sources/deepseek-v3-report.yaml b/data/sources/deepseek-v3-report.yaml new file mode 100644 index 0000000..832d014 --- /dev/null +++ b/data/sources/deepseek-v3-report.yaml @@ -0,0 +1,8 @@ +id: source:deepseek-v3-report +type: source +title: DeepSeek-V3 Technical Report +source_type: technical_report +url: https://arxiv.org/abs/2412.19437 +publisher: arXiv +published_at: '2024-12-27' +retrieved_at: '2026-09-29T06:10:00Z' diff --git a/data/sources/deepseekmoe-paper.yaml b/data/sources/deepseekmoe-paper.yaml new file mode 100644 index 0000000..43553d9 --- /dev/null +++ b/data/sources/deepseekmoe-paper.yaml @@ -0,0 +1,8 @@ +id: source:deepseekmoe-paper +type: source +title: "DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models" +source_type: paper +url: https://arxiv.org/abs/2401.06066 +publisher: arXiv +published_at: '2024-01-11' +retrieved_at: '2026-09-29T06:10:00Z' diff --git a/data/sources/gqa-paper.yaml b/data/sources/gqa-paper.yaml new file mode 100644 index 0000000..22c479e --- /dev/null +++ b/data/sources/gqa-paper.yaml @@ -0,0 +1,8 @@ +id: source:gqa-paper +type: source +title: "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints" +source_type: paper +url: https://arxiv.org/abs/2305.13245 +publisher: arXiv +published_at: '2023-05-22' +retrieved_at: '2026-09-29T06:10:00Z' diff --git a/data/sources/llama-2-paper.yaml b/data/sources/llama-2-paper.yaml new file mode 100644 index 0000000..63de19f --- /dev/null +++ b/data/sources/llama-2-paper.yaml @@ -0,0 +1,8 @@ +id: source:llama-2-paper +type: source +title: "Llama 2: Open Foundation and Fine-Tuned Chat Models" +source_type: technical_report +url: https://arxiv.org/abs/2307.09288 +publisher: arXiv +published_at: '2023-07-18' +retrieved_at: '2026-09-29T06:25:00Z' diff --git a/data/sources/llama-3-paper.yaml b/data/sources/llama-3-paper.yaml new file mode 100644 index 0000000..69a58b7 --- /dev/null +++ b/data/sources/llama-3-paper.yaml @@ -0,0 +1,8 @@ +id: source:llama-3-paper +type: source +title: The Llama 3 Herd of Models +source_type: technical_report +url: https://arxiv.org/abs/2407.21783 +publisher: arXiv +published_at: '2024-07-31' +retrieved_at: '2026-09-29T06:25:00Z' diff --git a/data/sources/multi-query-attention.yaml b/data/sources/multi-query-attention.yaml new file mode 100644 index 0000000..d7b0875 --- /dev/null +++ b/data/sources/multi-query-attention.yaml @@ -0,0 +1,8 @@ +id: source:multi-query-attention +type: source +title: "Fast Transformer Decoding: One Write-Head is All You Need" +source_type: paper +url: https://arxiv.org/abs/1911.02150 +publisher: arXiv +published_at: '2019-11-06' +retrieved_at: '2026-09-29T06:10:00Z' diff --git a/data/techniques/deepseek-moe.yaml b/data/techniques/deepseek-moe.yaml new file mode 100644 index 0000000..241efda --- /dev/null +++ b/data/techniques/deepseek-moe.yaml @@ -0,0 +1,4 @@ +id: technique:deepseek-moe +type: technique +name: DeepSeekMoE +status: draft diff --git a/data/techniques/grouped-query-attention.yaml b/data/techniques/grouped-query-attention.yaml new file mode 100644 index 0000000..664afb7 --- /dev/null +++ b/data/techniques/grouped-query-attention.yaml @@ -0,0 +1,6 @@ +id: technique:grouped-query-attention +type: technique +name: Grouped-Query Attention +aliases: + - GQA +status: draft diff --git a/data/techniques/multi-head-attention.yaml b/data/techniques/multi-head-attention.yaml new file mode 100644 index 0000000..1102700 --- /dev/null +++ b/data/techniques/multi-head-attention.yaml @@ -0,0 +1,6 @@ +id: technique:multi-head-attention +type: technique +name: Multi-Head Attention +aliases: + - MHA +status: draft diff --git a/data/techniques/multi-head-latent-attention.yaml b/data/techniques/multi-head-latent-attention.yaml new file mode 100644 index 0000000..f5bae2c --- /dev/null +++ b/data/techniques/multi-head-latent-attention.yaml @@ -0,0 +1,6 @@ +id: technique:multi-head-latent-attention +type: technique +name: Multi-Head Latent Attention +aliases: + - MLA +status: draft diff --git a/data/techniques/multi-query-attention.yaml b/data/techniques/multi-query-attention.yaml new file mode 100644 index 0000000..9477e60 --- /dev/null +++ b/data/techniques/multi-query-attention.yaml @@ -0,0 +1,6 @@ +id: technique:multi-query-attention +type: technique +name: Multi-Query Attention +aliases: + - MQA +status: draft diff --git a/data/techniques/sparse-mixture-of-experts.yaml b/data/techniques/sparse-mixture-of-experts.yaml new file mode 100644 index 0000000..45480ba --- /dev/null +++ b/data/techniques/sparse-mixture-of-experts.yaml @@ -0,0 +1,6 @@ +id: technique:sparse-mixture-of-experts +type: technique +name: Sparse Mixture-of-Experts +aliases: + - Sparse MoE +status: draft diff --git a/docs/seed-corpus.md b/docs/seed-corpus.md new file mode 100644 index 0000000..3ccbabc --- /dev/null +++ b/docs/seed-corpus.md @@ -0,0 +1,13 @@ +# Seed corpus v0.1 + +The first ModelMap corpus is intentionally small. Its job is to exercise the ontology and provenance chain before broad ingestion. + +It establishes three proof paths: + +1. **attention lineage:** multi-head attention → multi-query attention → grouped-query attention; +2. **latent attention adoption:** DeepSeek-V2 and DeepSeek-V3 using multi-head latent attention; +3. **sparse-compute lineage:** sparse mixture-of-experts → DeepSeekMoE, followed by DeepSeek-V2/V3 adoption. + +Every graph edge in this seed is backed by an atomic claim and a primary paper or technical report. The seed deliberately does **not** create a direct lineage edge from GQA to MLA: shared motivation or chronology is not sufficient evidence for ancestry. + +Primary sources represented: arXiv:1911.02150, arXiv:2305.13245, arXiv:2401.06066, arXiv:2405.04434, and arXiv:2412.19437. diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..6d99ed6 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +jsonschema>=4.23,<5 +PyYAML>=6.0,<7 diff --git a/schemas/relationship.schema.json b/schemas/relationship.schema.json index 773d870..1d940be 100644 --- a/schemas/relationship.schema.json +++ b/schemas/relationship.schema.json @@ -17,6 +17,7 @@ "checkpoint_derived_from", "fine_tuned_from", "distilled_from", + "conceptual_predecessor_of", "uses_architecture", "uses_technique", "introduces_technique", diff --git a/tools/validate.py b/tools/validate.py new file mode 100644 index 0000000..cddfbd6 --- /dev/null +++ b/tools/validate.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +"""Validate ModelMap canonical records and cross-record references.""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path +from typing import Any + +import yaml +from jsonschema import Draft202012Validator, FormatChecker + +ROOT = Path(__file__).resolve().parents[1] +DATA = ROOT / "data" +SCHEMAS = ROOT / "schemas" + +SCHEMA_BY_TYPE = { + "source": "source.schema.json", + "claim": "claim.schema.json", + "relationship": "relationship.schema.json", + "architecture_spec": "architecture.schema.json", +} + + +def load_document(path: Path) -> Any: + with path.open("r", encoding="utf-8") as fh: + if path.suffix == ".json": + return json.load(fh) + return yaml.safe_load(fh) + + +def load_schema(name: str) -> dict[str, Any]: + with (SCHEMAS / name).open("r", encoding="utf-8") as fh: + return json.load(fh) + + +def iter_records() -> list[tuple[Path, dict[str, Any]]]: + records: list[tuple[Path, dict[str, Any]]] = [] + for path in sorted(DATA.rglob("*")): + if path.suffix not in {".yaml", ".yml", ".json"}: + continue + doc = load_document(path) + if not isinstance(doc, dict): + raise ValueError(f"{path.relative_to(ROOT)} must contain one mapping/object") + records.append((path, doc)) + return records + + +def main() -> int: + errors: list[str] = [] + try: + records = iter_records() + except Exception as exc: + print(f"ERROR: failed to load corpus: {exc}") + return 1 + + schema_cache = { + name: load_schema(name) + for name in set(SCHEMA_BY_TYPE.values()) | {"entity.schema.json"} + } + by_id: dict[str, tuple[Path, dict[str, Any]]] = {} + + for path, record in records: + rel = path.relative_to(ROOT) + schema_name = SCHEMA_BY_TYPE.get(record.get("type"), "entity.schema.json") + validator = Draft202012Validator(schema_cache[schema_name], format_checker=FormatChecker()) + for err in sorted(validator.iter_errors(record), key=lambda e: list(e.path)): + location = ".".join(str(part) for part in err.path) or "" + errors.append(f"{rel}: {location}: {err.message}") + record_id = record.get("id") + if isinstance(record_id, str): + if record_id in by_id: + previous = by_id[record_id][0].relative_to(ROOT) + errors.append(f"{rel}: duplicate id {record_id!r}; first seen in {previous}") + else: + by_id[record_id] = (path, record) + + def require_id(owner: Path, ref: Any, expected_type: str | None = None) -> None: + rel = owner.relative_to(ROOT) + if not isinstance(ref, str): + errors.append(f"{rel}: reference must be a string, got {type(ref).__name__}") + return + target = by_id.get(ref) + if target is None: + errors.append(f"{rel}: unresolved reference {ref!r}") + return + if expected_type is not None and target[1].get("type") != expected_type: + errors.append(f"{rel}: {ref!r} must reference type {expected_type!r}, found {target[1].get('type')!r}") + + for path, record in records: + if record.get("type") == "claim": + require_id(path, record.get("subject")) + if "object" in record: + require_id(path, record.get("object")) + for evidence in record.get("evidence", []): + require_id(path, evidence.get("source"), "source") + elif record.get("type") == "relationship": + require_id(path, record.get("subject")) + require_id(path, record.get("object")) + for claim_ref in record.get("claim_refs", []): + require_id(path, claim_ref, "claim") + + if errors: + print(f"ModelMap validation failed with {len(errors)} error(s):") + for error in errors: + print(f" - {error}") + return 1 + + counts: dict[str, int] = {} + for _, record in records: + kind = str(record.get("type", "unknown")) + counts[kind] = counts.get(kind, 0) + 1 + summary = ", ".join(f"{kind}={count}" for kind, count in sorted(counts.items())) + print(f"ModelMap validation passed: {len(records)} records ({summary})") + return 0 + + +if __name__ == "__main__": + sys.exit(main())