argo-search 2.9.9 → 2.10.1
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 +39 -22
- package/README.es.md +39 -22
- package/README.ja.md +38 -21
- package/README.ko.md +38 -21
- package/README.md +41 -22
- package/SKILL.md +13 -12
- package/backends/domain_profiles.json +76 -0
- package/backends/engine_registry.yaml +163 -7
- package/backends/quota_profiles.json +122 -2
- package/backends/source_types_cn.json +9 -0
- package/bin/argo +22 -1
- package/bin/argo.js +3 -3
- package/config.yaml +150 -30
- package/docs/ARGO_INTRO.md +4 -4
- package/docs/ENGINE_CATALOG.md +68 -48
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
- package/docs/RELEASE_NOTES_v2.10.1.md +57 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
- package/engines/_template_http.yaml +2 -0
- 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 +44 -0
- package/engines/specs/sciverse.yaml +73 -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 +3 -2
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/size-gate.test.js +113 -0
- package/scripts/adaptive.py +41 -14
- package/scripts/article.py +6 -1
- package/scripts/article_meta.py +151 -2
- package/scripts/bench_general_pool.py +145 -0
- package/scripts/candidate_envelope.py +45 -4
- package/scripts/charset_decode.py +127 -0
- package/scripts/ci_drift_gate.py +47 -24
- package/scripts/crawl.py +240 -74
- package/scripts/crawl_frontier.py +217 -0
- package/scripts/crawl_policy.py +174 -0
- package/scripts/engine_dispatch.py +23 -18
- package/scripts/engine_failure.py +15 -0
- package/scripts/engine_status.py +12 -5
- package/scripts/engine_validate.py +8 -0
- package/scripts/engines.py +15 -0
- package/scripts/engines_base.py +43 -15
- package/scripts/engines_builders.py +14 -0
- package/scripts/engines_builders_data.py +10 -3
- package/scripts/engines_builders_dsh.py +330 -0
- package/scripts/engines_builders_skill.py +314 -0
- package/scripts/evidence.py +26 -5
- package/scripts/fetch_v3.py +37 -5
- package/scripts/gen_engine_catalog.py +218 -2
- package/scripts/general_pool.py +162 -0
- package/scripts/http_client.py +38 -42
- package/scripts/image_ops.py +4 -0
- package/scripts/install.ps1 +47 -19
- package/scripts/install.sh +45 -20
- package/scripts/local_seek.py +53 -11
- package/scripts/matrix_search_eval.py +17 -1
- package/scripts/mcp_transport.py +1 -1
- package/scripts/ncpssd_bridge.py +123 -0
- package/scripts/paid_policy.py +109 -13
- package/scripts/pre-commit +19 -4
- package/scripts/query_signals.py +156 -3
- package/scripts/redskill/redskill_engine.py +29 -2
- package/scripts/release.py +398 -0
- 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 +37 -59
- package/scripts/route_domains.py +22 -3
- package/scripts/route_policy.py +6 -0
- package/scripts/search.py +13 -3
- package/scripts/search_cli.py +49 -0
- package/scripts/search_entry.py +9 -0
- package/scripts/search_output.py +43 -0
- package/scripts/search_pipeline.py +43 -3
- package/scripts/search_rank.py +4 -1
- package/scripts/serp_guard.py +11 -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/url_canon.py +2 -1
- 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/sub-skills/local-seek/scripts/seek.py +19 -4
- package/engines/specs/_cisa_kev.yaml +0 -54
- package/engines/specs/_osv.yaml +0 -63
- package/scripts/local_engines.py +0 -321
package/scripts/paid_policy.py
CHANGED
|
@@ -11,9 +11,16 @@
|
|
|
11
11
|
再不行返回空,由原 combo 继续。
|
|
12
12
|
- `fast`/`budget` 模式不参与(与 quota 的成本纪律一致)。
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
anysearch/Exa/Tavily
|
|
14
|
+
当前只开三个域:`english_tech`、`intl_news_flash`、`global_event`。
|
|
15
|
+
依据 2026-10-21 多引擎实测:DeepSeek 在英文技术/英文新闻上 p50 515ms、
|
|
16
|
+
日期覆盖 23/39,明显优于 anysearch/Exa/Tavily;中文宽泛新闻与金融原文
|
|
17
|
+
反而更差,故不纳入。
|
|
18
|
+
|
|
19
|
+
2026-10-27(issue #23)追加**语言条件**:`general_search` 且
|
|
20
|
+
`primary_lang=en` 时同样常驻第二位。实测该查询 DeepSeek 589ms/5 条/
|
|
21
|
+
7,064B/5 条带 authority,比免费领队的 1.4–3.0s 更快、比中文长摘要源
|
|
22
|
+
体积小一半;费用 ¥0.005/次(5 元/月≈1000 次),预算耗尽自动跳过。中文
|
|
23
|
+
通用仍不加——按 10-21 的实测结论走。
|
|
17
24
|
"""
|
|
18
25
|
|
|
19
26
|
from __future__ import annotations
|
|
@@ -25,11 +32,48 @@ __all__ = ["PAID_DOMAIN_HEDGES", "hedge_for", "insert_hedge"]
|
|
|
25
32
|
PAID_DOMAIN_HEDGES: dict[str, str] = {
|
|
26
33
|
"english_tech": "deepseek_search",
|
|
27
34
|
"intl_news_flash": "deepseek_search",
|
|
35
|
+
# 2026-10-26:英文新闻里 `US election latest` / `Middle East ceasefire`
|
|
36
|
+
# 实际落在这个域(不是 intl_news_flash);不加这一条,DeepSeek 拿不到
|
|
37
|
+
# 这类查询。新闻域的收益最明确,放在第二位。
|
|
38
|
+
"global_event": "deepseek_search",
|
|
28
39
|
}
|
|
29
40
|
|
|
41
|
+
# 插入位置默认第二位。english_tech 可选用 ARGO_PAID_HEDGE_DEFER=1 降到
|
|
42
|
+
# 第三位(wave-1 只跑免费源,不够才付费)。2026-10-26 四臂实测:
|
|
43
|
+
# 常驻第二位 p50 726ms / 均值 967ms / 权威覆盖 0.83;
|
|
44
|
+
# 条件第三位 p50 749ms / 均值 1246ms / 权威覆盖 0.50,DeepSeek 调用少 75%。
|
|
45
|
+
# p50 打平、均值与权威覆盖常驻更好,而 5 元/月额度足够覆盖这两个域,
|
|
46
|
+
# 故默认常驻;预算紧张或要严格省钱时再开 DEFER。
|
|
47
|
+
# general_search 的英文对冲同样受 DEFER 控制:DEFER=1 时降到第三位,
|
|
48
|
+
# 免费源够用就完全不付费(1000 次/月的额度也能再省一道)。
|
|
49
|
+
_DEFER_DOMAINS = frozenset({"english_tech", "general_search"})
|
|
50
|
+
|
|
30
51
|
_FREE_FALLBACK = "tinyfish"
|
|
31
52
|
|
|
32
53
|
|
|
54
|
+
def _flag(name: str, default: bool = False) -> bool:
|
|
55
|
+
try:
|
|
56
|
+
from engine_env import env_flag
|
|
57
|
+
return bool(env_flag(name, default=default))
|
|
58
|
+
except Exception:
|
|
59
|
+
raw = os.environ.get(name)
|
|
60
|
+
if raw is None:
|
|
61
|
+
return default
|
|
62
|
+
return raw.strip().lower() not in ("", "0", "false", "no", "off")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _hedge_position(domain: str) -> int:
|
|
66
|
+
"""付费对冲插入位置:默认第二位;ARGO_PAID_HEDGE_DEFER=1 时
|
|
67
|
+
english_tech 降到第三位(免费源先跑,不达标才付费)。
|
|
68
|
+
|
|
69
|
+
位置决定「免费源够用时是否还付费」,是速度与成本的直接旋钮;默认值
|
|
70
|
+
由 2026-10-26 四臂实测决定,见上方注释。
|
|
71
|
+
"""
|
|
72
|
+
if _flag("ARGO_PAID_HEDGE_DEFER") and str(domain or "") in _DEFER_DOMAINS:
|
|
73
|
+
return 2
|
|
74
|
+
return 1
|
|
75
|
+
|
|
76
|
+
|
|
33
77
|
def _enabled() -> bool:
|
|
34
78
|
try:
|
|
35
79
|
from engine_env import get_env
|
|
@@ -68,19 +112,65 @@ def _healthy_and_enabled(engine: str, enabled: set[str] | None) -> bool:
|
|
|
68
112
|
return True
|
|
69
113
|
|
|
70
114
|
|
|
115
|
+
def _env_allowed(engine: str) -> bool:
|
|
116
|
+
"""尊重 ENABLE/DISABLE 环境开关(付费例外只豁免 explicit_only)。"""
|
|
117
|
+
try:
|
|
118
|
+
from engine_env import is_engine_allowed_by_env
|
|
119
|
+
return bool(is_engine_allowed_by_env(engine))
|
|
120
|
+
except Exception:
|
|
121
|
+
return True
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _admission_ok(engine: str) -> bool:
|
|
125
|
+
try:
|
|
126
|
+
from engine_admission import is_blocked
|
|
127
|
+
return not is_blocked(engine)
|
|
128
|
+
except Exception:
|
|
129
|
+
return True
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _paid_hedge_ready(engine: str) -> bool:
|
|
133
|
+
"""白名单里的付费引擎:豁免 explicit_only,其余门槛一个不少。
|
|
134
|
+
|
|
135
|
+
为什么不能只查 `engine in enabled`:`deepseek_search` 声明了
|
|
136
|
+
`explicit_only`,而 `config._routable_filter` 正是把它从 enabled 里剔掉
|
|
137
|
+
的那一处(防付费源被 TF-IDF/兜底带到任意查询)。付费对冲是**显式白名单**
|
|
138
|
+
(PAID_DOMAIN_HEDGES),成员资格不能再用 enabled 判一次,否则策略从
|
|
139
|
+
2026-10-21 起就是死代码。这里改为逐项检查:env 禁用、准入拉黑、熔断、
|
|
140
|
+
key、月度预算,仍全部生效。
|
|
141
|
+
"""
|
|
142
|
+
if not _env_allowed(engine) or not _admission_ok(engine):
|
|
143
|
+
return False
|
|
144
|
+
try:
|
|
145
|
+
from route_combo import _breaker_blocked
|
|
146
|
+
if _breaker_blocked(engine):
|
|
147
|
+
return False
|
|
148
|
+
except Exception:
|
|
149
|
+
pass
|
|
150
|
+
return _key_ready(engine) and _budget_ok(engine)
|
|
151
|
+
|
|
152
|
+
|
|
71
153
|
def hedge_for(domain: str, mode: str = "auto",
|
|
72
|
-
enabled: set[str] | None = None
|
|
73
|
-
|
|
154
|
+
enabled: set[str] | None = None,
|
|
155
|
+
lang: str = "") -> list[str]:
|
|
156
|
+
"""返回该域应插入的付费/回落引擎(0 或 1 个)。永不抛异常。
|
|
157
|
+
|
|
158
|
+
`lang` 只对 general_search 生效:英文通用查询才加 DeepSeek 对冲,
|
|
159
|
+
中文通用按 10-21 实测结论不加(中文宽泛查询它更差)。
|
|
160
|
+
"""
|
|
74
161
|
if not _enabled() or mode in ("fast", "budget"):
|
|
75
162
|
return []
|
|
76
|
-
|
|
163
|
+
domain = str(domain or "")
|
|
164
|
+
engine = PAID_DOMAIN_HEDGES.get(domain)
|
|
165
|
+
if not engine and domain == "general_search" and str(lang or "") == "en":
|
|
166
|
+
engine = "deepseek_search"
|
|
77
167
|
if not engine:
|
|
78
168
|
return []
|
|
79
169
|
try:
|
|
80
|
-
if (
|
|
81
|
-
and _key_ready(engine) and _budget_ok(engine)):
|
|
170
|
+
if _paid_hedge_ready(engine):
|
|
82
171
|
return [engine]
|
|
83
|
-
# 付费位不可用:TinyFish
|
|
172
|
+
# 付费位不可用:TinyFish 是免费且带发布日期的回落位。回落位不是
|
|
173
|
+
# 白名单付费源,仍须在 enabled 里(不在说明本机没注册/被禁用)。
|
|
84
174
|
if (_healthy_and_enabled(_FREE_FALLBACK, enabled)
|
|
85
175
|
and _key_ready(_FREE_FALLBACK) and _budget_ok(_FREE_FALLBACK)):
|
|
86
176
|
return [_FREE_FALLBACK]
|
|
@@ -90,9 +180,15 @@ def hedge_for(domain: str, mode: str = "auto",
|
|
|
90
180
|
|
|
91
181
|
|
|
92
182
|
def insert_hedge(combo: list[str], domain: str, mode: str = "auto",
|
|
93
|
-
enabled: set[str] | None = None
|
|
94
|
-
|
|
95
|
-
|
|
183
|
+
enabled: set[str] | None = None,
|
|
184
|
+
lang: str = "") -> list[str]:
|
|
185
|
+
"""把付费/回落引擎插到该域声明的位置(原地改并返回)。
|
|
186
|
+
|
|
187
|
+
默认第二位;english_tech 第三位(免费源先跑,不够才付费)。位置不参与
|
|
188
|
+
排序,只是 combo 的插入下标,后续 wave 调度按位置分波。
|
|
189
|
+
"""
|
|
190
|
+
position = _hedge_position(domain)
|
|
191
|
+
for engine in reversed(hedge_for(domain, mode, enabled=enabled, lang=lang)):
|
|
96
192
|
if engine not in combo:
|
|
97
|
-
combo.insert(min(
|
|
193
|
+
combo.insert(min(max(0, position), len(combo)), engine)
|
|
98
194
|
return combo
|
package/scripts/pre-commit
CHANGED
|
@@ -31,13 +31,27 @@ if [ -z "$root" ] || [ ! -d "$root/tests" ]; then
|
|
|
31
31
|
fi
|
|
32
32
|
cd "$root" || exit 1
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
# 解释器选择:取第一个「存在且真 import 得动 pytest+yaml」的候选。此前是
|
|
35
|
+
# 裸 `command -v python3`——2026-10-26 实测,默认 PATH 的 python3 是 3.15
|
|
36
|
+
# (无 pytest),hook 每次提交都死在 pytest 收集之前,拦截层形同虚设。
|
|
37
|
+
# 与 6971c73 给 eval 侧加的自愈重入是同一类根因(解释器选择散落多处、没有
|
|
38
|
+
# 单一真源),这里把门禁这一处也收进候选链。真 import 而非 find_spec:半装
|
|
39
|
+
# 的 pytest、被 sitecustomize 顶掉的包都属「说在其实不在」(见 bin/argo 严格
|
|
40
|
+
# 档的同类教训)。候选全空时维持原口径 fail closed,绝不静默放行。
|
|
41
|
+
PY=""
|
|
42
|
+
for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3 python; do
|
|
43
|
+
if [ -n "$cand" ] && command -v "$cand" >/dev/null 2>&1 \
|
|
44
|
+
&& "$cand" -c "import pytest, yaml" >/dev/null 2>&1; then
|
|
45
|
+
PY=$cand
|
|
46
|
+
break
|
|
47
|
+
fi
|
|
48
|
+
done
|
|
35
49
|
if [ -z "$PY" ]; then
|
|
36
|
-
echo "[pre-commit]
|
|
50
|
+
echo "[pre-commit] 找不到带 pytest+yaml 的解释器(候选:\$ARGO_GATE_PYTHON、python3.14、python3、python),门禁视为失败" >&2
|
|
37
51
|
exit 1
|
|
38
52
|
fi
|
|
39
53
|
|
|
40
|
-
echo "[pre-commit] argo 快门禁(~12s;全量回归请手动跑 tests/)..."
|
|
54
|
+
echo "[pre-commit] argo 快门禁(~12s,解释器 $PY;全量回归请手动跑 tests/)..."
|
|
41
55
|
"$PY" -m pytest -q \
|
|
42
56
|
tests/test_static_lint_gate.py \
|
|
43
57
|
tests/test_module_size_gate.py \
|
|
@@ -45,4 +59,5 @@ echo "[pre-commit] argo 快门禁(~12s;全量回归请手动跑 tests/)...
|
|
|
45
59
|
tests/test_consistency_gates.py \
|
|
46
60
|
tests/test_routing_snapshot.py \
|
|
47
61
|
tests/test_context_budget.py \
|
|
48
|
-
tests/test_engine_catalog.py
|
|
62
|
+
tests/test_engine_catalog.py \
|
|
63
|
+
tests/test_release_consistency.py
|
package/scripts/query_signals.py
CHANGED
|
@@ -12,8 +12,110 @@
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
+
import math
|
|
16
|
+
import re
|
|
15
17
|
from typing import Any
|
|
16
18
|
|
|
19
|
+
_CJK_RUN_RE = re.compile(r"[\u4e00-\u9fff]+")
|
|
20
|
+
_LATIN_WORD_RE = re.compile(r"[a-z0-9]+")
|
|
21
|
+
|
|
22
|
+
# 查询意图词:描述「怎么问」而不是「问什么」,不参与区分性判定。
|
|
23
|
+
# 只收高频且跨查询无区分度的词;保留 review/practice 这类可能承载主题的词,
|
|
24
|
+
# 避免把正常的结果集误判成「只命中了泛词」。
|
|
25
|
+
_INTENT_STOPWORDS = frozenset({
|
|
26
|
+
"how", "what", "why", "when", "where", "which", "who",
|
|
27
|
+
"the", "and", "or", "for", "with", "without", "vs", "versus",
|
|
28
|
+
"to", "of", "in", "on", "at", "by", "from", "about", "is", "are",
|
|
29
|
+
"best", "top", "good", "guide", "tutorial", "recommend",
|
|
30
|
+
"怎么", "如何", "什么", "为什么", "哪些", "哪个", "推荐", "教程",
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _query_terms(query: str) -> list[str]:
|
|
35
|
+
"""把查询切成「主题词」:CJK 按连续片段(≥2 字),拉丁按词(≥2 字符)。
|
|
36
|
+
|
|
37
|
+
与 `relevance_units` 的区别:那个返回 bigram,用于连续覆盖率;这里返回
|
|
38
|
+
完整片段,用于回答「这条结果到底命中了查询里的几个词」。中文「钙钛矿
|
|
39
|
+
太阳能 稳定性」是三个主题词,不是六个 bigram——按 bigram 数判定会把
|
|
40
|
+
「只命中太阳能」也算成命中两次。
|
|
41
|
+
"""
|
|
42
|
+
q = (query or "").lower()
|
|
43
|
+
terms: list[str] = []
|
|
44
|
+
for seg in _CJK_RUN_RE.findall(q):
|
|
45
|
+
# 中文意图词同样要滤:「如何 部署」若把「如何」当主题词,整批结果
|
|
46
|
+
# 都不命中它,区分性判据会误拒一条本来就答对的部署结果。
|
|
47
|
+
if len(seg) >= 2 and seg not in _INTENT_STOPWORDS:
|
|
48
|
+
terms.append(seg)
|
|
49
|
+
for word in _LATIN_WORD_RE.findall(q):
|
|
50
|
+
if len(word) >= 2 and word not in _INTENT_STOPWORDS:
|
|
51
|
+
terms.append(word)
|
|
52
|
+
seen: set[str] = set()
|
|
53
|
+
out: list[str] = []
|
|
54
|
+
for term in terms:
|
|
55
|
+
if term not in seen:
|
|
56
|
+
seen.add(term)
|
|
57
|
+
out.append(term)
|
|
58
|
+
return out
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _term_covered(term: str, text: str,
|
|
62
|
+
tokens: set[str] | None = None) -> bool:
|
|
63
|
+
"""主题词是否被文本命中:CJK 按 bigram 过半,拉丁按词干前缀。
|
|
64
|
+
|
|
65
|
+
`tokens` 由调用方按结果预算一次(同一条文本要判多个主题词),
|
|
66
|
+
不传时自行分词,保持单测可直接调用。
|
|
67
|
+
"""
|
|
68
|
+
if _CJK_RUN_RE.fullmatch(term):
|
|
69
|
+
units = [term[i:i + 2] for i in range(len(term) - 1)]
|
|
70
|
+
if not units:
|
|
71
|
+
return term in text
|
|
72
|
+
hits = sum(1 for unit in units if unit in text)
|
|
73
|
+
# 词序/分隔(「记忆 插件」vs「记忆插件」)不应让整词判负:
|
|
74
|
+
# 过半 bigram 命中即算这个词出现。
|
|
75
|
+
return hits >= max(1, math.ceil(len(units) * 0.5))
|
|
76
|
+
if tokens is None:
|
|
77
|
+
try:
|
|
78
|
+
from tfidf_router import tokenize
|
|
79
|
+
tokens = set(tokenize(text))
|
|
80
|
+
except ImportError:
|
|
81
|
+
return term in text
|
|
82
|
+
if term in tokens:
|
|
83
|
+
return True
|
|
84
|
+
# 英文词形变化:commit / commits / committed 视为同一主题词。
|
|
85
|
+
return len(term) >= 4 and any(tok.startswith(term) for tok in tokens)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _discriminative_coverage_ok(results: list[dict[str, Any]],
|
|
89
|
+
query: str) -> bool:
|
|
90
|
+
"""至少一条结果同时命中**两个**查询主题词。
|
|
91
|
+
|
|
92
|
+
2026-10-26 实测:查询「git commit」时 local_bing 返回 8 条泛化 Git 页
|
|
93
|
+
(Wikipedia / Install for Windows / Documentation),标题只命中 git,
|
|
94
|
+
旧守卫按「过半结果命中任意一个词」判定为够用 → 早停,真正对题的
|
|
95
|
+
git-commit 手册页被取消。只命中泛词(工具名)不等于回答了查询。
|
|
96
|
+
|
|
97
|
+
判据取「同一条结果命中 ≥2 个主题词」而不是提高覆盖率阈值:长查询的
|
|
98
|
+
正常结果本就只覆盖一半词,阈值一高就误杀;而「只命中一个泛词」在任何
|
|
99
|
+
查询长度下都是同一种失败。单主题词查询(如「Crawl4AI」)不适用。
|
|
100
|
+
"""
|
|
101
|
+
terms = _query_terms(query)
|
|
102
|
+
if len(terms) < 2:
|
|
103
|
+
return True
|
|
104
|
+
try:
|
|
105
|
+
from tfidf_router import tokenize
|
|
106
|
+
except ImportError:
|
|
107
|
+
return True # 分词不可用不设卡(与 query_coverage_ok 同一 fail-open)
|
|
108
|
+
for r in results:
|
|
109
|
+
if not isinstance(r, dict):
|
|
110
|
+
continue
|
|
111
|
+
text = f"{r.get('title') or ''} {r.get('snippet') or ''}".lower()
|
|
112
|
+
tokens = set(tokenize(text))
|
|
113
|
+
covered = sum(1 for term in terms
|
|
114
|
+
if _term_covered(term, text, tokens))
|
|
115
|
+
if covered >= 2:
|
|
116
|
+
return True
|
|
117
|
+
return False
|
|
118
|
+
|
|
17
119
|
|
|
18
120
|
def apply_query_rewrite(query: str) -> tuple[str, dict | None]:
|
|
19
121
|
"""统一查询改写逻辑,返回 (改写后的查询, 改写结果字典)。
|
|
@@ -110,7 +212,8 @@ def is_query_echo(results: list[dict[str, Any]], query: str) -> bool:
|
|
|
110
212
|
return len(covered_terms) == 1
|
|
111
213
|
|
|
112
214
|
|
|
113
|
-
def query_coverage_ok(results: list[dict[str, Any]], query: str
|
|
215
|
+
def query_coverage_ok(results: list[dict[str, Any]], query: str,
|
|
216
|
+
*, strict: bool = False) -> bool:
|
|
114
217
|
"""查询-结果词面覆盖守卫(fast/auto 早停质量门槛)。
|
|
115
218
|
|
|
116
219
|
2026-09-02 实测教训:fast 早停原只看计数+snippet,首引擎上游波动时
|
|
@@ -123,6 +226,15 @@ def query_coverage_ok(results: list[dict[str, Any]], query: str) -> bool:
|
|
|
123
226
|
交集同样会被拒早停(弱信号但非空);同义词改写场景(如「电脑」vs
|
|
124
227
|
「计算机」)可能多跑一个引擎,属可接受代价:宁可多一次调用,不放走
|
|
125
228
|
单引擎垃圾。
|
|
229
|
+
|
|
230
|
+
2026-10-26 补区分性判据(_discriminative_coverage_ok):只命中泛词
|
|
231
|
+
不算够用——「git commit」接受「Git - Install for Windows」是本守卫的
|
|
232
|
+
真实漏网案例。该判据只在「一条结果也没同时命中两个主题词」时拒绝,
|
|
233
|
+
不改变多数覆盖的口径,最坏代价仍是多跑一个引擎。
|
|
234
|
+
|
|
235
|
+
`strict=True`:没有任何权威信号时(authority_level/upstream_authority
|
|
236
|
+
全空或全 0),要求覆盖「明确过半」而不是「达到一半」。免费源的平庸结果
|
|
237
|
+
常在 4 条里只中 2 条就触发早停;收紧后多跑一个引擎,换更高的准确率。
|
|
126
238
|
"""
|
|
127
239
|
if not query or not query.strip():
|
|
128
240
|
return True
|
|
@@ -141,15 +253,24 @@ def query_coverage_ok(results: list[dict[str, Any]], query: str) -> bool:
|
|
|
141
253
|
single_token_titles = sum(
|
|
142
254
|
1 for r in results if len(set(tokenize(r.get("title") or ""))) <= 1
|
|
143
255
|
)
|
|
144
|
-
|
|
256
|
+
# 至少 3 条才判:单条结果本来就可能是「Paris」这种一词答案,把它当
|
|
257
|
+
# 包索引噪声会误杀(2026-10-26 实测「what is the capital of France」)。
|
|
258
|
+
if (len(results) >= 3 and len(q_set) >= 3
|
|
259
|
+
and single_token_titles * 2 > len(results)):
|
|
145
260
|
return False
|
|
146
261
|
if is_query_echo(results, query):
|
|
147
262
|
return False
|
|
263
|
+
if not _discriminative_coverage_ok(results, query):
|
|
264
|
+
return False
|
|
148
265
|
covered = 0
|
|
149
266
|
for r in results:
|
|
150
267
|
text = f"{r.get('title') or ''} {r.get('snippet') or ''}"
|
|
151
268
|
if q_set & set(tokenize(text)):
|
|
152
269
|
covered += 1
|
|
270
|
+
if strict:
|
|
271
|
+
# 明确过半:2 条要 2 条都命中,4 条要 3 条命中。没有权威信号时
|
|
272
|
+
# 不用「刚好一半」换早停。
|
|
273
|
+
return covered > len(results) / 2
|
|
153
274
|
return covered >= max(1, (len(results) + 1) // 2)
|
|
154
275
|
|
|
155
276
|
|
|
@@ -239,6 +360,22 @@ def score_clarity_ok(results: list[dict[str, Any]]) -> bool:
|
|
|
239
360
|
return (std / mean) > 0.02 # 变异系数 ≤2% 视为平坦(实测占位分全等=0)
|
|
240
361
|
|
|
241
362
|
|
|
363
|
+
def _authority_level_of(r: dict[str, Any]) -> int | None:
|
|
364
|
+
"""读单条结果的权威等级(0-4):精排写 authority_level,引擎原生写
|
|
365
|
+
upstream_authority。解析不了/越界返回 None(「没信号」不是「0」)。"""
|
|
366
|
+
for key in ("authority_level", "upstream_authority"):
|
|
367
|
+
value = r.get(key)
|
|
368
|
+
if value in (None, ""):
|
|
369
|
+
continue
|
|
370
|
+
try:
|
|
371
|
+
level = int(float(str(value).strip()))
|
|
372
|
+
except (TypeError, ValueError):
|
|
373
|
+
continue
|
|
374
|
+
if 0 <= level <= 4:
|
|
375
|
+
return level
|
|
376
|
+
return None
|
|
377
|
+
|
|
378
|
+
|
|
242
379
|
def _sufficient_internal(
|
|
243
380
|
results: list[dict[str, Any]],
|
|
244
381
|
mode: str,
|
|
@@ -255,6 +392,8 @@ def _sufficient_internal(
|
|
|
255
392
|
无交集时不许早停
|
|
256
393
|
- 两条路径都叠加平坦分守卫(score_clarity_ok):计数恰好压线且
|
|
257
394
|
分数无区分度时不许早停
|
|
395
|
+
- 权威信号(2026-10-26):任一条 authority≥3 时允许少一条即停;
|
|
396
|
+
全批无权威信号时覆盖要求收紧到「明确过半」,避免平庸免费结果早停
|
|
258
397
|
|
|
259
398
|
壳链不算「够数」(2026-10-11 热榜实测):early-stop 的两条调用
|
|
260
399
|
路径(wave-1 的 _wave1_stop → results_sufficient、wave-2 的
|
|
@@ -282,6 +421,11 @@ def _sufficient_internal(
|
|
|
282
421
|
1 for r in goods
|
|
283
422
|
if (r.get("snippet") or r.get("title") or "").strip()
|
|
284
423
|
)
|
|
424
|
+
authority_max = None
|
|
425
|
+
for r in goods:
|
|
426
|
+
level = _authority_level_of(r)
|
|
427
|
+
if level is not None and (authority_max is None or level > authority_max):
|
|
428
|
+
authority_max = level
|
|
285
429
|
if min_results is not None:
|
|
286
430
|
try:
|
|
287
431
|
need = max(1, int(min_results))
|
|
@@ -294,7 +438,16 @@ def _sufficient_internal(
|
|
|
294
438
|
# 平坦分守卫适用:占位分快照同样可能是垃圾
|
|
295
439
|
return ok and (len(goods) > need or score_clarity_ok(goods))
|
|
296
440
|
threshold = 2 if mode == "fast" else 3
|
|
441
|
+
# 高权威结果可以少一条:auto 默认 3 条,2 条 authority≥3 且覆盖通过
|
|
442
|
+
# 就停。这是 DeepSeek/官方源的结构化字段第一次参与「停不停」的判定。
|
|
443
|
+
if authority_max is not None and authority_max >= 3:
|
|
444
|
+
need = max(2, threshold - 1)
|
|
445
|
+
return (len(goods) >= need and with_snippet >= 1
|
|
446
|
+
and query_coverage_ok(goods, query))
|
|
297
447
|
ok = len(goods) >= threshold and with_snippet >= (1 if mode == "fast" else 2)
|
|
448
|
+
# 全批没有权威信号(None 或 0)时,覆盖要求明确过半;有 1-2 级弱信号
|
|
449
|
+
# 的批不额外收紧,避免把大量正常免费结果误伤。
|
|
450
|
+
strict = authority_max in (None, 0)
|
|
298
451
|
return (ok
|
|
299
|
-
and query_coverage_ok(goods, query)
|
|
452
|
+
and query_coverage_ok(goods, query, strict=strict)
|
|
300
453
|
and (len(goods) > threshold or score_clarity_ok(goods)))
|
|
@@ -57,6 +57,13 @@ RANK_LISTS = {
|
|
|
57
57
|
"today": "todayList",
|
|
58
58
|
"author": "authorList",
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
# 「非可安装」这个关键信息为什么进摘要前缀,而不是 metadata:
|
|
62
|
+
# argo 的 CLI builder 用 image_ops._cli_result_row 做字段白名单,只保留
|
|
63
|
+
# title/url/snippet/source/published_at + 图片字段——metadata 与 upstream
|
|
64
|
+
# **都不透传**(实测 redskill 输出带 metadata,Argo 结果里是 null)。
|
|
65
|
+
# snippet 是 CLI 引擎唯一能自由填充的字段,故把使用方式写在最前面。
|
|
66
|
+
_USAGE_PREFIX = "【小红书技能·APP 内使用】"
|
|
60
67
|
RANK_LABELS = {
|
|
61
68
|
"use": "使用人数榜",
|
|
62
69
|
"new": "7天新增榜",
|
|
@@ -216,10 +223,21 @@ def _search_all(data: dict[str, Any], query: str, n: int) -> list[dict[str, Any]
|
|
|
216
223
|
results.append({
|
|
217
224
|
"title": name,
|
|
218
225
|
"url": url,
|
|
219
|
-
"snippet": str(s.get(
|
|
226
|
+
"snippet": f"{_USAGE_PREFIX}{str(s.get('skill_description', ''))}"[:500],
|
|
220
227
|
"score": round(score, 3),
|
|
221
228
|
"source": "redskill",
|
|
222
229
|
"skill_id": sid,
|
|
230
|
+
# 小红书技能是**提示词/方法论**,不是可安装的代码包。上游数据
|
|
231
|
+
# (allSkills 52314 条)只有 skill_id / skill_name /
|
|
232
|
+
# skill_description 三个字段,**零安装地址**——实测 githubUrl /
|
|
233
|
+
# url / installUrl / repoUrl / note_id 全部为 0 命中;只有 300 条
|
|
234
|
+
# 榜单技能带 note_id。明确标注,避免用户以为「搜到就能装」。
|
|
235
|
+
"metadata": {
|
|
236
|
+
"platform": "xiaohongshu",
|
|
237
|
+
"installable": False,
|
|
238
|
+
"note_id": note,
|
|
239
|
+
"usage": "小红书站内技能:在小红书 APP 内使用,或复制描述作提示词",
|
|
240
|
+
},
|
|
223
241
|
})
|
|
224
242
|
return results
|
|
225
243
|
|
|
@@ -242,7 +260,7 @@ def _rank_list(data: dict[str, Any], rank_type: str, n: int) -> list[dict[str, A
|
|
|
242
260
|
note = item.get("note_id")
|
|
243
261
|
url = EXPLORE_URL.format(note) if note else PAGE_URL
|
|
244
262
|
|
|
245
|
-
snippet = str(item.get(
|
|
263
|
+
snippet = f"{_USAGE_PREFIX}{str(item.get('skill_description', ''))}"[:500]
|
|
246
264
|
results.append({
|
|
247
265
|
"title": item.get("skill_name", ""),
|
|
248
266
|
"url": url,
|
|
@@ -253,6 +271,15 @@ def _rank_list(data: dict[str, Any], rank_type: str, n: int) -> list[dict[str, A
|
|
|
253
271
|
"skill_id": item.get("skill_id"),
|
|
254
272
|
"use_cnt": item.get("use_cnt") if rank_type in ("use", "today") else item.get("new7_cnt"),
|
|
255
273
|
"use_users": item.get("use_users") if rank_type in ("use", "today") else None,
|
|
274
|
+
# 榜单技能有 note_id(可跳笔记),但笔记里也没有「安装包」——
|
|
275
|
+
# 小红书技能的使用入口是 APP 本身,不是下载。同 _search_all。
|
|
276
|
+
"metadata": {
|
|
277
|
+
"platform": "xiaohongshu",
|
|
278
|
+
"installable": False,
|
|
279
|
+
"note_id": note,
|
|
280
|
+
"rank": i + 1,
|
|
281
|
+
"usage": "小红书站内技能:在小红书 APP 内使用,或复制描述作提示词",
|
|
282
|
+
},
|
|
256
283
|
})
|
|
257
284
|
return results
|
|
258
285
|
|