argo-search 2.9.8 → 2.10.0
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 +48 -35
- package/README.es.md +48 -35
- package/README.ja.md +47 -34
- package/README.ko.md +47 -34
- package/README.md +50 -35
- package/SKILL.md +5 -5
- package/backends/domain_profiles.json +76 -0
- package/backends/engine_registry.yaml +161 -5
- package/backends/quota_profiles.json +122 -2
- package/bin/argo +26 -1
- package/bin/argo.js +3 -3
- package/config.yaml +180 -26
- package/docs/ARGO_INTRO.md +7 -5
- package/docs/ENGINE_CATALOG.md +64 -44
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
- package/docs/RELEASE_NOTES_v2.9.9.md +78 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
- package/engines/specs/clawhub.yaml +16 -15
- package/engines/specs/deepseek1024.yaml +46 -0
- package/engines/specs/dsh_hub.yaml +44 -0
- package/engines/specs/dshopen.yaml +32 -0
- package/engines/specs/explainx.yaml +32 -0
- package/engines/specs/gbfs_nyc.yaml +6 -1
- package/engines/specs/metaso_doc.yaml +49 -0
- package/engines/specs/metaso_image.yaml +65 -0
- package/engines/specs/metaso_podcast.yaml +60 -0
- package/engines/specs/metaso_scholar.yaml +57 -0
- package/engines/specs/metaso_video.yaml +62 -0
- package/engines/specs/ncpssd.yaml +41 -0
- package/engines/specs/sciverse.yaml +72 -0
- package/engines/specs/skills_sh.yaml +32 -0
- package/engines/specs/skillsmp.yaml +18 -16
- package/package.json +4 -2
- package/packages/dsh-plugin/README.md +4 -2
- package/packages/dsh-plugin/dsh/client.js +98 -32
- package/packages/dsh-plugin/dsh/diagnostics.js +43 -0
- package/packages/dsh-plugin/dsh/index.js +23 -1
- package/packages/dsh-plugin/package.json +2 -2
- package/packages/dsh-plugin/test/client.test.js +2 -1
- package/packages/dsh-plugin/test/size-gate.test.js +113 -0
- package/scripts/adaptive.py +135 -48
- package/scripts/article.py +6 -1
- package/scripts/article_meta.py +151 -2
- package/scripts/bench_general_pool.py +145 -0
- package/scripts/bench_tail_ab.py +281 -0
- package/scripts/bounded_run.py +91 -49
- package/scripts/candidate_envelope.py +45 -4
- package/scripts/charset_decode.py +127 -0
- package/scripts/clock_bridge.py +22 -0
- package/scripts/content_security.py +119 -4
- package/scripts/crawl.py +240 -74
- package/scripts/crawl_frontier.py +217 -0
- package/scripts/crawl_policy.py +174 -0
- package/scripts/dispatch_result.py +9 -2
- package/scripts/engine_add.py +602 -0
- package/scripts/engine_dispatch.py +31 -15
- package/scripts/engine_failure.py +15 -0
- package/scripts/engine_validate.py +8 -0
- package/scripts/engines.py +10 -0
- package/scripts/engines_base.py +12 -0
- package/scripts/engines_builders.py +14 -0
- package/scripts/engines_builders_dsh.py +330 -0
- package/scripts/engines_builders_skill.py +314 -0
- package/scripts/evidence_loop.py +4 -0
- package/scripts/fetch_quality.py +13 -0
- package/scripts/fetch_v3.py +39 -7
- package/scripts/gen_engine_catalog.py +218 -2
- package/scripts/general_pool.py +162 -0
- package/scripts/http_client.py +62 -80
- package/scripts/image_ops.py +4 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.ps1 +47 -19
- package/scripts/install.sh +45 -20
- package/scripts/matrix_search_eval.py +128 -2
- package/scripts/mcp_transport.py +1 -1
- package/scripts/ncpssd_bridge.py +123 -0
- package/scripts/net_proxy.py +27 -0
- package/scripts/paid_policy.py +109 -13
- package/scripts/pre-commit +19 -4
- package/scripts/query_signals.py +156 -3
- package/scripts/recovery.py +7 -3
- package/scripts/redskill/redskill_engine.py +29 -2
- package/scripts/release_check.py +209 -0
- package/scripts/retry_policy.py +22 -1
- package/scripts/robots_guard.py +26 -0
- package/scripts/route.py +11 -8
- package/scripts/route_cache.py +6 -0
- package/scripts/route_combo.py +56 -64
- package/scripts/route_domains.py +142 -13
- package/scripts/route_policy.py +6 -0
- package/scripts/safe_conn.py +52 -0
- package/scripts/search.py +9 -1
- package/scripts/search_cli.py +27 -0
- package/scripts/search_entry.py +10 -0
- package/scripts/search_output.py +29 -0
- package/scripts/search_pipeline.py +59 -3
- package/scripts/search_rank.py +7 -0
- package/scripts/serp_guard.py +23 -0
- package/scripts/social_engines/bilibili_engine.py +163 -26
- package/scripts/social_engines/reddit_engine.py +52 -51
- package/scripts/source_selection.py +302 -0
- package/scripts/tail_completion.py +212 -0
- package/scripts/url_safety.py +126 -3
- package/scripts/usage_log.py +45 -0
- package/scripts/video_fetch.py +303 -0
- package/scripts/video_meta.py +225 -0
- package/scripts/video_route.py +65 -0
- package/scripts/watch.py +123 -0
package/scripts/route_domains.py
CHANGED
|
@@ -70,10 +70,103 @@ _ZH_LANG_GATED_DOMAINS = frozenset({
|
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
# ──
|
|
73
|
+
# ── 域预编译(内容指纹缓存与锚点快筛) ──────────────────────────────────────────
|
|
74
74
|
|
|
75
75
|
_compiled_domains: list[dict[str, Any]] | None = None
|
|
76
76
|
_compiled_domains_id: tuple | None = None # (name, patterns/exclude_if 内容指纹)
|
|
77
|
+
_compiled_domains_ref: int | None = None
|
|
78
|
+
_anchor_matcher: re.Pattern | None = None
|
|
79
|
+
_anchor_to_domains: dict[str, list[int]] = {}
|
|
80
|
+
_unconstrained_domains: set[int] = set()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _extract_anchors(src: Any) -> set[str] | None:
|
|
84
|
+
"""从正则源码中提取一组必须包含其一的字面锚点词集合(全小写)。
|
|
85
|
+
|
|
86
|
+
若无法提取安全锚点(如含有纯通配、字符集类 []、通用转义字符类),返回 None。
|
|
87
|
+
"""
|
|
88
|
+
if not isinstance(src, str) or not src:
|
|
89
|
+
return None
|
|
90
|
+
s = re.sub(r"^\(\?[a-zA-Z]+\)", "", src)
|
|
91
|
+
s = re.sub(r"\\b", "", s)
|
|
92
|
+
if s.startswith("(") and s.endswith(")"):
|
|
93
|
+
s = s[1:-1]
|
|
94
|
+
parts: list[str] = []
|
|
95
|
+
depth = 0
|
|
96
|
+
cur: list[str] = []
|
|
97
|
+
for ch in s:
|
|
98
|
+
if ch in ("(", "["):
|
|
99
|
+
depth += 1
|
|
100
|
+
elif ch in (")", "]"):
|
|
101
|
+
depth -= 1
|
|
102
|
+
if ch == "|" and depth == 0:
|
|
103
|
+
parts.append("".join(cur))
|
|
104
|
+
cur = []
|
|
105
|
+
else:
|
|
106
|
+
cur.append(ch)
|
|
107
|
+
if cur:
|
|
108
|
+
parts.append("".join(cur))
|
|
109
|
+
|
|
110
|
+
anchors: set[str] = set()
|
|
111
|
+
for part in parts:
|
|
112
|
+
# 正则字符类与元字符无法保证字面子串存在
|
|
113
|
+
if re.search(r"\[.*?\]", part) or re.search(r"\\[wWdDsS]", part):
|
|
114
|
+
return None
|
|
115
|
+
runs = re.findall(r"[\u4e00-\u9fff]{1,}|[a-zA-Z0-9_\-\.]{2,}", part)
|
|
116
|
+
if not runs:
|
|
117
|
+
return None
|
|
118
|
+
for r in runs:
|
|
119
|
+
anchors.add(r.lower())
|
|
120
|
+
return anchors if anchors else None
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _init_anchor_index(compiled: list[dict[str, Any]]) -> None:
|
|
124
|
+
"""初始化全局锚点自动机索引(方案一:Aho-Corasick 前置快速分桶)。"""
|
|
125
|
+
global _anchor_matcher, _anchor_to_domains, _unconstrained_domains
|
|
126
|
+
_anchor_to_domains = {}
|
|
127
|
+
_unconstrained_domains = set()
|
|
128
|
+
all_anchors: set[str] = set()
|
|
129
|
+
|
|
130
|
+
for idx, domain in enumerate(compiled):
|
|
131
|
+
entries = _pattern_entries(domain)
|
|
132
|
+
if not entries:
|
|
133
|
+
_unconstrained_domains.add(idx)
|
|
134
|
+
continue
|
|
135
|
+
dom_anchors: set[str] = set()
|
|
136
|
+
unconstrained = False
|
|
137
|
+
for p in entries:
|
|
138
|
+
match_src, _ = _split_pattern_entry(p)
|
|
139
|
+
anc = _extract_anchors(match_src)
|
|
140
|
+
if anc is None:
|
|
141
|
+
unconstrained = True
|
|
142
|
+
break
|
|
143
|
+
dom_anchors.update(anc)
|
|
144
|
+
if unconstrained or not dom_anchors:
|
|
145
|
+
_unconstrained_domains.add(idx)
|
|
146
|
+
else:
|
|
147
|
+
for term in dom_anchors:
|
|
148
|
+
_anchor_to_domains.setdefault(term, []).append(idx)
|
|
149
|
+
all_anchors.add(term)
|
|
150
|
+
|
|
151
|
+
if all_anchors:
|
|
152
|
+
sorted_terms = sorted(all_anchors, key=len, reverse=True)
|
|
153
|
+
escaped = [re.escape(t) for t in sorted_terms]
|
|
154
|
+
_anchor_matcher = re.compile("|".join(escaped), re.IGNORECASE)
|
|
155
|
+
else:
|
|
156
|
+
_anchor_matcher = None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _get_candidate_domain_indices(query: str) -> set[int] | None:
|
|
160
|
+
"""通过锚点词快速扫描返回候选域索引集合;无索引时返回 None。"""
|
|
161
|
+
if _anchor_matcher is None:
|
|
162
|
+
return None
|
|
163
|
+
candidates = set(_unconstrained_domains)
|
|
164
|
+
for m in _anchor_matcher.finditer(query):
|
|
165
|
+
term = m.group(0).lower()
|
|
166
|
+
doms = _anchor_to_domains.get(term)
|
|
167
|
+
if doms:
|
|
168
|
+
candidates.update(doms)
|
|
169
|
+
return candidates
|
|
77
170
|
|
|
78
171
|
|
|
79
172
|
def _ensure_domain_compiled(domain: dict[str, Any]) -> list[tuple[re.Pattern, re.Pattern | None]]:
|
|
@@ -134,18 +227,30 @@ def _split_pattern_entry(entry: Any) -> tuple[Any, Any]:
|
|
|
134
227
|
return entry, None
|
|
135
228
|
|
|
136
229
|
|
|
137
|
-
def
|
|
138
|
-
"""
|
|
230
|
+
def _domain_fires_with_span(domain: dict[str, Any], query: str) -> tuple[bool, int, int]:
|
|
231
|
+
"""一个域是否成立,并返回命中的 (是否成立, match_span_start, match_span_len)。"""
|
|
139
232
|
for match_re, unless_re in _ensure_domain_compiled(domain):
|
|
140
233
|
if unless_re is not None and unless_re.search(query):
|
|
141
234
|
continue
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
235
|
+
m = match_re.search(query)
|
|
236
|
+
if m is not None:
|
|
237
|
+
start, end = m.span()
|
|
238
|
+
return True, start, end - start
|
|
239
|
+
return False, 0, 0
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _domain_fires(domain: dict[str, Any], query: str) -> bool:
|
|
243
|
+
"""一个域是否成立:任一触发词命中,且它自己的否决词没命中。"""
|
|
244
|
+
fires, _, _ = _domain_fires_with_span(domain, query)
|
|
245
|
+
return fires
|
|
145
246
|
|
|
146
247
|
|
|
147
248
|
def _get_compiled_domains(domains: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
148
|
-
global _compiled_domains, _compiled_domains_id
|
|
249
|
+
global _compiled_domains, _compiled_domains_id, _compiled_domains_ref
|
|
250
|
+
# 快速指针比对:当传入同一 domains 引用且已编译时 O(1) 返回,免除 97 域的 SHA1 开销
|
|
251
|
+
dom_ref = id(domains)
|
|
252
|
+
if _compiled_domains is not None and _compiled_domains_ref == dom_ref:
|
|
253
|
+
return _compiled_domains
|
|
149
254
|
# 用内容指纹替代 id(domains),避免 GC 后 id 复用导致缓存失效/错误。
|
|
150
255
|
# 指纹含规则本体(只记长度会漏「改正则不改条数」的编辑),且必须覆盖
|
|
151
256
|
# exclude_if / intent_required——它们和 patterns 一样会改变命中结果。
|
|
@@ -169,6 +274,8 @@ def _get_compiled_domains(domains: list[dict[str, Any]]) -> list[dict[str, Any]]
|
|
|
169
274
|
for idx, domain in enumerate(domains)
|
|
170
275
|
]
|
|
171
276
|
_compiled_domains_id = dom_fp
|
|
277
|
+
_compiled_domains_ref = dom_ref
|
|
278
|
+
_init_anchor_index(_compiled_domains)
|
|
172
279
|
return _compiled_domains
|
|
173
280
|
|
|
174
281
|
|
|
@@ -216,7 +323,10 @@ def _social_domain_first(hits: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
|
216
323
|
idx_first_social = hits.index(social[0])
|
|
217
324
|
# 「热搜/热榜」是比泛 social 更具体的意图:查询里带微博/抖音这类平台名时,
|
|
218
325
|
# social 会被提前,把 hot_trending 顶掉——用户问的是榜单,不是社交帖子。
|
|
219
|
-
|
|
326
|
+
# video 同理:「抖音视频 红烧肉」要的是视频,不是社交帖子;2026-10-27
|
|
327
|
+
# 加 video 域时一并登记,否则 social 提权会把它压回第二位。
|
|
328
|
+
_SPECIFIC_BEFORE_SOCIAL = ("redskill_search", "zhihu_user_data",
|
|
329
|
+
"hot_trending", "video")
|
|
220
330
|
idx_specific = next(
|
|
221
331
|
(i for i, h in enumerate(hits)
|
|
222
332
|
if h.get("name") in _SPECIFIC_BEFORE_SOCIAL), None
|
|
@@ -311,20 +421,39 @@ def match_domains(query: str, domains: list[dict[str, Any]] | None = None,
|
|
|
311
421
|
domains = get_domains()
|
|
312
422
|
compiled = _get_compiled_domains(domains)
|
|
313
423
|
hits: list[dict[str, Any]] = []
|
|
424
|
+
secondary_hits: list[tuple[dict[str, Any], float]] = []
|
|
314
425
|
catch_all: dict[str, Any] | None = None
|
|
315
426
|
non_zh = bool(primary_lang and primary_lang not in ("zh", "mixed", "other"))
|
|
316
|
-
|
|
427
|
+
candidates = _get_candidate_domain_indices(query)
|
|
428
|
+
q_len = max(len(query), 1)
|
|
429
|
+
|
|
430
|
+
for idx, domain in enumerate(compiled):
|
|
317
431
|
if not domain.get("patterns", []):
|
|
318
432
|
catch_all = domain
|
|
319
433
|
continue
|
|
320
434
|
if non_zh and domain.get("name") in _ZH_LANG_GATED_DOMAINS:
|
|
321
435
|
continue
|
|
322
|
-
if
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
436
|
+
if candidates is not None and idx not in candidates:
|
|
437
|
+
continue
|
|
438
|
+
fires, span_start, span_len = _domain_fires_with_span(domain, query)
|
|
439
|
+
if fires:
|
|
440
|
+
if not hits:
|
|
441
|
+
hits.append(domain)
|
|
442
|
+
else:
|
|
443
|
+
pos_ratio = span_start / q_len
|
|
444
|
+
# 方案二:跨度高(特异性强)优先提拔;同跨度下严格保持前序特化域顺位稳定
|
|
445
|
+
score = (span_len * 2.0) - (idx * 0.1) + (pos_ratio * 0.01)
|
|
446
|
+
secondary_hits.append((domain, score))
|
|
447
|
+
if len(hits) + len(secondary_hits) >= max_n:
|
|
448
|
+
break
|
|
449
|
+
|
|
450
|
+
if secondary_hits:
|
|
451
|
+
secondary_hits.sort(key=lambda x: x[1], reverse=True)
|
|
452
|
+
hits.extend(h[0] for h in secondary_hits)
|
|
453
|
+
|
|
326
454
|
hits = _social_domain_first(hits)
|
|
327
455
|
hits = _intent_gate(hits, query)
|
|
456
|
+
hits = hits[:max_n]
|
|
328
457
|
return hits if hits else ([catch_all] if catch_all else [])
|
|
329
458
|
|
|
330
459
|
|
package/scripts/route_policy.py
CHANGED
|
@@ -44,6 +44,12 @@ _VERTICAL_NEW_SOURCE: dict[str, tuple[str, ...]] = {
|
|
|
44
44
|
# cinii 声明 langs=ja,靠 engines_demote_for_lang 的语言专用源降级,
|
|
45
45
|
# 只在日语查询里占位;zbmath 语言中立,数学查询与 deep 档可达。
|
|
46
46
|
"soil_agri": ("openfoodfacts",), # 食品成分库:补 usda(单一国别)之外的多国食品数据
|
|
47
|
+
# 2026-10-26:技能域两个新专源。explainx 给「安装量 + 分类 + 官方标记」,
|
|
48
|
+
# skills.sh 给 Vercel 官方安装遥测——两者都是「这个技能多少人在用」的硬
|
|
49
|
+
# 指标,而此前三个技能源(skillsmp 只有仓库星数、clawhub 只有生态下载量、
|
|
50
|
+
# redskill 只有小红书站内口径)都给不出。声明在既有源之后,由本表加槽,
|
|
51
|
+
# 不挤掉 skillsmp/clawhub/redskill 的位次。
|
|
52
|
+
"skill_search": ("explainx", "skills_sh"),
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""safe_conn.py — 解析即锁定的 HTTP/HTTPS 连接类(DNS rebinding / TOCTOU 防护)
|
|
3
|
+
|
|
4
|
+
独立成模块的理由:``http.client`` 会连带拉起 ``ssl``(实测 ≈14 ms)。
|
|
5
|
+
``url_safety`` 被 ``robots_guard`` 等在**模块级**导入(见 robots_guard 的
|
|
6
|
+
「轻导入」注释),若把 ``http.client`` 放在 ``url_safety`` 里,
|
|
7
|
+
``test_robots_guard.test_module_import_stays_light`` 会红。连接类只在真正
|
|
8
|
+
建连时经 ``net_proxy.open_connection`` 导入,不进轻导入路径。
|
|
9
|
+
|
|
10
|
+
原理:``check_url()`` 在请求前解析一次 DNS,``http.client`` 在 ``connect()``
|
|
11
|
+
时再解析一次——两次之间域名可改指内网(DNS rebinding)。本类在 ``connect()``
|
|
12
|
+
里解析一次、过滤私网、把结果钉给本次 TCP 连接,窗口关闭;SNI/Host 仍用原域名。
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import http.client
|
|
18
|
+
|
|
19
|
+
from url_safety import pin_host
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SafeHTTPConnection(http.client.HTTPConnection):
|
|
23
|
+
"""解析即锁定的 HTTP 连接:TCP 只连校验过的公网 IP,Host 头仍用原域名。"""
|
|
24
|
+
|
|
25
|
+
def connect(self):
|
|
26
|
+
pinned = pin_host(self.host)
|
|
27
|
+
if pinned is None:
|
|
28
|
+
return super().connect()
|
|
29
|
+
host = self.host
|
|
30
|
+
self.host = pinned
|
|
31
|
+
try:
|
|
32
|
+
super().connect()
|
|
33
|
+
finally:
|
|
34
|
+
self.host = host
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SafeHTTPSConnection(http.client.HTTPSConnection):
|
|
38
|
+
"""解析即锁定的 HTTPS 连接:TCP 钉公网 IP,SNI/证书校验仍用原域名。"""
|
|
39
|
+
|
|
40
|
+
def connect(self):
|
|
41
|
+
pinned = pin_host(self.host)
|
|
42
|
+
if pinned is None:
|
|
43
|
+
return super().connect()
|
|
44
|
+
host = self.host
|
|
45
|
+
self.host = pinned
|
|
46
|
+
try:
|
|
47
|
+
http.client.HTTPConnection.connect(self) # 仅 TCP
|
|
48
|
+
finally:
|
|
49
|
+
self.host = host
|
|
50
|
+
server_hostname = self._tunnel_host or host
|
|
51
|
+
self.sock = self._context.wrap_socket(
|
|
52
|
+
self.sock, server_hostname=server_hostname)
|
package/scripts/search.py
CHANGED
|
@@ -563,6 +563,9 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
|
|
|
563
563
|
since: str | None = None,
|
|
564
564
|
until: str | None = None,
|
|
565
565
|
sort: str = "relevance",
|
|
566
|
+
video_only: bool = False,
|
|
567
|
+
min_duration: int | None = None,
|
|
568
|
+
max_duration: int | None = None,
|
|
566
569
|
include_local: bool | None = None,
|
|
567
570
|
include_domains: list[str] | None = None,
|
|
568
571
|
exclude_domains: list[str] | None = None,
|
|
@@ -735,7 +738,10 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
|
|
|
735
738
|
from route import route_query_cached
|
|
736
739
|
|
|
737
740
|
_op_langs = (decision_operators or {}).get("langs") or None
|
|
738
|
-
if local_first:
|
|
741
|
+
if video_only and not local_first and engine == "auto":
|
|
742
|
+
from video_route import video_decision
|
|
743
|
+
decision = video_decision(min_duration, max_duration)
|
|
744
|
+
elif local_first:
|
|
739
745
|
_tk_route = _tick(timing)
|
|
740
746
|
decision = route_query_cached(
|
|
741
747
|
original_query, engine_override="local_search", mode=mode,
|
|
@@ -751,6 +757,8 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
|
|
|
751
757
|
lang_override=_op_langs,
|
|
752
758
|
)
|
|
753
759
|
_tock(timing, "route", _tk_route)
|
|
760
|
+
decision.update(video_only=video_only, min_duration=min_duration,
|
|
761
|
+
max_duration=max_duration)
|
|
754
762
|
if decision_operators:
|
|
755
763
|
decision["operators"] = decision_operators
|
|
756
764
|
if context == "research":
|
package/scripts/search_cli.py
CHANGED
|
@@ -102,6 +102,17 @@ def _max_results_arg(value: str) -> int:
|
|
|
102
102
|
return n
|
|
103
103
|
|
|
104
104
|
|
|
105
|
+
def _non_negative_int(value: str) -> int:
|
|
106
|
+
"""argparse 的 `type=`:时长等非负整数(负值不是「不限」,是坏输入)。"""
|
|
107
|
+
try:
|
|
108
|
+
n = int(value)
|
|
109
|
+
except (TypeError, ValueError):
|
|
110
|
+
raise argparse.ArgumentTypeError(f"必须是整数,收到 {value!r}") from None
|
|
111
|
+
if n < 0:
|
|
112
|
+
raise argparse.ArgumentTypeError(f"不能为负(收到 {n})")
|
|
113
|
+
return n
|
|
114
|
+
|
|
115
|
+
|
|
105
116
|
def build_parser() -> argparse.ArgumentParser:
|
|
106
117
|
"""构造 CLI 参数解析器。
|
|
107
118
|
|
|
@@ -159,6 +170,16 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
159
170
|
parser.add_argument("--sort", default="relevance",
|
|
160
171
|
choices=["relevance", "oldest", "newest"],
|
|
161
172
|
help="时间排序:relevance=相关度(默认), oldest=最早在前(溯源), newest=最新在前")
|
|
173
|
+
parser.add_argument("--video", action="store_true",
|
|
174
|
+
help="只搜视频源(B 站 + anysearch),并只保留视频结果;"
|
|
175
|
+
"不带此开关时视频源只按显式意图路由进入 combo")
|
|
176
|
+
parser.add_argument("--min-duration", type=_non_negative_int, default=None,
|
|
177
|
+
metavar="SEC",
|
|
178
|
+
help="视频最短时长(秒);B 站下推 duration 档位,"
|
|
179
|
+
"其他源按已返回的时长字段后过滤,时长未知的保留")
|
|
180
|
+
parser.add_argument("--max-duration", type=_non_negative_int, default=None,
|
|
181
|
+
metavar="SEC",
|
|
182
|
+
help="视频最长时长(秒);语义同 --min-duration")
|
|
162
183
|
parser.add_argument("--include-domains", default="",
|
|
163
184
|
help="仅保留这些域名(含子域),逗号分隔,如 github.com,arxiv.org")
|
|
164
185
|
parser.add_argument("--exclude-domains", default="",
|
|
@@ -438,6 +459,9 @@ def main():
|
|
|
438
459
|
|
|
439
460
|
if not args.query:
|
|
440
461
|
parser.error("必须提供搜索关键词")
|
|
462
|
+
if (args.min_duration is not None and args.max_duration is not None
|
|
463
|
+
and args.min_duration > args.max_duration):
|
|
464
|
+
parser.error("--min-duration 不能大于 --max-duration")
|
|
441
465
|
|
|
442
466
|
# envelope 默认**关**,要时显式开(--envelope / --archive)。
|
|
443
467
|
#
|
|
@@ -499,6 +523,9 @@ def main():
|
|
|
499
523
|
since=args.since,
|
|
500
524
|
until=args.until,
|
|
501
525
|
sort=args.sort,
|
|
526
|
+
video_only=args.video,
|
|
527
|
+
min_duration=args.min_duration,
|
|
528
|
+
max_duration=args.max_duration,
|
|
502
529
|
include_domains=[d for d in args.include_domains.split(",") if d.strip()] or None,
|
|
503
530
|
exclude_domains=[d for d in args.exclude_domains.split(",") if d.strip()] or None,
|
|
504
531
|
engine_domain=engine_domain,
|
package/scripts/search_entry.py
CHANGED
|
@@ -209,6 +209,15 @@ def prepare(query: str, decision: dict[str, Any], max_results: int,
|
|
|
209
209
|
cache_engine_key += f"|since={since_iso}"
|
|
210
210
|
if until_iso and time_aware:
|
|
211
211
|
cache_engine_key += f"|until={until_iso}"
|
|
212
|
+
# 视频模式与时长过滤进缓存键:--video 与 auto 的结果集不同(前者强制
|
|
213
|
+
# 只留视频),--min-duration 也会改变最终条数;不隔离就会把未过滤的
|
|
214
|
+
# 旧结果当成带条件的答案发回去。
|
|
215
|
+
if (decision or {}).get("video_only"):
|
|
216
|
+
cache_engine_key += "|video=1"
|
|
217
|
+
_min_d = (decision or {}).get("min_duration")
|
|
218
|
+
_max_d = (decision or {}).get("max_duration")
|
|
219
|
+
if _min_d is not None or _max_d is not None:
|
|
220
|
+
cache_engine_key += f"|dur={_min_d or 0}-{_max_d or 0}"
|
|
212
221
|
|
|
213
222
|
if on_progress:
|
|
214
223
|
on_progress(Stage.ROUTING, {"domain": domain, "engine": engine_label, "engines": engines})
|
|
@@ -392,4 +401,5 @@ def dispatch(req: _SearchRequest, run: _SearchRun, hooks: _SearchHooks) -> _Sear
|
|
|
392
401
|
quota_batch=quota_batch,
|
|
393
402
|
run_one=_run_one,
|
|
394
403
|
ingest=_ingest,
|
|
404
|
+
stranded=_dispatch.stranded,
|
|
395
405
|
)
|
package/scripts/search_output.py
CHANGED
|
@@ -85,6 +85,31 @@ _AGENT_RESULT_FIELDS = (
|
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
def _ensure_authority_levels(results: list[dict[str, Any]]) -> None:
|
|
89
|
+
"""把上游原生 authority(DeepSeek 0-4)转成离散等级,补齐非精排路径。
|
|
90
|
+
|
|
91
|
+
`search_rank.local_five_dim_rerank` 只在五维精排里写 `authority_level`;
|
|
92
|
+
单引擎 `--engine`、付费对冲的第二位、以及部分 fast 路径不走精排,于是
|
|
93
|
+
`upstream_authority` 明明在结果里,agent 档的 `authority_level` 却是空。
|
|
94
|
+
DeepSeek 搜索最大的差异点就是这套结构化字段(v2.9.6 接入时的定位),
|
|
95
|
+
输出层丢掉它等于把价值重新埋回去。这里按 `authority_level` 的唯一实现
|
|
96
|
+
回填:上游 0-4 优先,缺失/不可解析再走自有分数映射。
|
|
97
|
+
"""
|
|
98
|
+
try:
|
|
99
|
+
from rank_signals import authority_level
|
|
100
|
+
except Exception:
|
|
101
|
+
return
|
|
102
|
+
for r in results:
|
|
103
|
+
if not isinstance(r, dict):
|
|
104
|
+
continue
|
|
105
|
+
if r.get("authority_level") is not None:
|
|
106
|
+
continue
|
|
107
|
+
upstream = r.get("upstream_authority")
|
|
108
|
+
if upstream in (None, ""):
|
|
109
|
+
continue
|
|
110
|
+
r["authority_level"] = authority_level(r.get("authority"), upstream)
|
|
111
|
+
|
|
112
|
+
|
|
88
113
|
def _slim_verify(v: Any) -> dict[str, Any] | None:
|
|
89
114
|
"""verify 块的 agent 精简版:保留「核验后改了什么」,丢掉逐条细节。
|
|
90
115
|
|
|
@@ -600,6 +625,10 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
|
|
|
600
625
|
except Exception:
|
|
601
626
|
pass
|
|
602
627
|
|
|
628
|
+
# 上游权威等级回填(DeepSeek 0-4):单引擎/对冲路径不走五维精排,
|
|
629
|
+
# 不补这一步 agent 档只能看到空 authority_level。
|
|
630
|
+
_ensure_authority_levels(result.get("results") or [])
|
|
631
|
+
|
|
603
632
|
# 域过滤(后置,引擎无关):融合排序之后裁剪,sources 与 results 保持一致。
|
|
604
633
|
# 裁剪导致不足 n 条是调用方过滤条件的诚实结果,不回填。
|
|
605
634
|
if include_domains or exclude_domains:
|
|
@@ -156,6 +156,9 @@ class _SearchRun:
|
|
|
156
156
|
useful_ms: int = 0
|
|
157
157
|
dispatch_tail: dict[str, int] = field(default_factory=dict)
|
|
158
158
|
early_stopped: bool = False
|
|
159
|
+
# 早停弃置且仍存活的 (engine, holder, now_fn):finalize 交给
|
|
160
|
+
# tail_completion 后台收割。纯数据字段,不改变任何既有阶段的行为。
|
|
161
|
+
stranded: tuple = ()
|
|
159
162
|
budget_used_ms: int | None = None
|
|
160
163
|
budget_total_ms: int | None = None
|
|
161
164
|
elapsed: int = 0
|
|
@@ -430,6 +433,27 @@ def postprocess(req: _SearchRequest, run: _SearchRun, hooks: Any) -> _SearchRun:
|
|
|
430
433
|
except OPT_IMPORT + SHAPE_BENIGN: # 软排序增强,任何失败按「不排序」处理
|
|
431
434
|
pass
|
|
432
435
|
|
|
436
|
+
# ── 视频模式/时长过滤(--video / --min-duration)──
|
|
437
|
+
# 必须在 _pool_limit 截断之前:--video 的候选池同时混着 anysearch 的
|
|
438
|
+
# 网页结果,若先截 top-N 再过滤,B 站结果可能整批落在池外(实测
|
|
439
|
+
# --video --min-duration 600 时 6 条 B 站结果在过滤前就被截掉,只剩
|
|
440
|
+
# 1 条 YouTube)。先过滤再截断,池里才都是候选视频。
|
|
441
|
+
video_filtered = 0
|
|
442
|
+
duration_filtered = 0
|
|
443
|
+
duration_unknown = 0
|
|
444
|
+
_video_only = bool((decision or {}).get("video_only"))
|
|
445
|
+
_min_d = (decision or {}).get("min_duration")
|
|
446
|
+
_max_d = (decision or {}).get("max_duration")
|
|
447
|
+
if merged and (_video_only or _min_d is not None or _max_d is not None):
|
|
448
|
+
from video_meta import filter_duration, filter_video_results
|
|
449
|
+
if _video_only:
|
|
450
|
+
merged, video_filtered = filter_video_results(merged)
|
|
451
|
+
if _min_d is not None or _max_d is not None:
|
|
452
|
+
merged, duration_filtered, duration_unknown = filter_duration(
|
|
453
|
+
merged, _min_d, _max_d)
|
|
454
|
+
_log(f"视频过滤:非视频 {video_filtered},时长不符 {duration_filtered},"
|
|
455
|
+
f"时长未知保留 {duration_unknown}")
|
|
456
|
+
|
|
433
457
|
# 放宽截断:rerank 阶段看到 _pool_limit 条,最终输出再截断 max_results
|
|
434
458
|
merged = merged[:_pool_limit]
|
|
435
459
|
|
|
@@ -508,7 +532,11 @@ def postprocess(req: _SearchRequest, run: _SearchRun, hooks: Any) -> _SearchRun:
|
|
|
508
532
|
_echo_triggered = _echo_needed(merged, query)
|
|
509
533
|
except OPT_IMPORT + SHAPE_BENIGN: # 守卫不可用不设卡(fail-open)
|
|
510
534
|
_echo_triggered = False
|
|
511
|
-
|
|
535
|
+
# 视频/时长模式不做恢复链:恢复链会跨域补搜普通网页,补进来的结果要么
|
|
536
|
+
# 被 video_only 过滤掉(白付一轮网络),要么绕过时长过滤(把已筛掉的
|
|
537
|
+
# 长/短视频重新带回来)。0 条就直接返回空,条件由调用方自己放宽。
|
|
538
|
+
_video_scope = (_video_only or _min_d is not None or _max_d is not None)
|
|
539
|
+
if (not merged or _echo_triggered) and not _video_scope:
|
|
512
540
|
from recovery_runner import run_pipeline_recovery
|
|
513
541
|
_dk = {k: v for k in ("domain", "sub_domain") if (v := getattr(req, "engine_" + k, None))}
|
|
514
542
|
merged, _rec_info = run_pipeline_recovery(
|
|
@@ -668,6 +696,14 @@ def postprocess(req: _SearchRequest, run: _SearchRun, hooks: Any) -> _SearchRun:
|
|
|
668
696
|
"noise_dropped": _noise_dropped,
|
|
669
697
|
"funnel": funnel,
|
|
670
698
|
}
|
|
699
|
+
# 只有真的用了视频/时长过滤才输出这三个账;普通搜索不塞无意义的 0
|
|
700
|
+
# (输出契约:不适用就整个键缺席)。
|
|
701
|
+
if _video_only or _min_d is not None or _max_d is not None:
|
|
702
|
+
result_payload.update(
|
|
703
|
+
video_filtered=video_filtered,
|
|
704
|
+
duration_filtered=duration_filtered,
|
|
705
|
+
duration_unknown=duration_unknown,
|
|
706
|
+
)
|
|
671
707
|
if _site_include or _site_exclude:
|
|
672
708
|
result_payload["site_filter"] = {
|
|
673
709
|
"sites": _site_include, "exclude_sites": _site_exclude,
|
|
@@ -772,7 +808,7 @@ def finalize(req: _SearchRequest, run: _SearchRun, hooks: Any) -> dict[str, Any]
|
|
|
772
808
|
# 自适应学习(单事务批量写入 + cache_guard 统一状态态过滤)
|
|
773
809
|
try:
|
|
774
810
|
import contextlib
|
|
775
|
-
from adaptive import get_learner
|
|
811
|
+
from adaptive import get_learner, scenario_of
|
|
776
812
|
learner = get_learner()
|
|
777
813
|
_outcome_of = {o.get("engine"): o
|
|
778
814
|
for o in engine_outcomes if isinstance(o, dict)}
|
|
@@ -797,12 +833,27 @@ def finalize(req: _SearchRequest, run: _SearchRun, hooks: Any) -> dict[str, Any]
|
|
|
797
833
|
quality = None
|
|
798
834
|
learner.record(eng, success=success, latency_ms=latency,
|
|
799
835
|
cost=0.0 if cost >= 0.85 else 0.001, empty=empty,
|
|
800
|
-
quality=quality)
|
|
836
|
+
quality=quality, **scenario_of(decision))
|
|
801
837
|
except ImportError:
|
|
802
838
|
pass
|
|
803
839
|
except Exception as e:
|
|
804
840
|
_log(f"自适应学习记录跳过: {type(e).__name__}")
|
|
805
841
|
|
|
842
|
+
# 早停后台补全(2026-10-25):弃置引擎的交付不再丢弃,宽限内完成的
|
|
843
|
+
# 记学习器真实成绩 + 合并写 L2 缓存(ARGO_TAIL_COMPLETE_S 控制,0=关)。
|
|
844
|
+
# 放在缓存写与学习记账之后:补全读的是刚写的主缓存条目;主响应已定,
|
|
845
|
+
# 这里的一切都是锦上添花,异常 fail-open。
|
|
846
|
+
if run.stranded:
|
|
847
|
+
try:
|
|
848
|
+
from tail_completion import hand_off
|
|
849
|
+
hand_off(run.stranded, query=query,
|
|
850
|
+
cache_engine_key=cache_engine_key,
|
|
851
|
+
max_results=max_results, domain=domain,
|
|
852
|
+
mode=mode, depth=depth, decision=decision,
|
|
853
|
+
skip_cache=skip_cache, cache_instance=cache)
|
|
854
|
+
except Exception as e:
|
|
855
|
+
_log(f"后台补全移交跳过: {type(e).__name__}")
|
|
856
|
+
|
|
806
857
|
# 语言偏好:记录本轮查询语 + 输出观测快照(默认中英 + 系统 + 习惯)
|
|
807
858
|
lang_pref_info: dict[str, Any] | None = None
|
|
808
859
|
try:
|
|
@@ -896,6 +947,11 @@ def finalize(req: _SearchRequest, run: _SearchRun, hooks: Any) -> dict[str, Any]
|
|
|
896
947
|
if result_payload.get("site_filter") is not None:
|
|
897
948
|
out["site_filter"] = result_payload["site_filter"]
|
|
898
949
|
out["site_filtered"] = result_payload.get("site_filtered", 0)
|
|
950
|
+
# 视频/时长过滤账:用于解释「--min-duration 后为什么只剩 N 条」,
|
|
951
|
+
# duration_unknown 明确告诉调用方有多少条没有时长、未被严格过滤。
|
|
952
|
+
for _key in ("video_filtered", "duration_filtered", "duration_unknown"):
|
|
953
|
+
if _key in result_payload:
|
|
954
|
+
out[_key] = result_payload[_key]
|
|
899
955
|
if lang_pref_info is not None:
|
|
900
956
|
out["lang_pref"] = lang_pref_info
|
|
901
957
|
if timing is not None:
|
package/scripts/search_rank.py
CHANGED
|
@@ -96,6 +96,13 @@ _ENGINE_FUSION_WEIGHTS: dict[str, float] = {
|
|
|
96
96
|
"stackoverflow": 1.1, "imdb": 1.2, "thesportsdb": 1.2, "itunes": 1.2,
|
|
97
97
|
"finviz": 1.2, "sina_quote": 1.2, "tencent_quote": 1.2, "eastmoney": 1.2,
|
|
98
98
|
"fred": 1.3, "worldbank": 1.3, "nbs_stats": 1.3, "eurostat": 1.3, "fx_rate": 1.2, "frankfurter": 1.2,
|
|
99
|
+
# 2026-10-25 补表:学术聚合与官方一手数据此前表外=1.0 基线。实证缺口:
|
|
100
|
+
# 学术域查询常由 core 独家交付(当日实测组合里 arxiv/local_pubmed 零结果、
|
|
101
|
+
# 只 core 有货)却拿基线权重;官方 open data / 法律 / 标准系同理。
|
|
102
|
+
"core": 1.3, "openreview": 1.3, "zenodo": 1.2, "datacite": 1.2,
|
|
103
|
+
"sec_edgar": 1.3, "federal_register": 1.3, "eu_opendata": 1.3,
|
|
104
|
+
"egov_law": 1.3, "openstd": 1.3, "who_gho": 1.3, "usgs": 1.3, "nasa_cmr": 1.3,
|
|
105
|
+
"dshopen": 1.2, "deepseek1024": 1.2, "dsh_hub": 1.15, # DSH 插件目录三源(答案型;理由见 config.yaml dsh_plugin_search.score_floors)
|
|
99
106
|
# 通用引擎(基线)
|
|
100
107
|
"duckduckgo": 1.0, "local_bing": 1.0, "local_duckduckgo": 1.0,
|
|
101
108
|
"local_google": 1.0, "anysearch": 1.05, "byted": 1.1, "bocha": 1.0,
|
package/scripts/serp_guard.py
CHANGED
|
@@ -334,3 +334,26 @@ def filter_content_farms(results: list) -> list:
|
|
|
334
334
|
kept.append(r)
|
|
335
335
|
return kept
|
|
336
336
|
|
|
337
|
+
|
|
338
|
+
# ── 自适应放宽建议(2026-10-23 方案四)───────────────────────────────────
|
|
339
|
+
|
|
340
|
+
_RELAX_TAIL_RE = re.compile(
|
|
341
|
+
r"(?:\b\d{4}年?(?:度)?|\b\d{1,2}月|"
|
|
342
|
+
r"最新|最全|详细|完整|全面|2020|2021|2022|2023|2024|2025|2026|"
|
|
343
|
+
r"知乎|贴吧|论坛|大全|汇总|排行榜|一览|数据|报告|统计|分析|趋势)"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def suggest_relaxed_query(query: str) -> str:
|
|
348
|
+
"""针对 SERP 守卫击杀场景的自适应放宽查询(剥离过度约束的修饰与年份词)。"""
|
|
349
|
+
if not query or not isinstance(query, str):
|
|
350
|
+
return ""
|
|
351
|
+
q = _RELAX_TAIL_RE.sub(" ", query)
|
|
352
|
+
q = re.sub(r"(?<=\s)[年月](?=\s|$)|^([年月]\s+)", " ", q)
|
|
353
|
+
tokens = re.findall(r"[\u4e00-\u9fffA-Za-z0-9]+", q)
|
|
354
|
+
stopwords = {"的", "了", "呢", "吧", "请问", "怎么", "如何", "一下", "关于", "有关", "求", "谁知道",
|
|
355
|
+
"the", "a", "an", "of", "for", "to", "how", "what"}
|
|
356
|
+
kept = [t for t in tokens if t.lower() not in stopwords]
|
|
357
|
+
relaxed = " ".join(kept).strip()
|
|
358
|
+
return relaxed or re.sub(r"\s+", " ", q).strip() or query
|
|
359
|
+
|