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,285 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""build_route_labels.py — 从本机真实运行数据构建路由回归语料(方案 A)。
|
|
3
|
+
|
|
4
|
+
## 为什么需要它
|
|
5
|
+
|
|
6
|
+
路由准确性的评测集此前只有三处手工维护的语料(ROUTE_MATRIX 135 +
|
|
7
|
+
LEGITIMATE_ROUTES 43 + SUBSTRING_ACCIDENTS 26 = 快照 201 条)加 13 条人工
|
|
8
|
+
标注集。13 条无法区分概念路由的净收益(实测 2 好 2 差),201 条快照只判
|
|
9
|
+
「domain+kind 不漂移」,不判「意图对不对」。
|
|
10
|
+
|
|
11
|
+
本机 `usage_log/query.jsonl` 里有 ~670 条去重真实查询,`badcase.db` 里有
|
|
12
|
+
259 条已归因坏例。本脚本把它们转成可入库的**回归语料**。
|
|
13
|
+
|
|
14
|
+
## 关键定位:回归门,不是准确率门
|
|
15
|
+
|
|
16
|
+
**弱标注的 `domain` 是历史路由的输出,不是真值。** 2026-11-04 实测:
|
|
17
|
+
31 条「路由输出 != 弱标注期望」的失配里,人工复核 20 条,**19 条是弱标注错、
|
|
18
|
+
路由对**(例:`Transformer 注意力机制 原理` 弱标注 academic,路由
|
|
19
|
+
chinese_tech_deep,而 13 条人工集判路由是对的)。
|
|
20
|
+
|
|
21
|
+
因此本脚本产出的语料用于:
|
|
22
|
+
|
|
23
|
+
1. **回归门**:判路由决策在真实查询上**不漂移**(同一条查询的路由输出
|
|
24
|
+
应与语料记录的 `expect_domain` 一致——注意这是「与历史输出一致」,
|
|
25
|
+
不是「与真值一致」);
|
|
26
|
+
2. **分布视图**:看真实查询落在哪些域、哪些域从没被真实查询命中过;
|
|
27
|
+
3. **badcase 锚**:`badcase.db` 的坏例是已确认的失败,用于回归验证。
|
|
28
|
+
|
|
29
|
+
**不用于准确率**。准确率由 `test_route_accuracy_labeled`(13 条人工集)
|
|
30
|
+
和后续扩充的人工集承担。把弱标注当准确率会得出虚高或虚低的错误结论。
|
|
31
|
+
|
|
32
|
+
## 证据分档
|
|
33
|
+
|
|
34
|
+
| 档 | 来源 | 判据 | 用途 |
|
|
35
|
+
|---|---|---|---|
|
|
36
|
+
| A | `badcase.db` 的 query_error / empty_result / recovery | 真实失败,已归因 | badcase 锚(最高优先) |
|
|
37
|
+
| B | `usage_log` 里 errors 非空或 recovered=true | 有失败信号 | 回归 + 失败模式分析 |
|
|
38
|
+
| C | `usage_log` 里正常返回(无 errors、count>0) | 无失败信号 | 分布视图 + 回归 |
|
|
39
|
+
|
|
40
|
+
## 输出
|
|
41
|
+
|
|
42
|
+
`tests/golden/route_labeled.jsonl`,每行:
|
|
43
|
+
|
|
44
|
+
{"query": ..., "expect_domain": ..., "expect_family": ...,
|
|
45
|
+
"evidence": "badcase|usage_error|usage_ok",
|
|
46
|
+
"quality": {...}, "source": "badcase.db|usage_log"}
|
|
47
|
+
|
|
48
|
+
**只入库查询与期望,不含本机路径、状态目录、时间戳**——语料是可公开的
|
|
49
|
+
评测资产,本机状态不是。
|
|
50
|
+
|
|
51
|
+
## 用法
|
|
52
|
+
|
|
53
|
+
python3 scripts/build_route_labels.py # 构建(写 jsonl + 打印统计)
|
|
54
|
+
python3 scripts/build_route_labels.py --dry-run # 只统计不写
|
|
55
|
+
python3 scripts/build_route_labels.py --check # 与已提交文件对账
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
from __future__ import annotations
|
|
59
|
+
|
|
60
|
+
import argparse
|
|
61
|
+
import json
|
|
62
|
+
import os
|
|
63
|
+
import sqlite3
|
|
64
|
+
import sys
|
|
65
|
+
from collections import Counter, defaultdict
|
|
66
|
+
from pathlib import Path
|
|
67
|
+
from typing import Any
|
|
68
|
+
|
|
69
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
70
|
+
SCRIPTS = ROOT / "scripts"
|
|
71
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
72
|
+
|
|
73
|
+
OUTPUT = ROOT / "tests" / "golden" / "route_labeled.jsonl"
|
|
74
|
+
|
|
75
|
+
# usage_log 目录:与 badcase_ledger 同源(走 argo_paths,可被 ARGO_STATE_DIR 覆盖)
|
|
76
|
+
def _usage_log_dir() -> Path:
|
|
77
|
+
import argo_paths
|
|
78
|
+
return Path(argo_paths.state_path("usage_log"))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _badcase_db() -> Path:
|
|
82
|
+
import argo_paths
|
|
83
|
+
return Path(argo_paths.state_path("badcase.db"))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# ── 读取本机数据 ────────────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
def _read_usage_log() -> list[dict[str, Any]]:
|
|
89
|
+
"""读 usage_log/query.jsonl(可能多份轮转文件)。"""
|
|
90
|
+
d = _usage_log_dir()
|
|
91
|
+
if not d.is_dir():
|
|
92
|
+
return []
|
|
93
|
+
out: list[dict[str, Any]] = []
|
|
94
|
+
for f in sorted(d.glob("query*.jsonl")):
|
|
95
|
+
try:
|
|
96
|
+
for line in f.read_text(encoding="utf-8").splitlines():
|
|
97
|
+
if not line.strip():
|
|
98
|
+
continue
|
|
99
|
+
try:
|
|
100
|
+
r = json.loads(line)
|
|
101
|
+
except json.JSONDecodeError:
|
|
102
|
+
continue
|
|
103
|
+
if r.get("stream") == "query" and (r.get("query") or "").strip():
|
|
104
|
+
out.append(r)
|
|
105
|
+
except OSError:
|
|
106
|
+
continue
|
|
107
|
+
return out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _read_badcases() -> list[dict[str, Any]]:
|
|
111
|
+
"""读 badcase.db(只取查询类坏例,breaker 无查询)。"""
|
|
112
|
+
p = _badcase_db()
|
|
113
|
+
if not p.is_file():
|
|
114
|
+
return []
|
|
115
|
+
try:
|
|
116
|
+
con = sqlite3.connect(str(p), timeout=8)
|
|
117
|
+
rows = list(con.execute(
|
|
118
|
+
"SELECT kind, query, engine, detail FROM badcases "
|
|
119
|
+
"WHERE kind IN ('query_error','empty_result','recovery') "
|
|
120
|
+
"AND query <> ''"))
|
|
121
|
+
con.close()
|
|
122
|
+
return [{"kind": r[0], "query": r[1], "engine": r[2] or "",
|
|
123
|
+
"detail": r[3] or ""} for r in rows]
|
|
124
|
+
except sqlite3.Error:
|
|
125
|
+
return []
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# ── 构建标注 ────────────────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
def _family_of(engine: str) -> str | None:
|
|
131
|
+
try:
|
|
132
|
+
from engine_families import family_of
|
|
133
|
+
return family_of(engine)
|
|
134
|
+
except Exception:
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def build() -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
|
139
|
+
"""构建标注集,返回 (条目列表, 统计)。"""
|
|
140
|
+
usage = _read_usage_log()
|
|
141
|
+
badcases = _read_badcases()
|
|
142
|
+
|
|
143
|
+
# usage_log 按查询聚合:同查询多次出现时,domain 是否稳定
|
|
144
|
+
by_query: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
|
145
|
+
for r in usage:
|
|
146
|
+
by_query[(r.get("query") or "").strip()].append(r)
|
|
147
|
+
|
|
148
|
+
entries: dict[str, dict[str, Any]] = {}
|
|
149
|
+
|
|
150
|
+
# ── A 档:badcase.db(最高优先,覆盖 usage_log 的同查询条目)──
|
|
151
|
+
for b in badcases:
|
|
152
|
+
q = (b.get("query") or "").strip()
|
|
153
|
+
if not q:
|
|
154
|
+
continue
|
|
155
|
+
# badcase 记录的是「失败时的引擎」,期望域要从 usage_log 里找该查询的
|
|
156
|
+
# domain;找不到就跳过(没有期望域的坏例无法当标注用)。
|
|
157
|
+
dom = None
|
|
158
|
+
for r in by_query.get(q, []):
|
|
159
|
+
if r.get("domain"):
|
|
160
|
+
dom = r["domain"]
|
|
161
|
+
break
|
|
162
|
+
if not dom:
|
|
163
|
+
continue
|
|
164
|
+
entries[q] = {
|
|
165
|
+
"query": q,
|
|
166
|
+
"expect_domain": dom,
|
|
167
|
+
"expect_family": _family_of((b.get("engine") or "").split(",")[0]),
|
|
168
|
+
"evidence": "badcase",
|
|
169
|
+
"quality": {"errors": True, "recovered": b["kind"] == "recovery",
|
|
170
|
+
"count": 0, "occurrences": len(by_query.get(q, [])),
|
|
171
|
+
"badcase_kind": b["kind"]},
|
|
172
|
+
"source": "badcase.db",
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# ── B/C 档:usage_log ──
|
|
176
|
+
for q, rows in by_query.items():
|
|
177
|
+
if not q:
|
|
178
|
+
continue
|
|
179
|
+
domains = [r.get("domain") for r in rows if r.get("domain")]
|
|
180
|
+
if not domains:
|
|
181
|
+
continue
|
|
182
|
+
# 稳定性:同查询多次出现时 domain 必须一致(否则是噪声,跳过)
|
|
183
|
+
if len(set(domains)) > 1:
|
|
184
|
+
continue
|
|
185
|
+
dom = domains[0]
|
|
186
|
+
has_error = any(r.get("errors") for r in rows)
|
|
187
|
+
recovered = any(r.get("recovered") for r in rows)
|
|
188
|
+
counts = [r.get("count") or 0 for r in rows]
|
|
189
|
+
# C 档(无错误信号)要求至少出现 2 次或 count 中位数 > 0
|
|
190
|
+
# ——单次出现的正常条目证据太弱
|
|
191
|
+
evidence = "usage_error" if (has_error or recovered) else "usage_ok"
|
|
192
|
+
if evidence == "usage_ok" and len(rows) < 2 and max(counts) == 0:
|
|
193
|
+
continue
|
|
194
|
+
# A/B 档已覆盖的查询不重复入(badcase 优先)
|
|
195
|
+
if q in entries:
|
|
196
|
+
continue
|
|
197
|
+
# 期望主源族:取该查询出现最多的引擎的族
|
|
198
|
+
eng_counter: Counter[str] = Counter()
|
|
199
|
+
for r in rows:
|
|
200
|
+
for e in (r.get("engines_used") or []):
|
|
201
|
+
eng_counter[e] += 1
|
|
202
|
+
top_eng = eng_counter.most_common(1)[0][0] if eng_counter else None
|
|
203
|
+
entries[q] = {
|
|
204
|
+
"query": q,
|
|
205
|
+
"expect_domain": dom,
|
|
206
|
+
"expect_family": _family_of(top_eng) if top_eng else None,
|
|
207
|
+
"evidence": evidence,
|
|
208
|
+
"quality": {"errors": has_error, "recovered": recovered,
|
|
209
|
+
"count": max(counts), "occurrences": len(rows)},
|
|
210
|
+
"source": "usage_log",
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
out = [entries[k] for k in sorted(entries)]
|
|
214
|
+
stats = {
|
|
215
|
+
"total": len(out),
|
|
216
|
+
"by_evidence": dict(Counter(e["evidence"] for e in out)),
|
|
217
|
+
"by_source": dict(Counter(e["source"] for e in out)),
|
|
218
|
+
"domains": len(set(e["expect_domain"] for e in out)),
|
|
219
|
+
"usage_log_raw": len(usage),
|
|
220
|
+
"usage_log_unique": len(by_query),
|
|
221
|
+
"badcases": len(badcases),
|
|
222
|
+
}
|
|
223
|
+
return out, stats
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _write(entries: list[dict[str, Any]]) -> None:
|
|
227
|
+
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
|
|
228
|
+
with OUTPUT.open("w", encoding="utf-8") as f:
|
|
229
|
+
for e in entries:
|
|
230
|
+
f.write(json.dumps(e, ensure_ascii=False) + "\n")
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _check() -> int:
|
|
234
|
+
if not OUTPUT.is_file():
|
|
235
|
+
print(f"[build_route_labels] 标注集不存在:{OUTPUT}", file=sys.stderr)
|
|
236
|
+
return 1
|
|
237
|
+
recorded = {}
|
|
238
|
+
for line in OUTPUT.read_text(encoding="utf-8").splitlines():
|
|
239
|
+
if line.strip():
|
|
240
|
+
d = json.loads(line)
|
|
241
|
+
recorded[d["query"]] = d
|
|
242
|
+
entries, stats = build()
|
|
243
|
+
current = {e["query"]: e for e in entries}
|
|
244
|
+
problems = []
|
|
245
|
+
for q in sorted(set(current) - set(recorded)):
|
|
246
|
+
problems.append(f" 新增: {q!r}")
|
|
247
|
+
for q in sorted(set(recorded) - set(current)):
|
|
248
|
+
problems.append(f" 消失: {q!r}(本机数据已清理?)")
|
|
249
|
+
for q in sorted(set(current) & set(recorded)):
|
|
250
|
+
if current[q]["expect_domain"] != recorded[q]["expect_domain"]:
|
|
251
|
+
problems.append(
|
|
252
|
+
f" 期望域漂移: {q!r} {recorded[q]['expect_domain']!r}"
|
|
253
|
+
f" -> {current[q]['expect_domain']!r}")
|
|
254
|
+
if problems:
|
|
255
|
+
print("标注集漂移:\n " + "\n ".join(problems[:40]), file=sys.stderr)
|
|
256
|
+
return 1
|
|
257
|
+
print(f"[build_route_labels] 一致({len(recorded)} 条)")
|
|
258
|
+
return 0
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def main() -> int:
|
|
262
|
+
ap = argparse.ArgumentParser(description="从本机真实运行数据构建路由标注集")
|
|
263
|
+
ap.add_argument("--dry-run", action="store_true", help="只统计不写")
|
|
264
|
+
ap.add_argument("--check", action="store_true", help="与已提交文件对账")
|
|
265
|
+
args = ap.parse_args()
|
|
266
|
+
|
|
267
|
+
entries, stats = build()
|
|
268
|
+
print(f"[build_route_labels] 原始 usage_log {stats['usage_log_raw']} 行 / "
|
|
269
|
+
f"去重 {stats['usage_log_unique']} 条;badcase {stats['badcases']} 条")
|
|
270
|
+
print(f"[build_route_labels] 标注集 {stats['total']} 条,"
|
|
271
|
+
f"覆盖 {stats['domains']} 个域")
|
|
272
|
+
print(f"[build_route_labels] 证据分档: {stats['by_evidence']}")
|
|
273
|
+
print(f"[build_route_labels] 来源: {stats['by_source']}")
|
|
274
|
+
|
|
275
|
+
if args.check:
|
|
276
|
+
return _check()
|
|
277
|
+
if args.dry_run:
|
|
278
|
+
return 0
|
|
279
|
+
_write(entries)
|
|
280
|
+
print(f"[build_route_labels] 已写入 {OUTPUT}")
|
|
281
|
+
return 0
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
if __name__ == "__main__":
|
|
285
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""caliber_dedupe.py — 跨口径同 URL 合并(口径拼接之后的最后一道去重)。
|
|
3
|
+
|
|
4
|
+
## 为什么必须在口径拼接之后再做一次
|
|
5
|
+
|
|
6
|
+
`caliber_isolation.merge_within_caliber` 只在**同一口径内**按 URL 折叠。
|
|
7
|
+
同一 URL 被不同口径的引擎同时命中时(维基词条既被百科源也被通用源返回),
|
|
8
|
+
拼接路径会让它出现两次:
|
|
9
|
+
|
|
10
|
+
- 用户看到重复条目;
|
|
11
|
+
- `ranking_eval` 的 nDCG 因为「同一相关项被计两次」算出大于 1 的值
|
|
12
|
+
(实测金标 `consensus_vs_longtext` nDCG=1.4525,而定义上界是 1)。
|
|
13
|
+
|
|
14
|
+
## 去重不删证据
|
|
15
|
+
|
|
16
|
+
合并 `consensus_engines`、取最大 `_rrf_score`、保留更长的标题/摘要、
|
|
17
|
+
拼接 `source`。跨口径共识信号因此保留,而不是被当成重复丢掉。
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def merge_cross_caliber_duplicates(
|
|
26
|
+
rows: list[dict[str, Any]],
|
|
27
|
+
canonical_url=None,
|
|
28
|
+
) -> list[dict[str, Any]]:
|
|
29
|
+
"""按归一 URL 合并跨口径重复条;无重复时原样返回。"""
|
|
30
|
+
if not rows or len(rows) <= 1:
|
|
31
|
+
return rows
|
|
32
|
+
if canonical_url is None:
|
|
33
|
+
from url_canon import canonical_url
|
|
34
|
+
index: dict[str, dict[str, Any]] = {}
|
|
35
|
+
out: list[dict[str, Any]] = []
|
|
36
|
+
for r in rows:
|
|
37
|
+
if not isinstance(r, dict):
|
|
38
|
+
continue
|
|
39
|
+
key = (
|
|
40
|
+
canonical_url(r.get("url", ""))
|
|
41
|
+
or (f"__title__:{r.get('title', '')}" if r.get("title") else "")
|
|
42
|
+
or (f"__card__:{r.get('card_type', '')}" if r.get("card_type") else "")
|
|
43
|
+
or f"__idx__:{id(r)}"
|
|
44
|
+
)
|
|
45
|
+
cur = index.get(key)
|
|
46
|
+
if cur is None:
|
|
47
|
+
index[key] = r
|
|
48
|
+
out.append(r)
|
|
49
|
+
continue
|
|
50
|
+
cons = list(cur.get("consensus_engines") or [])
|
|
51
|
+
for eng in r.get("consensus_engines") or []:
|
|
52
|
+
if eng and eng not in cons:
|
|
53
|
+
cons.append(eng)
|
|
54
|
+
cur["consensus_engines"] = cons
|
|
55
|
+
cur["_rrf_score"] = round(max(
|
|
56
|
+
float(cur.get("_rrf_score") or 0.0),
|
|
57
|
+
float(r.get("_rrf_score") or 0.0),
|
|
58
|
+
), 6)
|
|
59
|
+
sources = {cur.get("source", ""), r.get("source", "")}
|
|
60
|
+
cur["source"] = "/".join(s for s in sources if s)
|
|
61
|
+
new_txt = f"{r.get('title', '')} {r.get('snippet', '')}"
|
|
62
|
+
cur_txt = f"{cur.get('title', '')} {cur.get('snippet', '')}"
|
|
63
|
+
if len(new_txt) > len(cur_txt):
|
|
64
|
+
cur["title"] = r.get("title", cur.get("title"))
|
|
65
|
+
cur["snippet"] = r.get("snippet", cur.get("snippet"))
|
|
66
|
+
return out
|
|
@@ -187,9 +187,11 @@ def merge_by_caliber(
|
|
|
187
187
|
_canonical_url=_canonical_url, _engine_weight=_engine_weight,
|
|
188
188
|
)
|
|
189
189
|
|
|
190
|
-
#
|
|
190
|
+
# 不同口径按优先级排序后并列输出;拼接后再按 URL 合并一次,
|
|
191
|
+
# 避免同一文档因跨口径命中被交付两遍(共识证据并入首条)。
|
|
191
192
|
out = []
|
|
192
193
|
for cal in sorted(merged_by_caliber.keys(),
|
|
193
194
|
key=lambda c: _CALIBER_PRIORITY.get(c, 8)):
|
|
194
195
|
out.extend(merged_by_caliber[cal])
|
|
195
|
-
|
|
196
|
+
from caliber_dedupe import merge_cross_caliber_duplicates
|
|
197
|
+
return merge_cross_caliber_duplicates(out, _canonical_url)
|
package/scripts/ci_drift_gate.py
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""漂移门判定:把夜间「重录 vs 滚动基线」的比较结果变成退出码。
|
|
3
3
|
|
|
4
4
|
## 为什么单独成文件
|
|
5
5
|
|
|
6
6
|
判定逻辑原来写在 nightly.yml 的 heredoc 里:语法对错只能在推上去之后知道,
|
|
7
7
|
阈值改松改紧也没人测。抽出来后有两个好处——本地能跑同一套判定,用例能锁住
|
|
8
|
-
|
|
8
|
+
「什么算回归」这条契约(tests/test_ci_drift_gate.py)。
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## 2026-10-29 起只判结构回归,不再判数值漂移
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
|
|
12
|
+
活网重录下「结果换血」是常态不是回归:2026-10-28 夜(issue #35)四条固定
|
|
13
|
+
查询三条整批换血,asyncio 一条体积 +32% 破线,逐条核对全是外部排名漂移
|
|
14
|
+
(docs.python.org 掉出、内容农场页换入),没有一条是 argo 自己的问题。
|
|
15
|
+
静态基线 + 数值阈值的设计每周都会红一次、开一个无人能修的 issue。所以:
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
- **基线改滚动**:绿跑后由 nightly 把本次报告提交为新基线([skip ci]),
|
|
18
|
+
门比较的是「今晚 vs 昨晚」,源一夜之间死掉才红;
|
|
19
|
+
- **只判结构回归**:条数跌破地板(-1 允许)、单条查询零结果、基线里有的
|
|
20
|
+
用例整条消失(查询集被改或录制失败);
|
|
21
|
+
- **体积只记录不判**:超阈值打一行信息项进日志,供人翻 artifact 时对照,
|
|
22
|
+
不再当失败。
|
|
23
|
+
|
|
24
|
+
两处已知边界,刻意接受:每晚 -1 条的缓慢衰减不会红(地板只看单晚),
|
|
25
|
+
趋势由 ledger 账本的结果率曲线盯着;`not_recorded`(重放时要了一个当时
|
|
26
|
+
没调过的引擎)也不计入——录制只保留真正被调到的引擎,而重放是瞬时完成,
|
|
27
|
+
早停时机与真跑不同,这是录制机制的正常边界,当成回归报会制造长期噪音。
|
|
18
28
|
|
|
19
29
|
用法:
|
|
20
30
|
python3 scripts/ci_drift_gate.py --baseline 基线报告.json --current 本次报告.json
|
|
21
|
-
退出码:0 通过;1
|
|
22
|
-
|
|
31
|
+
退出码:0 通过;1 结构回归;2 输入缺失/格式不对(这两件事必须分开,混在
|
|
32
|
+
一起会让人以为「红了=质量掉了」)。
|
|
23
33
|
"""
|
|
24
34
|
|
|
25
35
|
from __future__ import annotations
|
|
@@ -30,8 +40,8 @@ import sys
|
|
|
30
40
|
from pathlib import Path
|
|
31
41
|
from typing import Any
|
|
32
42
|
|
|
33
|
-
KEPT_SLACK = 1 # 允许少 1
|
|
34
|
-
BYTES_GROWTH = 1.2 #
|
|
43
|
+
KEPT_SLACK = 1 # 允许少 1 条(工具源单条抖动很常见)
|
|
44
|
+
BYTES_GROWTH = 1.2 # 体积信息项:超过基线 20% 打一行,不判失败
|
|
35
45
|
|
|
36
46
|
|
|
37
47
|
def _load(path: Path) -> dict[str, Any]:
|
|
@@ -45,17 +55,14 @@ def violations(base: dict[str, Any], cur: dict[str, Any]) -> list[str]:
|
|
|
45
55
|
cur_ids = {c.get("id") for c in (cur.get("cases") or [])}
|
|
46
56
|
out: list[str] = []
|
|
47
57
|
for case in cur.get("cases") or []:
|
|
48
|
-
old = by_id.get(case.get("id"))
|
|
49
|
-
if not old:
|
|
50
|
-
continue # 新增的用例没有基线,不算漂移
|
|
51
58
|
cid = case.get("id")
|
|
52
|
-
kept
|
|
53
|
-
if kept
|
|
54
|
-
out.append(f"{cid}:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
kept = case.get("kept", 0)
|
|
60
|
+
if kept == 0:
|
|
61
|
+
out.append(f"{cid}: 零结果——交付层死了(源挂/解析坏),这不是查询没人问")
|
|
62
|
+
continue
|
|
63
|
+
old = by_id.get(cid)
|
|
64
|
+
if old and kept < old.get("kept", 0) - KEPT_SLACK:
|
|
65
|
+
out.append(f"{cid}: 结果 {kept} 条,基线 {old.get('kept', 0)} 条")
|
|
59
66
|
# 基线里有、本次没有:不是「通过」,是这条根本没被录到(查询集被改、
|
|
60
67
|
# 或录制整条失败)。2026-10-22 本地实跑踩过:只剩 1 条时判定照样退 0。
|
|
61
68
|
for cid in by_id:
|
|
@@ -64,8 +71,22 @@ def violations(base: dict[str, Any], cur: dict[str, Any]) -> list[str]:
|
|
|
64
71
|
return out
|
|
65
72
|
|
|
66
73
|
|
|
74
|
+
def drift_notes(base: dict[str, Any], cur: dict[str, Any]) -> list[str]:
|
|
75
|
+
"""信息项:写进日志供人对照,不参与退出码。"""
|
|
76
|
+
by_id = {c.get("id"): c for c in (base.get("cases") or [])}
|
|
77
|
+
notes: list[str] = []
|
|
78
|
+
for case in cur.get("cases") or []:
|
|
79
|
+
old_bytes = (by_id.get(case.get("id")) or {}).get("bytes", 0)
|
|
80
|
+
new_bytes = case.get("bytes", 0)
|
|
81
|
+
if old_bytes and new_bytes > old_bytes * BYTES_GROWTH:
|
|
82
|
+
pct = round((new_bytes - old_bytes) / old_bytes * 100)
|
|
83
|
+
notes.append(f"{case.get('id')}: 输出 {new_bytes}B,基线 {old_bytes}B"
|
|
84
|
+
f"(+{pct}%)——网页常态漂移,仅记录")
|
|
85
|
+
return notes
|
|
86
|
+
|
|
87
|
+
|
|
67
88
|
def main() -> int:
|
|
68
|
-
ap = argparse.ArgumentParser(description="
|
|
89
|
+
ap = argparse.ArgumentParser(description="夜间漂移阈值判定(只判结构回归)")
|
|
69
90
|
ap.add_argument("--baseline", required=True)
|
|
70
91
|
ap.add_argument("--current", required=True)
|
|
71
92
|
args = ap.parse_args()
|
|
@@ -77,12 +98,14 @@ def main() -> int:
|
|
|
77
98
|
print(f"读不到报告:{type(e).__name__}: {e}", file=sys.stderr)
|
|
78
99
|
return 2
|
|
79
100
|
|
|
101
|
+
for note in drift_notes(base, cur):
|
|
102
|
+
print(f"信息项:{note}")
|
|
80
103
|
bad = violations(base, cur)
|
|
81
104
|
if bad:
|
|
82
105
|
print("\n".join(bad), file=sys.stderr)
|
|
83
106
|
return 1
|
|
84
107
|
print(f"通过:{len(cur.get('cases') or [])} 条,漏录 "
|
|
85
|
-
f"{cur.get('total_missing', 0)}
|
|
108
|
+
f"{cur.get('total_missing', 0)} 个引擎(信息项,不算回归)")
|
|
86
109
|
return 0
|
|
87
110
|
|
|
88
111
|
|
|
@@ -21,7 +21,25 @@ from typing import Any, Optional
|
|
|
21
21
|
# 本地状态目录唯一来源(env ARGO_STATE_DIR → config cache.db_path 父目录 → 旧路径)
|
|
22
22
|
import argo_paths as _paths
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# 默认状态路径**调用期解析**,不在导入期派生。
|
|
25
|
+
#
|
|
26
|
+
# 为什么:`ARGO_STATE_DIR` 在导入后才被改写是常态(测试用临时目录验证路径派生、
|
|
27
|
+
# 多工作树/子进程切换状态根)。导入期常量会让「记录」与「读取」落到两个不同文件,
|
|
28
|
+
# 且同一个类对默认路径给出两个答案。2026-11-02 的 `ec5b959` 只在消费侧(search_v3
|
|
29
|
+
# 调用期解析工厂)堵住了症状,源头这一处仍在——实测只改 `ARGO_STATE_DIR`、不重导入
|
|
30
|
+
# 时 `CircuitBreaker()._path` 仍指向旧目录。
|
|
31
|
+
#
|
|
32
|
+
# 用 PEP 562 模块 `__getattr__` 暴露 `STATE_PATH`:每次访问都按当前环境解析,
|
|
33
|
+
# 既保持「`circuit_breaker.STATE_PATH` 可读、可 patch」的既有契约(测试与
|
|
34
|
+
# monkeypatch 依赖它),又不再把值钉在导入那一刻。
|
|
35
|
+
def _default_state_path() -> str:
|
|
36
|
+
return str(_paths.state_path("circuit_breaker.json"))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def __getattr__(name: str):
|
|
40
|
+
if name == "STATE_PATH":
|
|
41
|
+
return str(_default_state_path())
|
|
42
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
25
43
|
|
|
26
44
|
# 熔断参数
|
|
27
45
|
FAILURE_THRESHOLD = 2 # 连续失败次数
|
|
@@ -38,8 +56,12 @@ DISABLE_COOLDOWN_SECONDS = 3600 # 禁用后 1h 内不自动恢复(避免频
|
|
|
38
56
|
class CircuitBreaker:
|
|
39
57
|
"""进程内 + 磁盘共享的引擎熔断器。"""
|
|
40
58
|
|
|
41
|
-
def __init__(self, state_path: str =
|
|
42
|
-
|
|
59
|
+
def __init__(self, state_path: str | None = None):
|
|
60
|
+
# 读模块属性而非 `_default_state_path()`:`STATE_PATH` 可被 monkeypatch,
|
|
61
|
+
# 且每次构造都按当前 ARGO_STATE_DIR 解析(见模块 `__getattr__`)。
|
|
62
|
+
# 注意用 `globals().get`:函数体内的裸名查找不触发 PEP 562 `__getattr__`。
|
|
63
|
+
self._path = state_path if state_path else (
|
|
64
|
+
globals().get("STATE_PATH") or _default_state_path())
|
|
43
65
|
self._lock = threading.RLock()
|
|
44
66
|
self._engines: dict[str, dict[str, Any]] = {}
|
|
45
67
|
self._neg: dict[str, dict[str, Any]] = {} # key → {expires, status}
|