lancedb/lancedb · error · ValueError
weight must be between 0 and 1.
Error message
weight must be between 0 and 1.
What it means
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.
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.
Example fix
// before reranker = LinearCombinationReranker(weight=1.5) // after reranker = LinearCombinationReranker(weight=min(max(weight, 0.0), 1.0))
Defensive patterns
Strategy: validation
Validate before calling
if not (0.0 <= weight <= 1.0):
raise ValueError(f'weight must be in [0,1], got {weight}') Try / catch
try:
reranker = LinearCombinationReranker(weight=w)
except ValueError as e:
reranker = LinearCombinationReranker(weight=min(max(w, 0.0), 1.0)) Prevention
- 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
When it happens
Trigger: LinearCombinationReranker(weight=-0.1), LinearCombinationReranker(weight=1.5), or computing weight dynamically (e.g. weight=score_sum/count) that overflows the range.
Common situations: 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).
Related errors
- weight_fts must be between 0.0 and 1.0
- weight_vector must be between 0.0 and 1.0
- weight_vector + weight_fts must equal 1.0
- All elements in vector_results should be of the same type
- All elements in vector_results should be of the same type
AI-assisted analysis of lancedb/lancedb@c7b051aff7 (2026-09-08).
Data as JSON: /api/errors/1e6c83d89429e011.
Report an issue: GitHub.
Appendix: source
Thrown at python/python/lancedb/rerankers/linear_combination.py:36
weight : float, default 0.7
The weight to give to the vector score. Must be between 0 and 1.
fill : float, default 1.0
The score to give to results that are only in one of the two result sets.
This is treated as penalty, so a higher value means a lower score.
TODO: We should just hardcode this--
its pretty confusing as we invert scores to calculate final score
return_score : str, default "relevance"
opntions are "relevance" or "all"
The type of score to return. If "relevance", will return only the relevance
score. If "all", will return all scores from the vector and FTS search along
with the relevance score.
"""
def __init__(
self, weight: float = 0.7, fill: float = 1.0, return_score="relevance"
):
if weight < 0 or weight > 1:
raise ValueError("weight must be between 0 and 1.")
super().__init__(return_score)
self.weight = weight
self.fill = fill
def __str__(self):
return f"LinearCombinationReranker(weight={self.weight}, fill={self.fill})"
def rerank_hybrid(
self,
query: str, # noqa: F821
vector_results: pa.Table,
fts_results: pa.Table,
):
combined_results = self.merge_results(vector_results, fts_results, self.fill)
return combined_results
def merge_results(View on GitHub (pinned to c7b051aff7)