Spaces:
Sleeping
Sleeping
ktsn-ud commited on
Commit ·
01356b8
1
Parent(s): 09c8b6b
クエリが1文字以内の場合にUnboundLocalErrorが出てしまう不具合を解消
Browse files- api/search/engine.py +12 -3
api/search/engine.py
CHANGED
|
@@ -431,7 +431,8 @@ class SearchEngine:
|
|
| 431 |
|
| 432 |
# Organization/reading auto-boost based on raw query substring match
|
| 433 |
qn = normalize_text_for_org(query)
|
| 434 |
-
|
|
|
|
| 435 |
exact = np.zeros((len(self.projects),), dtype=bool)
|
| 436 |
prefix = np.zeros_like(exact)
|
| 437 |
substr = np.zeros_like(exact)
|
|
@@ -455,9 +456,14 @@ class SearchEngine:
|
|
| 455 |
|
| 456 |
# collect results
|
| 457 |
ids = [d.get("projectId") for d in self.projects]
|
|
|
|
| 458 |
# Filtering to reduce false positives while keeping recall
|
| 459 |
# Relative threshold anchored to the top fused score
|
| 460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
top = float(np.max(score_with_boost)) if score_with_boost.size > 0 else 0.0
|
| 462 |
rel_cut = (
|
| 463 |
top * float(self.cfg.fused_rel_top_ratio) if top > 0 else self.cfg.fused_min
|
|
@@ -494,7 +500,10 @@ class SearchEngine:
|
|
| 494 |
if ws_rerank is None:
|
| 495 |
ws_rerank = ws_filter
|
| 496 |
fused_rerank = a * bm25 + (1.0 - a) * ws_rerank
|
| 497 |
-
|
|
|
|
|
|
|
|
|
|
| 498 |
pairs = [(ids[i], float(final_scores[i])) for i in selected_idx]
|
| 499 |
|
| 500 |
# sort
|
|
|
|
| 431 |
|
| 432 |
# Organization/reading auto-boost based on raw query substring match
|
| 433 |
qn = normalize_text_for_org(query)
|
| 434 |
+
boost_enabled = len(qn) >= int(self.cfg.org_boost_min_len)
|
| 435 |
+
if boost_enabled:
|
| 436 |
exact = np.zeros((len(self.projects),), dtype=bool)
|
| 437 |
prefix = np.zeros_like(exact)
|
| 438 |
substr = np.zeros_like(exact)
|
|
|
|
| 456 |
|
| 457 |
# collect results
|
| 458 |
ids = [d.get("projectId") for d in self.projects]
|
| 459 |
+
|
| 460 |
# Filtering to reduce false positives while keeping recall
|
| 461 |
# Relative threshold anchored to the top fused score
|
| 462 |
+
if boost_enabled:
|
| 463 |
+
score_with_boost = fused_filter + boost
|
| 464 |
+
else:
|
| 465 |
+
score_with_boost = fused_filter
|
| 466 |
+
|
| 467 |
top = float(np.max(score_with_boost)) if score_with_boost.size > 0 else 0.0
|
| 468 |
rel_cut = (
|
| 469 |
top * float(self.cfg.fused_rel_top_ratio) if top > 0 else self.cfg.fused_min
|
|
|
|
| 500 |
if ws_rerank is None:
|
| 501 |
ws_rerank = ws_filter
|
| 502 |
fused_rerank = a * bm25 + (1.0 - a) * ws_rerank
|
| 503 |
+
if boost_enabled:
|
| 504 |
+
final_scores = fused_rerank + boost
|
| 505 |
+
else:
|
| 506 |
+
final_scores = fused_rerank
|
| 507 |
pairs = [(ids[i], float(final_scores[i])) for i in selected_idx]
|
| 508 |
|
| 509 |
# sort
|