Spaces:
Runtime error
Runtime error
feat: implement hybrid similarity ranking engine with adaptive weighting and score normalization
Browse files
src/similarity_model/hybrid_ranker.py
CHANGED
|
@@ -124,6 +124,14 @@ def compute_hybrid_score(
|
|
| 124 |
coverage_w * coverage
|
| 125 |
)
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
return round(clamp(score), 4)
|
| 128 |
|
| 129 |
|
|
|
|
| 124 |
coverage_w * coverage
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# ==========================================
|
| 128 |
+
# Penalty for weak feature overlap
|
| 129 |
+
# (prevents generic keyword matches from scoring too high)
|
| 130 |
+
# ==========================================
|
| 131 |
+
if feature_score < 0.40:
|
| 132 |
+
penalty = 0.50 + (feature_score / 0.40) * 0.50
|
| 133 |
+
score *= penalty
|
| 134 |
+
|
| 135 |
return round(clamp(score), 4)
|
| 136 |
|
| 137 |
|
src/similarity_model/similarity_engine.py
CHANGED
|
@@ -160,9 +160,13 @@ def compare_candidate(
|
|
| 160 |
feature_model
|
| 161 |
) -> Dict[str, Any]:
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
feature_result = compute_feature_similarity(
|
| 164 |
query_project[FEATURE_COL],
|
| 165 |
-
|
| 166 |
model=feature_model
|
| 167 |
)
|
| 168 |
|
|
@@ -235,7 +239,10 @@ def compare_candidate(
|
|
| 235 |
feature_result["unique_a"],
|
| 236 |
|
| 237 |
"unique_candidate_features":
|
| 238 |
-
feature_result["unique_b"]
|
|
|
|
|
|
|
|
|
|
| 239 |
}
|
| 240 |
|
| 241 |
|
|
|
|
| 160 |
feature_model
|
| 161 |
) -> Dict[str, Any]:
|
| 162 |
|
| 163 |
+
candidate_features = safe_feature_list(
|
| 164 |
+
candidate_row[FEATURE_COL]
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
feature_result = compute_feature_similarity(
|
| 168 |
query_project[FEATURE_COL],
|
| 169 |
+
candidate_features,
|
| 170 |
model=feature_model
|
| 171 |
)
|
| 172 |
|
|
|
|
| 239 |
feature_result["unique_a"],
|
| 240 |
|
| 241 |
"unique_candidate_features":
|
| 242 |
+
feature_result["unique_b"],
|
| 243 |
+
|
| 244 |
+
"candidate_features":
|
| 245 |
+
candidate_features
|
| 246 |
}
|
| 247 |
|
| 248 |
|