{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mnemoverse-com/json-schema/mnemoverse-com-query-request-schema-schema.json",
  "title": "QueryRequestSchema",
  "description": "Advanced query with multi-domain and metadata filtering.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mnemoverse-com-memory-v1-api-openapi.yml#/components/schemas/QueryRequestSchema",
  "properties": {
    "query": {
      "type": "string",
      "maxLength": 5000,
      "minLength": 1,
      "title": "Query",
      "description": "Natural language query."
    },
    "domains": {
      "anyOf": [
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Domains",
      "description": "Filter by multiple domains (null = all)."
    },
    "metadata_filter": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/MetadataFilterSchema"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Metadata Filter",
      "description": "JSONB metadata filter conditions."
    },
    "top_k": {
      "type": "integer",
      "maximum": 500.0,
      "minimum": 1.0,
      "title": "Top K",
      "description": "Max items to return. Cap aligned with ReadRequestSchema (500).",
      "default": 10
    },
    "min_relevance": {
      "type": "number",
      "maximum": 1.0,
      "minimum": 0.0,
      "title": "Min Relevance",
      "description": "Min relevance threshold.",
      "default": 0.3
    },
    "include_associations": {
      "type": "boolean",
      "title": "Include Associations",
      "description": "Expand via concept associations.",
      "default": true
    },
    "concepts": {
      "items": {
        "type": "string"
      },
      "type": "array",
      "title": "Concepts",
      "description": "Concept hints."
    },
    "include_history": {
      "type": "boolean",
      "title": "Include History",
      "description": "Return superseded revisions alongside live ones; each carries `superseded_by`, and every item carries `supersedes` when it replaced something. History is returned in the domain where each revision is stored: a read scoped to the successor's domain does not include a cross-domain predecessor — use an unscoped read or `GET /memory/atoms/{id}`. History items compete under normal ranking, `min_relevance` and `top_k`/`limit` — `include_history` grants eligibility, not chain completeness; for the chain itself use `GET /memory/atoms/{id}/chain`, which spends a 64-LOOKUP budget per call (resolved revisions AND dangling-pointer misses both count) and sets `truncated` when the budget ran out — so `truncated` means the walk stopped early, not that the chain necessarily holds more than 64 revisions. One exception to the domain rule above: when a fingerprint matches a revision that has been replaced, the live tip is returned alongside it even if that tip lives in another domain — the episodic index is domain-blind, and this makes it two atoms rather than one. No effect until the read-side supersession filter is enabled (nothing is hidden before then, so nothing needs unhiding), and inert for `xroom:<room_id>` domains, whose atoms cannot be superseded at all.",
      "default": false
    },
    "diversity": {
      "type": "number",
      "maximum": 1.0,
      "minimum": 0.0,
      "title": "Diversity",
      "description": "0 (default) leaves the ranking as it is: the ranked candidates are cut to `top_k`. A value above 0 turns the cut into a maximal marginal relevance selection: items are picked one at a time, each the one that best trades its relevance against its cosine similarity to the items already picked (weight `diversity` on the similarity, `1 - diversity` on relevance), so a near-copy of something already in the answer loses its slot to the next distinct item. 1 means similarity alone decides after the first pick. Applied after outcome feedback and recency have re-ranked, on the ranked pool of up to 200 candidates that cleared `min_relevance`, and only when `top_k` is below 200 (at 200 or more the plain cut applies); pinned fingerprint revisions and the association-reserved slots are unchanged. It changes which items are returned, not their scores.",
      "default": 0.0
    }
  },
  "type": "object",
  "required": [
    "query"
  ],
  "$defs": {
    "MetadataFilterSchema": {
      "properties": {
        "key": {
          "type": "string",
          "maxLength": 64,
          "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
          "title": "Key",
          "description": "Metadata key to filter on."
        },
        "op": {
          "type": "string",
          "pattern": "^(eq|contains|in)$",
          "title": "Op",
          "description": "Operator: eq, contains, in.",
          "default": "eq"
        },
        "value": {
          "title": "Value",
          "description": "Value to compare against."
        }
      },
      "type": "object",
      "required": [
        "key",
        "value"
      ],
      "title": "MetadataFilterSchema",
      "description": "Single metadata filter condition."
    }
  }
}