@@ -14,7 +14,7 @@ def greedy_select(
1414 * ,
1515 metric : Metric ,
1616 normalize : bool ,
17- lambda_param : float ,
17+ diversity : float = 0.5 ,
1818) -> DiversificationResult :
1919 """
2020 Greedy selection for MMR/MSD strategies.
@@ -30,22 +30,25 @@ def greedy_select(
3030 :param k: Number of items to select.
3131 :param metric: Similarity metric to use. Default is Metric.COSINE.
3232 :param normalize: Whether to normalize embeddings before computing similarity.
33- :param lambda_param : Trade-off parameter in [0, 1].
34- 1.0 = pure relevance , 0.0 = pure diversity .
33+ :param diversity : Trade-off parameter in [0, 1].
34+ 1.0 = pure diversity , 0.0 = pure relevance .
3535 :return: A DiversificationResult containing the selected item indices,
3636 their marginal gains, the strategy used, and the parameters.
37- :raises ValueError: If lambda_param is not in [0, 1].
37+ :raises ValueError: If diversity is not in [0, 1].
3838 :raises ValueError: If input shapes are inconsistent.
3939 """
4040 # Validate parameters
41- if not (0.0 <= float (lambda_param ) <= 1.0 ):
42- raise ValueError ("lambda_param must be in [0, 1]" )
41+ if not (0.0 <= float (diversity ) <= 1.0 ):
42+ raise ValueError ("diversity must be in [0, 1]" )
4343
4444 params = {
45- "lambda_param" : lambda_param ,
4645 "metric" : metric ,
4746 }
4847
48+ # Lambda parameter for trade-off between relevance and diversity
49+ # This is 1 - diversity to align with common notation
50+ lambda_param = 1.0 - diversity
51+
4952 # Prepare inputs
5053 feature_matrix , relevance_scores , top_k , early_exit = prepare_inputs (embeddings , scores , k )
5154 if early_exit :
@@ -54,6 +57,7 @@ def greedy_select(
5457 indices = np .empty (0 , np .int32 ),
5558 marginal_gains = np .empty (0 , np .float32 ),
5659 strategy = Strategy .MMR if strategy == "mmr" else Strategy .MSD ,
60+ diversity = diversity ,
5761 parameters = params ,
5862 )
5963
@@ -108,5 +112,6 @@ def greedy_select(
108112 indices = selected_indices ,
109113 marginal_gains = marginal_gains ,
110114 strategy = Strategy .MMR if strategy == "mmr" else Strategy .MSD ,
115+ diversity = diversity ,
111116 parameters = params ,
112117 )
0 commit comments