{"record":{"id":"8c8331527b91128e","repo":"agentscope-ai/agentscope","slug":"dimensionpolicy-kind-any-requires-dimension-none","errorCode":null,"errorMessage":"DimensionPolicy: kind=ANY requires dimension=None, got dimension={self.dimension!r}.","messagePattern":"DimensionPolicy: kind=ANY requires dimension=None, got dimension=(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/app/rag/knowledge_base_manager/_dimension_policy.py","lineNumber":85,"sourceCode":"        description=(\n            \"The required dimension when ``kind`` is ``FIXED`` or \"\n            \"``LOCKED_BY_EXISTING``.  Always ``None`` for ``ANY``.\"\n        ),\n    )\n    \"\"\"The required dimension, or ``None`` when any dimension is fine.\"\"\"\n\n    @model_validator(mode=\"after\")\n    def _enforce_kind_dimension_invariant(self) -> \"DimensionPolicy\":\n        \"\"\"Reject states like ``ANY + dimension=768`` or ``FIXED + None``.\n\n        Without this guard, downstream code silently produces wrong\n        results (``ANY`` ignores a stray dimension) or crashes\n        (``FIXED`` with ``None`` makes ``filter_card`` raise\n        ``TypeError`` on ``target not in card.supported_dimensions``).\n        \"\"\"\n        if self.kind is DimensionPolicyKind.ANY:\n            if self.dimension is not None:\n                raise ValueError(\n                    \"DimensionPolicy: kind=ANY requires dimension=None, \"\n                    f\"got dimension={self.dimension!r}.\",\n                )\n        else:\n            if self.dimension is None or self.dimension <= 0:\n                raise ValueError(\n                    f\"DimensionPolicy: kind={self.kind.value} requires a \"\n                    f\"positive dimension, got dimension={self.dimension!r}.\",\n                )\n        return self\n\n    def accepts(self, dimensions: int) -> bool:\n        \"\"\"Check whether a candidate dimension satisfies this policy.\n\n        Args:\n            dimensions (`int`):\n                The candidate output dimension.\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/rag/knowledge_base_manager/_dimension_policy.py#L67-L103","documentation":"DimensionPolicy enforces an invariant in _enforce_kind_dimension_invariant: when kind is ANY (accept any embedding dimension), the policy must not carry a dimension — a stray value would be silently ignored otherwise, masking a config mistake. ANY + dimension set raises this ValueError. (Duplicate of error 158: the message spans two adjacent string literals; both trace the same raise.)","triggerScenarios":"Constructing DimensionPolicy(kind=DimensionPolicyKind.ANY, dimension=1536) or deserializing a policy dict where kind='any' but a leftover dimension field survives (e.g. config flipped from FIXED to ANY without clearing dimension).","commonSituations":"Editing policy config from a fixed-dimension setup to 'any' without deleting the dimension key; JSON/YAML defaults injecting dimension; form UIs that always submit the dimension field; LLM-generated config files keeping both fields.","solutions":["Set dimension=None (or omit the field) when kind is ANY","When flipping kind to ANY in stored config, strip/null the dimension key in the same change","Validate policy config at load time: if kind=='any', pop the dimension before constructing","If you actually need to pin a dimension, use FIXED/RANGE kinds, which require it"],"exampleFix":"# before\npolicy = DimensionPolicy(kind=DimensionPolicyKind.ANY, dimension=1536)  # ValueError\n\n# after\npolicy = DimensionPolicy(kind=DimensionPolicyKind.ANY, dimension=None)","handlingStrategy":"validation","validationCode":"cfg = {'kind': 'any', 'dimension': 1536}\nif cfg.get('kind') == 'any':\n    cfg['dimension'] = None\npolicy = DimensionPolicy(**cfg)","typeGuard":"def policy_config_is_consistent(cfg: dict) -> bool:\n    kind = str(cfg.get('kind', '')).lower()\n    dim = cfg.get('dimension')\n    return (kind == 'any' and dim is None) or (kind != 'any' and isinstance(dim, int) and dim > 0)","tryCatchPattern":"try:\n    policy = DimensionPolicy(**cfg)\nexcept ValueError:\n    if cfg['kind'] == 'any':\n        cfg['dimension'] = None\n        policy = DimensionPolicy(**cfg)\n    else:\n        raise","preventionTips":["When switching policy kind to ANY, null the dimension in the same commit","Validate policy dicts with a helper before construction/deserialization","Use kind=FIXED if you actually intend to pin a dimension"],"tags":["rag","validation","embedding-dimension","config"],"backgroundTag":"config-validation-failed","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}