{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chris-page-gov.github.io/okf-explorer/profiles/context-assembly/v1/corpus-v3.schema.json",
  "type": "object",
  "properties": {
    "schema": {
      "const": "okf-context-corpus.v3"
    },
    "bundle": {
      "$ref": "common.schema.json#/$defs/bundle"
    },
    "scope": {
      "type": "string"
    },
    "limitations": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "semantic_source_snapshot": {
      "type": "string"
    },
    "base_index": {
      "type": "object",
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240,
          "pattern": "^[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)*$"
        },
        "bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8388608
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "encoding": {
          "const": "gzip"
        },
        "decoded_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8388608
        },
        "decoded_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "path",
        "bytes",
        "sha256"
      ],
      "additionalProperties": false,
      "dependentRequired": {
        "encoding": [
          "decoded_bytes",
          "decoded_sha256"
        ]
      }
    },
    "counts": {
      "type": "object",
      "properties": {
        "documents": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "pages": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "nonempty_pages": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "empty_pages": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "tokenless_pages": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        }
      },
      "required": [
        "documents",
        "pages",
        "nonempty_pages",
        "empty_pages",
        "tokenless_pages"
      ],
      "additionalProperties": false
    },
    "records": {
      "type": "object",
      "properties": {
        "count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "shards": {
          "type": "array",
          "maxItems": 16000,
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1,
                "maxLength": 240,
                "pattern": "^[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)*$"
              },
              "bytes": {
                "type": "integer",
                "minimum": 1,
                "maximum": 4194304
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "encoding": {
                "const": "gzip"
              },
              "decoded_bytes": {
                "type": "integer",
                "minimum": 1,
                "maximum": 4194304
              },
              "decoded_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "first_ordinal": {
                "type": "integer",
                "minimum": 0,
                "maximum": 1000000
              },
              "count": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10000
              },
              "first_id": {
                "type": "string",
                "maxLength": 2000,
                "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
              },
              "last_id": {
                "type": "string",
                "maxLength": 2000,
                "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
              }
            },
            "required": [
              "path",
              "bytes",
              "sha256",
              "first_ordinal",
              "count",
              "first_id",
              "last_id"
            ],
            "additionalProperties": false,
            "dependentRequired": {
              "encoding": [
                "decoded_bytes",
                "decoded_sha256"
              ]
            }
          }
        }
      },
      "required": [
        "count",
        "shards"
      ],
      "additionalProperties": false
    },
    "search": {
      "type": "object",
      "properties": {
        "tokenisation": {
          "const": "nfkd-lowercase-ascii-alphanumeric-min2-v1"
        },
        "bucket_algorithm": {
          "const": "fnv1a32-high-byte-hex-v1"
        },
        "shards": {
          "type": "object",
          "minProperties": 256,
          "maxProperties": 256,
          "patternProperties": {
            "^[a-f0-9]{2}$": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 240,
                  "pattern": "^[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)*$"
                },
                "bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4194304
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "encoding": {
                  "const": "gzip"
                },
                "decoded_bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4194304
                },
                "decoded_sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "required": [
                "path",
                "bytes",
                "sha256"
              ],
              "additionalProperties": false,
              "dependentRequired": {
                "encoding": [
                  "decoded_bytes",
                  "decoded_sha256"
                ]
              }
            }
          },
          "additionalProperties": false
        },
        "ranking": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "schema": { "const": "okf-bm25.v1" },
                "k1": { "const": 1.2 },
                "b": { "const": 0.75 },
                "score_scale": { "const": 1000000 },
                "fields": { "const": ["source", "discovery"] }
              },
              "required": ["schema", "k1", "b", "score_scale", "fields"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "schema": { "const": "okf-bm25-weighted.v2" },
                "k1": { "const": 1.2 },
                "b": { "const": 0.75 },
                "score_scale": { "const": 1000000 },
                "fields": { "const": ["source", "discovery"] },
                "weights": {
                  "type": "object",
                  "properties": { "source": { "const": 1 }, "discovery": { "const": 2 } },
                  "required": ["source", "discovery"],
                  "additionalProperties": false
                }
              },
              "required": ["schema", "k1", "b", "score_scale", "fields", "weights"],
              "additionalProperties": false
            }
          ]
        },
        "alias_routes": {
          "type": "array",
          "maxItems": 2000,
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "ordinal": { "type": "integer", "minimum": 0 },
                  "phrase": { "type": "string", "minLength": 1, "maxLength": 500 }
                },
                "required": ["ordinal", "phrase"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "ordinal": { "type": "integer", "minimum": 0 },
                  "pattern": { "$ref": "discovery-card.schema.json#/$defs/route_pattern" }
                },
                "required": ["ordinal", "pattern"],
                "additionalProperties": false
              }
            ]
          }
        },
        "total_tokens": {
          "type": "object",
          "properties": {
            "source": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000000000
            },
            "discovery": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000000000
            }
          },
          "required": [
            "source",
            "discovery"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "tokenisation",
        "bucket_algorithm",
        "shards",
        "ranking",
        "total_tokens"
      ],
      "if": { "required": ["alias_routes"] },
      "then": {
        "properties": {
          "ranking": { "properties": { "schema": { "const": "okf-bm25-weighted.v2" } } }
        }
      },
      "additionalProperties": false
    },
    "discovery": {
      "type": "object",
      "properties": {
        "count": {
          "type": "integer",
          "minimum": 0
        },
        "shards": {
          "type": "array",
          "maxItems": 16000,
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1,
                "maxLength": 240,
                "pattern": "^[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)*$"
              },
              "bytes": {
                "type": "integer",
                "minimum": 1,
                "maximum": 4194304
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "encoding": {
                "const": "gzip"
              },
              "decoded_bytes": {
                "type": "integer",
                "minimum": 1,
                "maximum": 4194304
              },
              "decoded_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "first_ordinal": {
                "type": "integer",
                "minimum": 0
              },
              "count": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10000
              }
            },
            "required": [
              "path",
              "bytes",
              "sha256",
              "first_ordinal",
              "count"
            ],
            "additionalProperties": false,
            "dependentRequired": {
              "encoding": [
                "decoded_bytes",
                "decoded_sha256"
              ]
            }
          }
        }
      },
      "required": [
        "count",
        "shards"
      ],
      "additionalProperties": false
    },
    "relationships": {
      "type": "object",
      "properties": {
        "schema": {
          "const": "okf-context-adjacency.v1"
        },
        "bucket_algorithm": {
          "const": "fnv1a32-high-byte-hex-v1"
        },
        "shards": {
          "type": "object",
          "minProperties": 256,
          "maxProperties": 256,
          "patternProperties": {
            "^[a-f0-9]{2}$": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 240,
                  "pattern": "^[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)*$"
                },
                "bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4194304
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "encoding": {
                  "const": "gzip"
                },
                "decoded_bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4194304
                },
                "decoded_sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "required": [
                "path",
                "bytes",
                "sha256"
              ],
              "additionalProperties": false,
              "dependentRequired": {
                "encoding": [
                  "decoded_bytes",
                  "decoded_sha256"
                ]
              }
            }
          },
          "additionalProperties": false
        }
      },
      "required": [
        "schema",
        "bucket_algorithm",
        "shards"
      ],
      "additionalProperties": false
    },
    "extensions": {
      "type": "object"
    }
  },
  "required": [
    "schema",
    "bundle",
    "scope",
    "limitations",
    "semantic_source_snapshot",
    "base_index",
    "counts",
    "records",
    "search",
    "discovery",
    "relationships"
  ],
  "additionalProperties": false,
  "title": "Source-bound discovery corpus v3",
  "description": "Exact logical evidence, separate discovery cards, fixed two-channel BM25 and committed sharded directed assertions."
}
