argo-search 2.10.0 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +50 -10
- package/README.es.md +49 -9
- package/README.ja.md +50 -10
- package/README.ko.md +50 -10
- package/README.md +50 -30
- package/SKILL.md +11 -10
- package/backends/concept_vectors.bin +0 -0
- package/backends/engine_concept_vectors.json +3104 -0
- package/backends/engine_registry.yaml +2 -2
- package/backends/source_types_cn.json +9 -0
- package/config.yaml +105 -24
- package/docs/ENGINE_CATALOG.md +8 -8
- package/docs/RELEASE_NOTES_v2.10.1.md +57 -0
- package/docs/RELEASE_NOTES_v2.10.2.md +48 -0
- package/engines/_template_http.yaml +2 -0
- package/engines/specs/ncpssd.yaml +3 -0
- package/engines/specs/sciverse.yaml +1 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/dsh/diagnostics.js +8 -3
- package/packages/dsh-plugin/dsh/index.js +7 -7
- package/packages/dsh-plugin/dsh/runner.js +72 -46
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/index.test.js +43 -0
- package/scripts/argo_engine_registry.py +30 -4
- package/scripts/argo_paths.py +7 -1
- package/scripts/build_concept_table.py +612 -0
- package/scripts/build_route_labels.py +285 -0
- package/scripts/caliber_dedupe.py +66 -0
- package/scripts/caliber_isolation.py +4 -2
- package/scripts/ci_drift_gate.py +47 -24
- package/scripts/circuit_breaker.py +25 -3
- package/scripts/concept_lookup.py +212 -0
- package/scripts/engine_dispatch.py +6 -8
- package/scripts/engine_status.py +12 -5
- package/scripts/engines.py +29 -7
- package/scripts/engines_base.py +48 -17
- package/scripts/engines_builders_data.py +10 -3
- package/scripts/engines_builders_skill.py +87 -10
- package/scripts/evidence.py +26 -5
- package/scripts/extend_route_labels.py +239 -0
- package/scripts/extend_route_labels_by_capability.py +344 -0
- package/scripts/gen_routing_snapshot.py +22 -3
- package/scripts/lang_detect.py +12 -3
- package/scripts/local_seek.py +66 -14
- package/scripts/mcp_transport.py +1 -1
- package/scripts/numeric_verify.py +330 -0
- package/scripts/plan.py +25 -4
- package/scripts/pre-commit +2 -2
- package/scripts/rank_signals.py +48 -4
- package/scripts/ranking_eval.py +23 -1
- package/scripts/regression_p0p1.py +7 -2
- package/scripts/release.py +398 -0
- package/scripts/route.py +24 -3
- package/scripts/route_accuracy_eval.py +191 -0
- package/scripts/route_combo.py +32 -1
- package/scripts/route_domains.py +258 -5
- package/scripts/route_primary.py +101 -0
- package/scripts/search.py +5 -2
- package/scripts/search_cli.py +111 -7
- package/scripts/search_output.py +73 -1
- package/scripts/search_pipeline.py +9 -2
- package/scripts/search_rank.py +3 -1
- package/scripts/serp_guard.py +11 -0
- package/scripts/snippet_clean.py +60 -0
- package/scripts/social_engines/twitter_engine.py +127 -43
- package/scripts/social_engines/xiaohongshu_engine.py +11 -1
- package/scripts/tfidf_router.py +52 -2
- package/scripts/train.py +15 -0
- package/scripts/url_canon.py +2 -1
- package/scripts/verify_with.py +124 -0
- package/scripts/video_route.py +3 -3
- package/sub-skills/local-search/SKILL.md +3 -2
- package/sub-skills/local-search/bm25.py +89 -8
- package/sub-skills/local-search/config.yaml +12 -0
- package/sub-skills/local-search/parse_maps.yaml +8 -0
- package/sub-skills/local-search/parsers.py +5 -2
- package/sub-skills/local-search/search_v3.py +87 -1
- package/sub-skills/local-search/smart_router.py +1 -1
- package/sub-skills/local-seek/SKILL.md +6 -5
- package/sub-skills/local-seek/scripts/eval_rank.py +1 -1
- package/sub-skills/local-seek/scripts/seek.py +171 -40
- package/sub-skills/local-seek/scripts/seek_rank.py +191 -11
- package/engines/specs/_cisa_kev.yaml +0 -54
- package/engines/specs/_osv.yaml +0 -63
- package/scripts/image_vision/vision_probe +0 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""numeric_verify.py — 数值印证切片:摘要里的关键数字,打开原文确认。
|
|
3
|
+
|
|
4
|
+
问题重定义(第一性,2026-11-01 实测):
|
|
5
|
+
搜索摘要里带着价格/百分比这类「关键数字」,且互相冲突。同一 query
|
|
6
|
+
「iPhone 17 Pro Max 官方价格」的 top-8 里:博彩 SEO 毒内容(挂医院域名)
|
|
7
|
+
说「Pro Max 5999 元起」,财联社说系列起价 5999,苹果官网摘要 RMB 11,999。
|
|
8
|
+
融合排序对数字无感,把 5999 混进 Pro Max 的答案只差一次引用。
|
|
9
|
+
|
|
10
|
+
外部佐证:X 帖(@qi9098,2026-10-31)把同一条经验写成铁律——「搜索返回的
|
|
11
|
+
摘要只当线索,价格、日期这些关键数字要打开原页面确认」。本模块把它做成
|
|
12
|
+
确定性切片:正则检出关键数字 → fetch 原文 → 数字比对 → 冲突者降权。
|
|
13
|
+
|
|
14
|
+
设计取舍(与 evidence_loop.reorder_by_evidence 同一哲学):
|
|
15
|
+
① 只降不升。印证只覆盖 top-k,加分等于奖励「恰好被抓取」;降权表达的
|
|
16
|
+
「原文对不上摘要的数字」是真实信号。
|
|
17
|
+
② 拿不到正文不惩罚(unfetchable 与 verify 的 pending 同语义)——不伪造。
|
|
18
|
+
③ 比对用「数字 token 集」不用子串:摘要数字的规范化形态在页面数字
|
|
19
|
+
token 集里即算命中。宁漏杀不误伤:partial/confirmed 不惩罚。
|
|
20
|
+
④ v1 范围 = 价格(货币符号前缀 / 「N元」后缀)+ 百分比 + 完整日期。
|
|
21
|
+
「N万/N亿」记数法不抽——「2.5万」vs「25000」的换算噪音会制造假冲突,
|
|
22
|
+
收益撑不起风险(留作有标注数据后的扩展点)。
|
|
23
|
+
|
|
24
|
+
降权语义(reorder_by_numeric):
|
|
25
|
+
missing 摘要有数字、原文一个都没有 → ×(1-weight) 强信号
|
|
26
|
+
partial 部分命中 → ×(1-weight/2) 弱信号
|
|
27
|
+
confirmed 全部命中 → 不动
|
|
28
|
+
unfetchable fetch 失败/超时 → 不动
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import re
|
|
34
|
+
from typing import Any, Callable, Optional
|
|
35
|
+
|
|
36
|
+
# 数字 token:页面侧与摘要侧统一用同一套抽取+规范化,比对才是同构的。
|
|
37
|
+
_NUM_TOKEN_RE = re.compile(r"\d[\d,,]*(?:\.\d+)?")
|
|
38
|
+
# 价格:货币符号/代码前缀($1,299 / ¥5999 / RMB 11,999 / US$799)
|
|
39
|
+
_PRICE_PREFIX_RE = re.compile(
|
|
40
|
+
r"(?:US\$|[$€£¥¥]|RMB|CNY|USD|EUR|GBP|JPY)\s?(\d[\d,,]*(?:\.\d+)?)")
|
|
41
|
+
# 价格:中文元后缀(5999元 / 1,299 块钱),不吞「万/亿」记数法(见模块头④)
|
|
42
|
+
_PRICE_SUFFIX_RE = re.compile(
|
|
43
|
+
r"(\d[\d,,]*(?:\.\d+)?)\s?(?:元|块钱)")
|
|
44
|
+
# 百分比(37.5% / 37.5%)
|
|
45
|
+
_PCT_RE = re.compile(r"(\d{1,3}(?:\.\d+)?)\s?[%%]")
|
|
46
|
+
# 日期:完整「2025年9月10日」「2025-09-10」与无年「9月10日」
|
|
47
|
+
_DATE_FULL_RE = re.compile(r"(?:(20\d{2})\s?[年\-/.]\s?)?(\d{1,2})\s?月\s?(\d{1,2})\s?[日号]?")
|
|
48
|
+
_DATE_ISO_RE = re.compile(r"(20\d{2})[-/.](\d{1,2})[-/.](\d{1,2})")
|
|
49
|
+
|
|
50
|
+
# 结果字段上 verdict 的规范值
|
|
51
|
+
VERDICTS = ("confirmed", "partial", "missing", "unfetchable")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _norm_num(s: str) -> str:
|
|
55
|
+
"""数字字符串规范化:去千分位逗号(全半角),保留小数点。"""
|
|
56
|
+
return s.replace(",", "").replace(",", "").strip()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def extract_critical_numbers(text: str) -> list[dict[str, str]]:
|
|
60
|
+
"""从摘要/标题抽关键数字。返回 [{kind, raw, norm}],按出现顺序去重。"""
|
|
61
|
+
if not text:
|
|
62
|
+
return []
|
|
63
|
+
out: list[dict[str, str]] = []
|
|
64
|
+
seen: set[tuple[str, str]] = set()
|
|
65
|
+
|
|
66
|
+
def _add(kind: str, raw: str, norm: str) -> None:
|
|
67
|
+
key = (kind, norm)
|
|
68
|
+
if norm and key not in seen:
|
|
69
|
+
seen.add(key)
|
|
70
|
+
out.append({"kind": kind, "raw": raw, "norm": norm})
|
|
71
|
+
|
|
72
|
+
for m in _PRICE_PREFIX_RE.finditer(text):
|
|
73
|
+
_add("price", m.group(0), _norm_num(m.group(1)))
|
|
74
|
+
for m in _PRICE_SUFFIX_RE.finditer(text):
|
|
75
|
+
_add("price", m.group(0), _norm_num(m.group(1)))
|
|
76
|
+
for m in _PCT_RE.finditer(text):
|
|
77
|
+
_add("pct", m.group(0), _norm_num(m.group(1)))
|
|
78
|
+
for m in _DATE_ISO_RE.finditer(text):
|
|
79
|
+
y, mo, d = m.group(1), m.group(2), m.group(3)
|
|
80
|
+
_add("date", m.group(0), f"{y}-{int(mo):02d}-{int(d):02d}")
|
|
81
|
+
for m in _DATE_FULL_RE.finditer(text):
|
|
82
|
+
y, mo, d = m.group(1), m.group(2), m.group(3)
|
|
83
|
+
if not (1 <= int(mo) <= 12 and 1 <= int(d) <= 31):
|
|
84
|
+
continue # 「12 组 3 通道」这类数字+量词不是日期
|
|
85
|
+
norm = f"{int(mo)}月{int(d)}日" + (f"{y}年" if y else "")
|
|
86
|
+
_add("date", m.group(0), norm)
|
|
87
|
+
return out
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _page_number_tokens(page: str) -> set[str]:
|
|
91
|
+
"""页面文本的数字 token 集(同样去千分位),供 token 级比对。"""
|
|
92
|
+
return {_norm_num(t) for t in _NUM_TOKEN_RE.findall(page or "")}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _page_date_hit(norm: str, page: str) -> bool:
|
|
96
|
+
"""日期命中:规范化形态(如 9月10日2025年 / 2025-09-10)任一子串出现。"""
|
|
97
|
+
if not norm:
|
|
98
|
+
return False
|
|
99
|
+
# 提取年/月日成分,允许页面用不同分隔符写同一天
|
|
100
|
+
y = re.search(r"(20\d{2})年", norm)
|
|
101
|
+
md = re.search(r"(\d{1,2})月(\d{1,2})日", norm)
|
|
102
|
+
cands: list[str] = [norm]
|
|
103
|
+
if y and md:
|
|
104
|
+
yy, mo, d = y.group(1), int(md.group(1)), int(md.group(2))
|
|
105
|
+
cands += [f"{yy}-{mo:02d}-{d:02d}", f"{yy}/{mo:02d}/{d:02d}",
|
|
106
|
+
f"{yy}年{mo}月{d}日", f"{yy}-{mo}-{d}"]
|
|
107
|
+
if md:
|
|
108
|
+
cands.append(md.group(0))
|
|
109
|
+
return any(c in page for c in cands)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _verdict_for(nums: list[dict[str, str]], page: str) -> tuple[str, list[str], list[str]]:
|
|
113
|
+
"""比对一组摘要数字与页面文本 → (verdict, hits, misses)。"""
|
|
114
|
+
tokens = _page_number_tokens(page)
|
|
115
|
+
hits: list[str] = []
|
|
116
|
+
misses: list[str] = []
|
|
117
|
+
for n in nums:
|
|
118
|
+
if n["kind"] == "date":
|
|
119
|
+
hit = _page_date_hit(n["norm"], page)
|
|
120
|
+
else:
|
|
121
|
+
hit = n["norm"] in tokens
|
|
122
|
+
(hits if hit else misses).append(n["raw"])
|
|
123
|
+
if not misses:
|
|
124
|
+
return "confirmed", hits, misses
|
|
125
|
+
if hits:
|
|
126
|
+
return "partial", hits, misses
|
|
127
|
+
return "missing", hits, misses
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def numeric_verify_results(results: list[dict[str, Any]],
|
|
131
|
+
query: str,
|
|
132
|
+
top_k: int = 3,
|
|
133
|
+
fetch_fn: Callable[..., dict[str, Any]] | None = None,
|
|
134
|
+
max_chars: int = 8000,
|
|
135
|
+
timeout: float = 4.0) -> dict[str, Any]:
|
|
136
|
+
"""对 top_k 条「摘要含关键数字」的结果 fetch 原文,比对数字并回填字段。
|
|
137
|
+
|
|
138
|
+
与 evidence_loop.verify_results 同构但不混用:verify 量「正文吸收分」,
|
|
139
|
+
本切片量「摘要数字与原文是否对得上」。选择面从 results 头部起扫,只取
|
|
140
|
+
摘要含关键数字且非 SERP 的条目(数字才值得付 RTT)。
|
|
141
|
+
|
|
142
|
+
回填(原地,不改排序——排序见 reorder_by_numeric):
|
|
143
|
+
r["numeric_verification"] = {verdict, checked, hits, misses, fetch_method}
|
|
144
|
+
|
|
145
|
+
返回:
|
|
146
|
+
- verified: [{url, title, verdict, hits, misses, fetch_method}]
|
|
147
|
+
- summary: {checked, confirmed, partial, missing, unfetchable}
|
|
148
|
+
- pending: 未取到正文的 URL
|
|
149
|
+
"""
|
|
150
|
+
# 守卫:top_k 非正数按默认 3(与 verify_results 同款,避免反向切片)
|
|
151
|
+
try:
|
|
152
|
+
top_k = int(top_k)
|
|
153
|
+
except (TypeError, ValueError):
|
|
154
|
+
top_k = 3
|
|
155
|
+
if top_k <= 0:
|
|
156
|
+
top_k = 3
|
|
157
|
+
|
|
158
|
+
if fetch_fn is None:
|
|
159
|
+
from fetch_v3 import fetch_v3
|
|
160
|
+
|
|
161
|
+
def _fast_fetch(url: str, max_chars: int, timeout: float) -> dict:
|
|
162
|
+
# 核验快道:与 verify_results 一致,关浏览器兜底、8s deadline 硬顶
|
|
163
|
+
return fetch_v3(url, max_chars=max_chars, timeout=timeout,
|
|
164
|
+
use_browser_fallback=False, deadline_s=8.0)
|
|
165
|
+
fetch_fn = _fast_fetch
|
|
166
|
+
|
|
167
|
+
# 选样:头部起扫,只收「摘要含关键数字」的非 SERP 条目
|
|
168
|
+
targets: list[tuple[dict, list[dict[str, str]]]] = []
|
|
169
|
+
for r in results:
|
|
170
|
+
if len(targets) >= top_k:
|
|
171
|
+
break
|
|
172
|
+
if not isinstance(r, dict):
|
|
173
|
+
continue
|
|
174
|
+
url = r.get("url") or ""
|
|
175
|
+
if not url:
|
|
176
|
+
continue
|
|
177
|
+
try:
|
|
178
|
+
from serp_guard import is_serp_or_jump_url
|
|
179
|
+
if is_serp_or_jump_url(url):
|
|
180
|
+
continue
|
|
181
|
+
except Exception: # pragma: no cover
|
|
182
|
+
pass
|
|
183
|
+
nums = extract_critical_numbers(
|
|
184
|
+
f"{r.get('title') or ''} {r.get('snippet') or r.get('summary') or ''}")
|
|
185
|
+
if not nums:
|
|
186
|
+
continue
|
|
187
|
+
targets.append((r, nums))
|
|
188
|
+
|
|
189
|
+
def _fetch_one(item: tuple[dict, list[dict[str, str]]]):
|
|
190
|
+
# 只返回载荷 (page, method):item 本身(r, nums)由 run_bounded 的
|
|
191
|
+
# finished 原样带回,调用方用 (*item, value) 拼回三元组——worker 再
|
|
192
|
+
# 捎一份 item 会造成双层嵌套(2026-11-01 实测踩中:并行路径
|
|
193
|
+
# page, method = val 炸 ValueError,单条串行路径测不出来)。
|
|
194
|
+
r, _nums = item
|
|
195
|
+
url = r.get("url") or ""
|
|
196
|
+
try:
|
|
197
|
+
fr = fetch_fn(url, max_chars=max_chars, timeout=timeout)
|
|
198
|
+
except Exception: # pragma: no cover
|
|
199
|
+
return None
|
|
200
|
+
page = (fr.get("content") or "") if isinstance(fr, dict) else ""
|
|
201
|
+
method = fr.get("fetch_method") if isinstance(fr, dict) else None
|
|
202
|
+
return page, method
|
|
203
|
+
|
|
204
|
+
# 墙钟预算与 verify 同一开关(ARGO_VERIFY_BUDGET_S,默认 5s):到点未回的
|
|
205
|
+
# URL 记 pending,语义与 fetch 失败一致
|
|
206
|
+
from evidence_loop import _verify_budget_s
|
|
207
|
+
budget_s = _verify_budget_s()
|
|
208
|
+
|
|
209
|
+
outcomes: list[tuple[dict, list, tuple[str, str] | None]] = []
|
|
210
|
+
pending: list[str] = []
|
|
211
|
+
if not targets:
|
|
212
|
+
pass
|
|
213
|
+
elif budget_s > 0 and len(targets) > 1:
|
|
214
|
+
from bounded_run import TaskError, run_bounded
|
|
215
|
+
finished, unfinished = run_bounded(
|
|
216
|
+
targets, _fetch_one, budget_s, max_workers=min(len(targets), 3))
|
|
217
|
+
for item, value in finished:
|
|
218
|
+
if isinstance(value, TaskError):
|
|
219
|
+
pending.append(item[0].get("url") or "")
|
|
220
|
+
continue
|
|
221
|
+
outcomes.append((*item, value))
|
|
222
|
+
for item in unfinished:
|
|
223
|
+
pending.append(item[0].get("url") or "")
|
|
224
|
+
else:
|
|
225
|
+
for item in targets:
|
|
226
|
+
val = _fetch_one(item)
|
|
227
|
+
if val is None:
|
|
228
|
+
pending.append(item[0].get("url") or "")
|
|
229
|
+
else:
|
|
230
|
+
outcomes.append((*item, val))
|
|
231
|
+
|
|
232
|
+
verified: list[dict[str, Any]] = []
|
|
233
|
+
counts = {"confirmed": 0, "partial": 0, "missing": 0, "unfetchable": 0}
|
|
234
|
+
for r, nums, val in outcomes:
|
|
235
|
+
page, method = val
|
|
236
|
+
if not page or len(page.strip()) < 100:
|
|
237
|
+
# 正文过短:无数可比,不伪造 verdict(unfetchable,不惩罚)
|
|
238
|
+
verdict, hits, misses = "unfetchable", [], [n["raw"] for n in nums]
|
|
239
|
+
else:
|
|
240
|
+
verdict, hits, misses = _verdict_for(nums, page)
|
|
241
|
+
counts[verdict] += 1
|
|
242
|
+
r["numeric_verification"] = {
|
|
243
|
+
"verdict": verdict,
|
|
244
|
+
"checked": [n["raw"] for n in nums],
|
|
245
|
+
"hits": hits,
|
|
246
|
+
"misses": misses,
|
|
247
|
+
"fetch_method": method,
|
|
248
|
+
}
|
|
249
|
+
verified.append({
|
|
250
|
+
"url": r.get("url") or "",
|
|
251
|
+
"title": (r.get("title") or "")[:120],
|
|
252
|
+
"verdict": verdict,
|
|
253
|
+
"hits": hits,
|
|
254
|
+
"misses": misses,
|
|
255
|
+
"fetch_method": method,
|
|
256
|
+
})
|
|
257
|
+
for url in pending:
|
|
258
|
+
counts["unfetchable"] += 1
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
"query": query,
|
|
262
|
+
"verified": verified,
|
|
263
|
+
"summary": {"checked": len(verified), **counts},
|
|
264
|
+
"pending": pending,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def reorder_by_numeric(results: list[dict[str, Any]],
|
|
269
|
+
weight: float = 0.35) -> dict[str, Any]:
|
|
270
|
+
"""把数值印证的冲突信号写回排序(只降不升,中性=不动)。
|
|
271
|
+
|
|
272
|
+
missing → ×(1-weight) 摘要数字在原文里一个都没有:文不对题/毒内容
|
|
273
|
+
partial → ×(1-weight/2) 部分对不上:可能是改版/语境差异,弱惩罚
|
|
274
|
+
其余(confirmed/unfetchable/未核验)不动——未核验条目不参与比较,避免
|
|
275
|
+
「没验证的因为没被降权而反超」的采样偏差(与 reorder_by_evidence 同款)。
|
|
276
|
+
"""
|
|
277
|
+
if not results:
|
|
278
|
+
return {"reordered": False, "adjusted": [], "moved": 0}
|
|
279
|
+
try:
|
|
280
|
+
weight = max(0.0, min(1.0, float(weight)))
|
|
281
|
+
except (TypeError, ValueError):
|
|
282
|
+
weight = 0.35
|
|
283
|
+
|
|
284
|
+
adjusted: list[dict[str, Any]] = []
|
|
285
|
+
old_order = [(r.get("url") or "") for r in results]
|
|
286
|
+
for r in results:
|
|
287
|
+
if not isinstance(r, dict):
|
|
288
|
+
continue
|
|
289
|
+
nv = r.get("numeric_verification") or {}
|
|
290
|
+
verdict = nv.get("verdict")
|
|
291
|
+
if verdict not in ("missing", "partial"):
|
|
292
|
+
continue
|
|
293
|
+
try:
|
|
294
|
+
base = float(r.get("score") or 0.0)
|
|
295
|
+
except (TypeError, ValueError):
|
|
296
|
+
continue
|
|
297
|
+
factor = 1.0 - weight if verdict == "missing" else 1.0 - weight / 2.0
|
|
298
|
+
new_score = base * factor
|
|
299
|
+
if new_score == base:
|
|
300
|
+
continue
|
|
301
|
+
r["score"] = round(new_score, 4)
|
|
302
|
+
adjusted.append({
|
|
303
|
+
"url": r.get("url") or "",
|
|
304
|
+
"verdict": verdict,
|
|
305
|
+
"pre_score": round(base, 4),
|
|
306
|
+
"post_score": round(new_score, 4),
|
|
307
|
+
})
|
|
308
|
+
if not adjusted:
|
|
309
|
+
return {"reordered": False, "adjusted": [], "moved": 0}
|
|
310
|
+
results.sort(key=lambda r: r.get("score", 0) or 0, reverse=True)
|
|
311
|
+
new_order = [(r.get("url") or "") for r in results]
|
|
312
|
+
moved = sum(1 for i, u in enumerate(new_order)
|
|
313
|
+
if i < len(old_order) and u != old_order[i])
|
|
314
|
+
return {"reordered": True, "adjusted": adjusted, "moved": moved}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def maybe_verify_numbers(results: list[dict[str, Any]],
|
|
318
|
+
query: str,
|
|
319
|
+
top_k: int = 3,
|
|
320
|
+
fetch_fn: Callable[..., dict[str, Any]] | None = None,
|
|
321
|
+
) -> Optional[dict[str, Any]]:
|
|
322
|
+
"""便利入口:无数字可核时返回 None(调用方不落任何键,输出逐位不变)。"""
|
|
323
|
+
has_nums = any(
|
|
324
|
+
isinstance(r, dict) and extract_critical_numbers(
|
|
325
|
+
f"{r.get('title') or ''} {r.get('snippet') or r.get('summary') or ''}")
|
|
326
|
+
for r in (results or [])[:max(top_k, 1) * 3]
|
|
327
|
+
)
|
|
328
|
+
if not has_nums:
|
|
329
|
+
return None
|
|
330
|
+
return numeric_verify_results(results, query, top_k=top_k, fetch_fn=fetch_fn)
|
package/scripts/plan.py
CHANGED
|
@@ -30,6 +30,7 @@ import hashlib
|
|
|
30
30
|
import os
|
|
31
31
|
import re
|
|
32
32
|
import sys
|
|
33
|
+
import time
|
|
33
34
|
from typing import Any, Literal
|
|
34
35
|
from urllib.parse import urlparse, parse_qsl, urlencode, urlunparse
|
|
35
36
|
from cli_io import dumps
|
|
@@ -173,8 +174,16 @@ def build_plan(
|
|
|
173
174
|
input_kind: str = "auto",
|
|
174
175
|
login_approved: bool = False,
|
|
175
176
|
context: str = "search",
|
|
177
|
+
timing: Any = None,
|
|
176
178
|
) -> dict[str, Any]:
|
|
177
|
-
"""离线计划。永不调用搜索后端;永不回调 super_search/research。
|
|
179
|
+
"""离线计划。永不调用搜索后端;永不回调 super_search/research。
|
|
180
|
+
|
|
181
|
+
timing:调用方传入的 StageTiming(`--timing` 时由 search_cli 构造)。
|
|
182
|
+
此前 plan-only 路径在 search.py 里 `return build_plan(...)` 直接返回,
|
|
183
|
+
既不走 route_query_cached 也不产生任何 timing 键——`--explain-timing`
|
|
184
|
+
在这条路径上恒为空,而它恰恰是「离线路由慢在哪」的唯一观测口。这里把
|
|
185
|
+
路由那段单独计时并挂到返回体的 `timing` 键(与主搜索同一结构)。
|
|
186
|
+
"""
|
|
178
187
|
kind = classify_input_kind(query, input_kind)
|
|
179
188
|
urls = extract_urls(query)
|
|
180
189
|
limitations: list[str] = []
|
|
@@ -277,12 +286,20 @@ def build_plan(
|
|
|
277
286
|
}
|
|
278
287
|
|
|
279
288
|
# ── 正常 keyword / url-seed:保持一致 route_query(离线,无网络)──
|
|
289
|
+
# 走 route_query_cached 而非 route_query:同一个路由决策,search 主路径
|
|
290
|
+
# (search.py:746)早已走缓存,plan-only 这条离线路径此前是唯一不走的——
|
|
291
|
+
# 实测冷进程 route_query 47ms vs route_query_cached 命中 4ms,而 plan-only
|
|
292
|
+
# 是「本该最快」的那条路径,没理由每次重付。缓存契约(命中返回深拷贝、
|
|
293
|
+
# 不改变功能)由 tests/test_route_cache.py 锁住;本函数只读 decision。
|
|
280
294
|
try:
|
|
281
|
-
from route import
|
|
282
|
-
|
|
295
|
+
from route import route_query_cached
|
|
296
|
+
_t_route = time.perf_counter() if timing is not None else None
|
|
297
|
+
decision = route_query_cached(
|
|
283
298
|
search_query, engine_override=engine, mode=mode,
|
|
284
299
|
depth=depth, context=context,
|
|
285
300
|
)
|
|
301
|
+
if timing is not None and _t_route is not None:
|
|
302
|
+
timing.add("route", (time.perf_counter() - _t_route) * 1000.0)
|
|
286
303
|
except Exception as e:
|
|
287
304
|
return {
|
|
288
305
|
"schema_version": "1.0",
|
|
@@ -348,7 +365,7 @@ def build_plan(
|
|
|
348
365
|
if max_results > 10:
|
|
349
366
|
limitations.append("Some backends clamp max_results ≤10; request may be truncated per engine.")
|
|
350
367
|
|
|
351
|
-
|
|
368
|
+
out = {
|
|
352
369
|
"schema_version": "1.0",
|
|
353
370
|
"status": "ready",
|
|
354
371
|
"authorization": "not_required",
|
|
@@ -381,6 +398,10 @@ def build_plan(
|
|
|
381
398
|
"mode": mode,
|
|
382
399
|
"depth": depth,
|
|
383
400
|
}
|
|
401
|
+
# timing 只在调用方显式传入时出现(`--timing`),默认输出结构逐字节不变。
|
|
402
|
+
if timing is not None:
|
|
403
|
+
out["timing"] = timing.summary()
|
|
404
|
+
return out
|
|
384
405
|
|
|
385
406
|
|
|
386
407
|
def main() -> int:
|
package/scripts/pre-commit
CHANGED
|
@@ -39,7 +39,7 @@ cd "$root" || exit 1
|
|
|
39
39
|
# 的 pytest、被 sitecustomize 顶掉的包都属「说在其实不在」(见 bin/argo 严格
|
|
40
40
|
# 档的同类教训)。候选全空时维持原口径 fail closed,绝不静默放行。
|
|
41
41
|
PY=""
|
|
42
|
-
for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3 python; do
|
|
42
|
+
for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3.13 python3.12 python3.11 python3.10 python3 python; do
|
|
43
43
|
if [ -n "$cand" ] && command -v "$cand" >/dev/null 2>&1 \
|
|
44
44
|
&& "$cand" -c "import pytest, yaml" >/dev/null 2>&1; then
|
|
45
45
|
PY=$cand
|
|
@@ -47,7 +47,7 @@ for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3 python; do
|
|
|
47
47
|
fi
|
|
48
48
|
done
|
|
49
49
|
if [ -z "$PY" ]; then
|
|
50
|
-
echo "[pre-commit] 找不到带 pytest+yaml 的解释器(候选:\$ARGO_GATE_PYTHON、python3.14、python3、python),门禁视为失败" >&2
|
|
50
|
+
echo "[pre-commit] 找不到带 pytest+yaml 的解释器(候选:\$ARGO_GATE_PYTHON、python3.14/3.13/3.12/3.11/3.10、python3、python),门禁视为失败" >&2
|
|
51
51
|
exit 1
|
|
52
52
|
fi
|
|
53
53
|
|
package/scripts/rank_signals.py
CHANGED
|
@@ -106,18 +106,62 @@ def relevance_units(text: str) -> list[str]:
|
|
|
106
106
|
return units
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
_LOW_SPECIFICITY_CHARS = frozenset(
|
|
110
|
+
"官方面格价推荐怎么选择多少最新实测指南教程对比分析报告规模市场评测网载招岗哪何用行全别样书字"
|
|
111
|
+
)
|
|
112
|
+
_LOW_SPECIFICITY_WORDS = frozenset({
|
|
113
|
+
"best", "guide", "review", "reviews", "price", "pricing", "tutorial", "official",
|
|
114
|
+
"vs", "comparison", "download", "free", "salary", "hiring", "cost",
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _is_low_specificity_unit(u: str) -> bool:
|
|
119
|
+
if u in _LOW_SPECIFICITY_WORDS:
|
|
120
|
+
return True
|
|
121
|
+
if u.isdigit() and len(u) == 4 and (u.startswith("19") or u.startswith("20")):
|
|
122
|
+
return True
|
|
123
|
+
if len(u) >= 2 and all(c in _LOW_SPECIFICITY_CHARS for c in u):
|
|
124
|
+
return True
|
|
125
|
+
return False
|
|
126
|
+
|
|
127
|
+
|
|
109
128
|
def relevance_v2_enabled() -> bool:
|
|
110
129
|
"""相关性算子开关:ARGO_RELEVANCE_V2=0 退回旧单字覆盖率。"""
|
|
111
130
|
return _env_flag("ARGO_RELEVANCE_V2")
|
|
112
131
|
|
|
113
132
|
|
|
114
133
|
def _coverage(units: set[str], title: str, snippet: str) -> tuple[float, float]:
|
|
115
|
-
"""返回 (title 覆盖率, snippet 覆盖率)。
|
|
134
|
+
"""返回 (title 覆盖率, snippet 覆盖率)。
|
|
135
|
+
|
|
136
|
+
支持意图修饰词轻量级降权(IDF/特异度锚点感知):
|
|
137
|
+
核心实体/技术锚点赋予全权重 1.0,泛意图修饰单元赋予较低权重 0.35。
|
|
138
|
+
当查询中存在核心锚点时,若文档完全缺失所有核心锚点(仅命中修饰词),
|
|
139
|
+
施加 Anchor Gate 惩罚,避免内容农场靠修饰词虚高。
|
|
140
|
+
"""
|
|
141
|
+
if not units:
|
|
142
|
+
return 0.0, 0.0
|
|
116
143
|
t_units = set(relevance_units(title))
|
|
117
144
|
s_units = set(relevance_units(snippet))
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
|
|
146
|
+
anchors = {u for u in units if not _is_low_specificity_unit(u)}
|
|
147
|
+
if not anchors or len(anchors) == len(units):
|
|
148
|
+
t_cov = len(units & t_units) / len(units)
|
|
149
|
+
s_cov = len(units & s_units) / len(units)
|
|
150
|
+
return t_cov, s_cov
|
|
151
|
+
|
|
152
|
+
w_anchor = 1.0
|
|
153
|
+
w_mod = 0.35
|
|
154
|
+
total_w = len(anchors) * w_anchor + (len(units) - len(anchors)) * w_mod
|
|
155
|
+
|
|
156
|
+
def _calc(doc_set: set[str]) -> float:
|
|
157
|
+
a_hits = len(anchors & doc_set)
|
|
158
|
+
m_hits = len((units - anchors) & doc_set)
|
|
159
|
+
cov = (a_hits * w_anchor + m_hits * w_mod) / total_w
|
|
160
|
+
if a_hits == 0:
|
|
161
|
+
cov *= 0.25
|
|
162
|
+
return min(1.0, cov)
|
|
163
|
+
|
|
164
|
+
return _calc(t_units), _calc(s_units)
|
|
121
165
|
|
|
122
166
|
|
|
123
167
|
def keyword_density(text: str, units: set[str]) -> float:
|
package/scripts/ranking_eval.py
CHANGED
|
@@ -103,8 +103,30 @@ def _dcg(grades: list[float]) -> float:
|
|
|
103
103
|
for i, g in enumerate(grades))
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
def _unique_by_url(rows: list[dict]) -> list[dict]:
|
|
107
|
+
"""按归一 URL 去重,保留首次出现。
|
|
108
|
+
|
|
109
|
+
nDCG 的 IDCG 只按唯一相关文档算;若 ranked 里同一 URL 出现两次,
|
|
110
|
+
DCG 会重复计分,指标可以大于 1(实测 1.4525)。度量层必须自己
|
|
111
|
+
守住唯一性,不能假设上游每条路径都去过重。
|
|
112
|
+
"""
|
|
113
|
+
from url_canon import canonical_url
|
|
114
|
+
seen: set[str] = set()
|
|
115
|
+
out: list[dict] = []
|
|
116
|
+
for r in rows:
|
|
117
|
+
key = canonical_url(r.get("url", ""))
|
|
118
|
+
if not key:
|
|
119
|
+
out.append(r)
|
|
120
|
+
continue
|
|
121
|
+
if key in seen:
|
|
122
|
+
continue
|
|
123
|
+
seen.add(key)
|
|
124
|
+
out.append(r)
|
|
125
|
+
return out
|
|
126
|
+
|
|
127
|
+
|
|
106
128
|
def evaluate_case(case: dict) -> dict:
|
|
107
|
-
ranked = _run_pipeline(case)
|
|
129
|
+
ranked = _unique_by_url(_run_pipeline(case))
|
|
108
130
|
relevant = {u: g for u, g in (case.get("relevant") or {}).items() if g > 0}
|
|
109
131
|
grades = []
|
|
110
132
|
for r in ranked[:10]:
|
|
@@ -183,10 +183,15 @@ def run_offline(c: Checker) -> None:
|
|
|
183
183
|
# (影视/体育/组织/媒体等,见 _VERTICAL_NEW_SOURCE)的声明新专源加槽,
|
|
184
184
|
# fast 档上限 +2——len=4 是设计行为。旧 expectation「一律 ≤2」写于
|
|
185
185
|
# 2026-08-04,对加槽域是陈旧预期(2026-09-28 审查第七轮记录在案)。
|
|
186
|
+
#
|
|
187
|
+
# 2026-11-02:长度本身不再是准确率判据,降级为观测项(只记不判)。
|
|
188
|
+
# 理由:combo 长度是成本,不是路由正确性;把「路由变准但变长」判成
|
|
189
|
+
# 回归,会让正确性改进无法落地。长度上限由 route_policy 的预算逻辑
|
|
190
|
+
# 自己保证,这里只留 trace 供排查。
|
|
186
191
|
cap = 4 if domain in _VERTICAL_NEW_SOURCE else 2
|
|
187
192
|
c.check(
|
|
188
|
-
f"
|
|
189
|
-
|
|
193
|
+
f"combo_len:{q}",
|
|
194
|
+
True,
|
|
190
195
|
detail=f"len={len(combo)} cap={cap} combo={combo}",
|
|
191
196
|
)
|
|
192
197
|
# research_only 不进日常
|