{
  "schema_version": "maintenance-rag-design/1",
  "published": "2026-11-13",
  "status": "proposed_design_not_implemented_or_field_accepted",
  "scope": {
    "data": "synthetic_only_for_first_experiment",
    "mode": "read_only_decision_support",
    "deployment": "single_customer_local_workspace",
    "example_role": "maintenance_engineer",
    "languages": [
      "tr",
      "en"
    ],
    "excluded": [
      "OT commands",
      "automatic work orders",
      "automatic model training from feedback",
      "cloud fallback",
      "real customer data without separate authorization"
    ]
  },
  "contracts": {
    "ingestion_states": [
      "received",
      "processing",
      "needs_review",
      "ready",
      "superseded",
      "rejected",
      "failed"
    ],
    "transitions": {
      "received": [
        "processing",
        "rejected"
      ],
      "processing": [
        "needs_review",
        "ready",
        "failed"
      ],
      "needs_review": [
        "processing",
        "ready",
        "rejected"
      ],
      "ready": [
        "superseded",
        "rejected"
      ],
      "failed": [
        "processing",
        "rejected"
      ],
      "superseded": [],
      "rejected": []
    },
    "approval": "Only an authenticated reviewer can approve needs_review; preserve original and corrected extraction as separate revisions.",
    "source_fields": [
      "workspace_id",
      "document_id",
      "document_version",
      "asset_ids",
      "sha256",
      "mime",
      "byte_size",
      "page_index",
      "printed_page_label",
      "item_id",
      "table_id",
      "row",
      "column",
      "row_span",
      "column_span",
      "bbox",
      "coord_origin",
      "extraction_revision",
      "raw_text",
      "normalized_text",
      "review_status",
      "effective_from",
      "effective_to",
      "access_scope"
    ],
    "locations": "PDF page_index is one-based. Table row/column are zero-based. bbox is normalized [left, top, right, bottom] with top-left origin; null/absent if unavailable. Reject invalid ordering. Keep original extractor coordinates and conversion metadata.",
    "identity": "Unique(workspace_id, sha256, extraction_revision). Reimport is idempotent; a content or extractor change makes a new version.",
    "revision": "Applicability and explicit supersession determine the active document; upload time alone never selects authority. Keep earlier versions as historical evidence.",
    "answer_schema": "answer.schema.json",
    "answer_status": "Non-answered outputs contain no publishable statements. Internal review drafts and conflict evidence live in restricted job records, separate from the public answer.",
    "review_binding": [
      "answer_id",
      "answer_content_hash",
      "source_versions",
      "reviewer_id",
      "reviewed_at",
      "decision",
      "reason"
    ],
    "permission_recheck": [
      "retrieval",
      "answer read",
      "source view",
      "download",
      "export",
      "cache hit"
    ],
    "cache_key": [
      "workspace_id",
      "principal_scope_revision",
      "corpus_revision",
      "model_revision",
      "prompt_revision",
      "normalized_question",
      "selected_asset_ids",
      "selected_document_versions"
    ],
    "errors": {
      "401": "unauthenticated",
      "403": "forbidden_without_content_or_document_existence_leak",
      "409": "idempotency_or_version_conflict",
      "413": "upload_limit",
      "415": "unsupported_mime",
      "422": "invalid_contract",
      "503": "local_model_unavailable_no_cloud_fallback"
    },
    "audit": "Local request/job IDs, timings and version digests by default; no full customer text in operational logs."
  },
  "endpoints": [
    {
      "method": "POST",
      "path": "/documents",
      "behavior": "Authenticated upload of allowlisted files; size/MIME check, sha256, idempotency key; return 202 job_id."
    },
    {
      "method": "GET",
      "path": "/jobs/{id}",
      "behavior": "Authorized job status; no partial searchable corpus. Surface failure and retry reason."
    },
    {
      "method": "POST",
      "path": "/documents/{id}/versions/{version}/reviews",
      "behavior": "Authenticated reviewer action on an exact extraction revision; optimistic concurrency."
    },
    {
      "method": "POST",
      "path": "/answers",
      "behavior": "Validate server-derived workspace and scope; return 202 job_id; immutable corpus/model/prompt snapshot."
    },
    {
      "method": "GET",
      "path": "/answers/{id}",
      "behavior": "Recheck scope; return the schema-validated answer or access error."
    },
    {
      "method": "GET",
      "path": "/sources/{id}/versions/{version}/pages/{page}",
      "behavior": "Recheck scope; return the exact source revision and verified location."
    },
    {
      "method": "POST",
      "path": "/answers/{id}/reviews",
      "behavior": "Append a version-bound human review. Never silently overwrite the generated answer."
    }
  ],
  "retrieval": {
    "baseline": "lexical + exact vector search within authorized ready source versions",
    "fusion": "versioned reciprocal-rank fusion; preserve both candidate lists",
    "start_parameters": {
      "lexical_k": 20,
      "vector_k": 20,
      "context_k": 6,
      "rrf_k": 60
    },
    "parameter_status": "initial_experimental_values_to_tune_on_development_set_only",
    "scope": "Enforce predicates in every retrieval path; do not retrieve broadly and rely on the model to redact.",
    "tables": "Repeat table title, column headers, relevant row labels and footnotes in chunks; preserve canonical cell IDs. Never merge documents or revisions.",
    "answer_gate": "Existence/quote/numeric checks are necessary but not semantic proof. Check wrong asset, wrong row, conditions, negation and contradiction; human review remains explicit."
  },
  "implementation_slices": [
    {
      "id": "S1",
      "deliverable": "Synthetic fixtures, independent gold answers, schemas and no-model source viewer",
      "exit": "A human opens the correct page/cell; swapped source IDs are rejected."
    },
    {
      "id": "S2",
      "deliverable": "Idempotent ingestion, Turkish OCR and extraction review queue",
      "exit": "Clean/native/scanned/rotated/table cases preserve source identity and expose failures."
    },
    {
      "id": "S3",
      "deliverable": "Scoped lexical retrieval then embeddings, measured independently",
      "exit": "Gold source retrieval and revoked-scope tests pass before generation."
    },
    {
      "id": "S4",
      "deliverable": "Local model generation, schema and evidence gates",
      "exit": "Known, unknown, conflicting and malicious-document cases return the expected states."
    },
    {
      "id": "S5",
      "deliverable": "Bilingual source-linked UI and version-bound human review",
      "exit": "Language switching preserves context; source page/cell opens; keyboard/mobile flow works."
    },
    {
      "id": "S6",
      "deliverable": "Offline operation, restart/retry, backup/restore and acceptance report",
      "exit": "No outbound successful connection with egress blocked; restored permissions and citations match; independent operator can replay tests."
    }
  ],
  "acceptance": {
    "status": "proposed_thresholds_not_measurements",
    "development_set": "At least 30 synthetic pages; include Turkish/English, clean text, scans, tables, decimals and revisions.",
    "held_out_suite": {
      "total": 60,
      "answerable": 30,
      "missing": 10,
      "conflicting": 10,
      "forbidden_or_revoked": 10
    },
    "gates": {
      "correct_supported_answers": ">=27/30 answerable; refused answerable tasks count as failures",
      "source_locator": "Every emitted claim resolves to correct document version, page and item/cell in this test set",
      "numeric_integrity": "Zero wrong number, unit or table-row attribution in emitted claims in this test set",
      "negative_cases": "All missing/conflicting/access cases produce the required state; no restricted content leaks",
      "offline": "All required artifacts preloaded; test full pipeline with egress blocked and inspect attempted connections",
      "business": "Measure paired manual vs assisted find-and-verify time, with quality non-inferiority; agree target before permitted field pilot"
    },
    "measure": [
      "OCR CER by document class",
      "cell value/header/row accuracy",
      "gold-source Recall@k",
      "correct supported answer rate",
      "negative-case behavior",
      "human find-and-verify time",
      "p50/p95 request latency",
      "peak RAM/VRAM",
      "review minutes",
      "recovery time"
    ],
    "caution": "Passing synthetic cases establishes only the tested behavior, not production or customer acceptance."
  },
  "operations": {
    "pin": [
      "package lockfiles",
      "OCR engine/language files",
      "embedding revision/dimension",
      "LLM digest/quantization",
      "prompt",
      "chunking policy",
      "schema/migrations"
    ],
    "bind": "127.0.0.1 during local experiment; remote access needs separate authenticated deployment design",
    "offline": "Preload and hash dependencies/models/fonts; disable cloud features and telemetry; enforce network egress policy for the entire stack.",
    "limits": "Configure and test page count, upload bytes, parser CPU/memory/timeouts, model context, concurrency and bounded retries.",
    "backup": "Encrypted, access-controlled backups cover originals, DB, extraction revisions, reviews and version manifest; test restore and permission revocation.",
    "owner": "Assign an operator and review cadence before a real pilot."
  }
}
