{"record":{"id":"6c8ea2f70e2e05e7","repo":"deepset-ai/haystack","slug":"parameter-weight-must-be-in-range-0-1-but-is-c","errorCode":null,"errorMessage":"Parameter <weight> must be in range [0,1] but is currently set to '{weight}'.\n'0' disables sorting by a meta field, '0.5' assigns equal weight to the previous relevance scores and the meta field, and '1' ranks by the meta field only.\nChange the <weight> parameter to a value in range 0 to 1 when initializing the MetaFieldRanker.","messagePattern":"Parameter <weight> must be in range \\[0,1\\] but is currently set to '(.+?)'\\.\n'0' disables sorting by a meta field, '0\\.5' assigns equal weight to the previous relevance scores and the meta field, and '1' ranks by the meta field only\\.\nChange the <weight> parameter to a value in range 0 to 1 when initializing the MetaFieldRanker\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/rankers/meta_field.py","lineNumber":124,"sourceCode":"            meta_value_type=meta_value_type,\n        )\n        self.meta_value_type = meta_value_type\n\n    def _validate_params(\n        self,\n        *,\n        weight: float,\n        top_k: int | None,\n        ranking_mode: Literal[\"reciprocal_rank_fusion\", \"linear_score\"],\n        sort_order: Literal[\"ascending\", \"descending\"],\n        missing_meta: Literal[\"drop\", \"top\", \"bottom\"],\n        meta_value_type: Literal[\"float\", \"int\", \"date\"] | None,\n    ) -> None:\n        if top_k is not None and top_k <= 0:\n            raise ValueError(f\"top_k must be > 0, but got {top_k}\")\n\n        if weight < 0 or weight > 1:\n            raise ValueError(\n                f\"Parameter <weight> must be in range [0,1] but is currently set to '{weight}'.\\n'0' disables sorting \"\n                \"by a meta field, '0.5' assigns equal weight to the previous relevance scores and the meta field, and \"\n                \"'1' ranks by the meta field only.\\nChange the <weight> parameter to a value in range 0 to 1 when \"\n                \"initializing the MetaFieldRanker.\"\n            )\n\n        if ranking_mode not in [\"reciprocal_rank_fusion\", \"linear_score\"]:\n            raise ValueError(\n                \"The value of parameter <ranking_mode> must be 'reciprocal_rank_fusion' or 'linear_score', but is \"\n                f\"currently set to '{ranking_mode}'.\\nChange the <ranking_mode> value to 'reciprocal_rank_fusion' or \"\n                \"'linear_score' when initializing the MetaFieldRanker.\"\n            )\n\n        if sort_order not in [\"ascending\", \"descending\"]:\n            raise ValueError(\n                \"The value of parameter <sort_order> must be 'ascending' or 'descending', \"\n                f\"but is currently set to '{sort_order}'.\\n\"\n                \"Change the <sort_order> value to 'ascending' or 'descending' when initializing the \"","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/rankers/meta_field.py#L106-L142","documentation":"MetaFieldRanker._validate_params rejects a weight outside [0, 1]. Weight blends relevance scores with the meta-field sort: 0 ignores the meta field, 0.5 mixes equally, 1 ranks purely by the meta field. Values outside this range are semantically invalid and raise ValueError.","triggerScenarios":"MetaFieldRanker(weight=1.5), weight=-0.1, or a run() override with an out-of-range value; validation runs in both __init__ and run.","commonSituations":"Confusing weight with a percentage and passing 100 or 50 instead of 1.0/0.5; multiplying weights across components and drifting above 1; parsing config strings into floats without range checks.","solutions":["Set weight to a float in [0,1], e.g. MetaFieldRanker(weight=0.5).","Normalize/clip the value before construction: weight = min(1.0, max(0.0, weight)).","If the intent was a percentage, divide by 100 first."],"exampleFix":"// before\nranker = MetaFieldRanker(weight=100)  # meant 100%\n// after\nranker = MetaFieldRanker(weight=1.0)","handlingStrategy":"validation","validationCode":"if not (0 <= weight <= 1):\n    raise ValueError(f\"weight must be in [0,1], got {weight}\")","typeGuard":"def is_valid_weight(v) -> bool:\n    return isinstance(v, (int, float)) and 0 <= v <= 1","tryCatchPattern":"try:\n    ranker = MetaFieldRanker(weight=w)\nexcept ValueError:\n    ranker = MetaFieldRanker(weight=min(1.0, max(0.0, w)))","preventionTips":["Clip weights with min/max before construction.","Convert percentages to fractions (x/100) when ingesting config values.","Beware float drift when combining weights across components; re-clamp after arithmetic."],"tags":["python","validation","ranker","meta-field"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}