{"record":{"id":"1e6c83d89429e011","repo":"lancedb/lancedb","slug":"weight-must-be-between-0-and-1","errorCode":null,"errorMessage":"weight must be between 0 and 1.","messagePattern":"weight must be between 0 and 1\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/python/lancedb/rerankers/linear_combination.py","lineNumber":36,"sourceCode":"    weight : float, default 0.7\n        The weight to give to the vector score. Must be between 0 and 1.\n    fill : float, default 1.0\n        The score to give to results that are only in one of the two result sets.\n        This is treated as penalty, so a higher value means a lower score.\n        TODO: We should just hardcode this--\n        its pretty confusing as we invert scores to calculate final score\n    return_score : str, default \"relevance\"\n        opntions are \"relevance\" or \"all\"\n        The type of score to return. If \"relevance\", will return only the relevance\n        score. If \"all\", will return all scores from the vector and FTS search along\n        with the relevance score.\n    \"\"\"\n\n    def __init__(\n        self, weight: float = 0.7, fill: float = 1.0, return_score=\"relevance\"\n    ):\n        if weight < 0 or weight > 1:\n            raise ValueError(\"weight must be between 0 and 1.\")\n        super().__init__(return_score)\n        self.weight = weight\n        self.fill = fill\n\n    def __str__(self):\n        return f\"LinearCombinationReranker(weight={self.weight}, fill={self.fill})\"\n\n    def rerank_hybrid(\n        self,\n        query: str,  # noqa: F821\n        vector_results: pa.Table,\n        fts_results: pa.Table,\n    ):\n        combined_results = self.merge_results(vector_results, fts_results, self.fill)\n\n        return combined_results\n\n    def merge_results(","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/python/python/lancedb/rerankers/linear_combination.py#L18-L54","documentation":"LinearCombinationReranker.__init__ validates that the hybrid weighting factor `weight` lies in [0, 1]. Weight controls the mix between vector and full-text scores; values outside the range are rejected with this ValueError.","triggerScenarios":"LinearCombinationReranker(weight=-0.1), LinearCombinationReranker(weight=1.5), or computing weight dynamically (e.g. weight=score_sum/count) that overflows the range.","commonSituations":"Confusing this weight with an unbounded 'boost' factor from other search systems, or a normalization bug producing weights slightly above 1.0 (e.g. 1.0000001).","solutions":["Clamp the weight: weight = max(0.0, min(1.0, weight)).","Pass a literal in [0, 1], e.g. LinearCombinationReranker(weight=0.7).","Normalize the computed value: weight = raw / max_value before construction."],"exampleFix":"// before\nreranker = LinearCombinationReranker(weight=1.5)\n// after\nreranker = LinearCombinationReranker(weight=min(max(weight, 0.0), 1.0))","handlingStrategy":"validation","validationCode":"if not (0.0 <= weight <= 1.0):\n    raise ValueError(f'weight must be in [0,1], got {weight}')","typeGuard":null,"tryCatchPattern":"try:\n    reranker = LinearCombinationReranker(weight=w)\nexcept ValueError as e:\n    reranker = LinearCombinationReranker(weight=min(max(w, 0.0), 1.0))","preventionTips":["Clamp config-driven weights at load time","Remember this weight is a fraction, not a boost multiplier","Unit-test reranker construction with edge values 0.0 and 1.0"],"tags":["python","reranker","argument-validation","out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}