{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anguskit.com/schema/anguscopilot-knowledge/1.0.0-alpha/knowledge.json",
  "title": "AngusCopilot Knowledge Base Specification",
  "description": "AngusCopilot 知识库顶层 Spec（specification: anguscopilot-knowledge/1.0.0-alpha）。与 §14.4 对齐。",
  "type": "object",
  "required": ["specification", "info", "spec"],
  "properties": {
    "specification": {
      "$ref": "https://www.anguskit.com/schema/anguscopilot/1.0.0/common.json#/$defs/SpecificationField",
      "pattern": "^anguscopilot-knowledge\\/(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-(?:alpha|beta|rc)(?:\\.(?:0|[1-9]\\d*))?)?$"
    },
    "info": {
      "$ref": "https://www.anguskit.com/schema/anguscopilot/1.0.0/info.json"
    },
    "spec": {
      "type": "object",
      "required": ["sources", "chunking", "embedding", "index"],
      "properties": {
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "source.json" },
          "uniqueItems": true
        },
        "chunking": { "$ref": "chunking.json" },
        "embedding": {
          "type": "object",
          "required": ["provider", "model"],
          "properties": {
            "provider": { "type": "string" },
            "model": { "type": "string" },
            "dimensions": { "type": "integer", "minimum": 1 },
            "credentialRef": {
              "$ref": "https://www.anguskit.com/schema/anguscopilot/1.0.0/common.json#/$defs/SecretRef"
            },
            "multiVector": {
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "representations": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": ["content", "summary", "hypothetical-questions"]
                  },
                  "uniqueItems": true
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "F6 约束：enabled=true 时 representations 非空。",
              "if": {
                "properties": { "enabled": { "const": true } },
                "required": ["enabled"]
              },
              "then": {
                "required": ["representations"],
                "properties": {
                  "representations": { "minItems": 1 }
                }
              },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },
        "index": { "$ref": "index.json" },
        "retrieval": {
          "type": "object",
          "properties": {
            "queryRewrite": {
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "maxRewrites": { "type": "integer", "minimum": 1, "maximum": 10, "default": 3 }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "hyde": {
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "modelRef": { "type": "string", "minLength": 1 }
              },
              "patternProperties": { "^x-": true },
              "if": {
                "properties": { "enabled": { "const": true } },
                "required": ["enabled"]
              },
              "then": {
                "required": ["modelRef"]
              },
              "unevaluatedProperties": false
            },
            "rerank": {
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "modelRef": { "type": "string", "minLength": 1 },
                "topK": { "type": "integer", "minimum": 1, "default": 30 },
                "finalTopK": { "type": "integer", "minimum": 1, "default": 8 }
              },
              "patternProperties": { "^x-": true },
              "if": {
                "properties": { "enabled": { "const": true } },
                "required": ["enabled"]
              },
              "then": {
                "required": ["modelRef"]
              },
              "unevaluatedProperties": false
            },
            "expand": {
              "type": "object",
              "properties": {
                "sentenceWindow": {
                  "type": "object",
                  "properties": {
                    "enabled": { "type": "boolean", "default": false },
                    "beforeSentences": { "type": "integer", "minimum": 0, "default": 2 },
                    "afterSentences": { "type": "integer", "minimum": 0, "default": 2 }
                  },
                  "patternProperties": { "^x-": true },
                  "unevaluatedProperties": false
                },
                "autoMerging": {
                  "type": "object",
                  "properties": {
                    "enabled": { "type": "boolean", "default": false },
                    "threshold": { "type": "number", "minimum": 0, "maximum": 1, "default": 0.6 }
                  },
                  "patternProperties": { "^x-": true },
                  "unevaluatedProperties": false
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },
        "accessControl": { "$ref": "access-control.json" },
        "compliance": {
          "type": "object",
          "properties": {
            "sensitivityField": { "type": "string", "default": "sensitivity" },
            "redactionPolicy": {
              "type": "string",
              "enum": ["off", "pii-redact", "ner-redact"],
              "default": "pii-redact"
            },
            "retentionDays": {
              "type": "integer",
              "minimum": 1,
              "maximum": 3650,
              "default": 365
            },
            "forgetSubject": {
              "type": "string",
              "enum": ["disabled", "enabled"],
              "default": "disabled"
            }
          },
          "patternProperties": { "^x-": true },
          "$comment": "F9: retentionDays minimum=1（已由 minimum 保证），redactionPolicy ∈ enum。",
          "unevaluatedProperties": false
        }
      },
      "patternProperties": { "^x-": true },
      "unevaluatedProperties": false
    }
  },
  "patternProperties": { "^x-": true },
  "unevaluatedProperties": false
}
