Spaces:
Sleeping
Sleeping
ktsn-ud commited on
Commit ·
0ca34ce
1
Parent(s): d7c1fde
デバッグ表示の内容を追加
Browse files- app/search/engine.py +18 -11
app/search/engine.py
CHANGED
|
@@ -532,6 +532,7 @@ class SearchEngine:
|
|
| 532 |
# Organization/reading auto-boost based on raw query substring match
|
| 533 |
qn = normalize_text_for_org(query)
|
| 534 |
boost_enabled = len(qn) >= int(self.cfg.org_boost_min_len)
|
|
|
|
| 535 |
if boost_enabled:
|
| 536 |
exact = np.zeros((len(self.projects),), dtype=bool)
|
| 537 |
prefix = np.zeros_like(exact)
|
|
@@ -552,7 +553,6 @@ class SearchEngine:
|
|
| 552 |
+ prefix.astype(np.float32) * float(self.cfg.org_boost_prefix)
|
| 553 |
+ substr.astype(np.float32) * float(self.cfg.org_boost_substring)
|
| 554 |
)
|
| 555 |
-
pass
|
| 556 |
|
| 557 |
# collect results
|
| 558 |
ids = [d.get("projectId") for d in self.projects]
|
|
@@ -628,21 +628,28 @@ class SearchEngine:
|
|
| 628 |
pairs.sort(key=lambda x: (-x[1], x[0]))
|
| 629 |
if not debug:
|
| 630 |
return pairs
|
| 631 |
-
# build debug details for
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
details = []
|
| 633 |
-
for
|
|
|
|
| 634 |
details.append(
|
| 635 |
{
|
| 636 |
-
"projectId": ids[
|
| 637 |
-
"
|
| 638 |
-
"
|
| 639 |
-
"
|
|
|
|
|
|
|
| 640 |
if ws_rerank is not None
|
| 641 |
else None,
|
| 642 |
-
"org_boost": float(boost[
|
| 643 |
-
"matched_substring": bool(substring_mask[
|
| 644 |
-
"fused_filter": float(fused_filter[
|
| 645 |
-
"fused_final": float(final_scores[
|
| 646 |
}
|
| 647 |
)
|
| 648 |
return pairs, {"details": details}
|
|
|
|
| 532 |
# Organization/reading auto-boost based on raw query substring match
|
| 533 |
qn = normalize_text_for_org(query)
|
| 534 |
boost_enabled = len(qn) >= int(self.cfg.org_boost_min_len)
|
| 535 |
+
boost = np.zeros((len(self.projects),), dtype=np.float32)
|
| 536 |
if boost_enabled:
|
| 537 |
exact = np.zeros((len(self.projects),), dtype=bool)
|
| 538 |
prefix = np.zeros_like(exact)
|
|
|
|
| 553 |
+ prefix.astype(np.float32) * float(self.cfg.org_boost_prefix)
|
| 554 |
+ substr.astype(np.float32) * float(self.cfg.org_boost_substring)
|
| 555 |
)
|
|
|
|
| 556 |
|
| 557 |
# collect results
|
| 558 |
ids = [d.get("projectId") for d in self.projects]
|
|
|
|
| 628 |
pairs.sort(key=lambda x: (-x[1], x[0]))
|
| 629 |
if not debug:
|
| 630 |
return pairs
|
| 631 |
+
# build debug details for all docs sorted by score
|
| 632 |
+
ranked_indices = sorted(
|
| 633 |
+
range(len(self.projects)),
|
| 634 |
+
key=lambda idx: (-float(final_scores[idx]), ids[idx]),
|
| 635 |
+
)
|
| 636 |
details = []
|
| 637 |
+
for idx in ranked_indices:
|
| 638 |
+
project = self.projects[idx]
|
| 639 |
details.append(
|
| 640 |
{
|
| 641 |
+
"projectId": ids[idx],
|
| 642 |
+
"organization": project.get("organization"),
|
| 643 |
+
"title": project.get("title"),
|
| 644 |
+
"bm25": float(bm25[idx]),
|
| 645 |
+
"ws_filter_topk": float(ws_filter[idx]),
|
| 646 |
+
"ws_rerank_pairavg": float(ws_rerank[idx])
|
| 647 |
if ws_rerank is not None
|
| 648 |
else None,
|
| 649 |
+
"org_boost": float(boost[idx]) if boost_enabled else None,
|
| 650 |
+
"matched_substring": bool(substring_mask[idx]),
|
| 651 |
+
"fused_filter": float(fused_filter[idx]),
|
| 652 |
+
"fused_final": float(final_scores[idx]),
|
| 653 |
}
|
| 654 |
)
|
| 655 |
return pairs, {"details": details}
|