argo-search 2.14.1 → 2.15.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/AGENTS.md +8 -6
- package/README.es.md +54 -832
- package/README.ja.md +53 -833
- package/README.ko.md +53 -831
- package/README.md +126 -769
- package/README.zh.md +124 -893
- package/SKILL.md +17 -18
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +23 -23
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +42 -0
- package/backends/engine_concept_vectors.json +1525 -1525
- package/backends/engine_registry.yaml +124 -28
- package/backends/quota_profiles.json +70 -0
- package/bin/argo +30 -17
- package/config.yaml +173 -33
- package/docs/ADDING_NEW_ENGINE.md +10 -0
- package/docs/ARGO_INTRO.md +1 -1
- package/docs/CHANGELOG.md +23 -0
- package/docs/ENGINE_CATALOG.md +97 -85
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
- package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/ai_labs.yaml +89 -0
- package/engines/specs/bilibili_hot.yaml +11 -1
- package/engines/specs/brave.yaml +3 -3
- package/engines/specs/cisa_alerts.yaml +40 -0
- package/engines/specs/cn_ai_news.yaml +10 -8
- package/engines/specs/digup.yaml +11 -6
- package/engines/specs/douyin_hot.yaml +11 -1
- package/engines/specs/dw_news.yaml +4 -2
- package/engines/specs/eng_blogs.yaml +63 -0
- package/engines/specs/europeana.yaml +3 -4
- package/engines/specs/felo.yaml +3 -3
- package/engines/specs/firecrawl.yaml +3 -0
- package/engines/specs/fourget.yaml +5 -2
- package/engines/specs/france24.yaml +6 -4
- package/engines/specs/fxtwitter.yaml +29 -6
- package/engines/specs/grepapp_mcp.yaml +62 -0
- package/engines/specs/guardian_rss.yaml +6 -4
- package/engines/specs/itotii.yaml +13 -1
- package/engines/specs/lobsters.yaml +41 -0
- package/engines/specs/local_seek.yaml +6 -0
- package/engines/specs/open_meteo.yaml +1 -1
- package/engines/specs/redskill.yaml +2 -0
- package/engines/specs/searxng.yaml +4 -2
- package/engines/specs/sec_edgar.yaml +8 -3
- package/engines/specs/tinyfish.yaml +2 -0
- package/engines/specs/tinyfish_news.yaml +2 -0
- package/engines/specs/tinyfish_paper.yaml +2 -0
- package/engines/specs/toutiao_hot.yaml +11 -1
- package/engines/specs/train.yaml +3 -0
- package/engines/specs/twitter.yaml +4 -0
- package/engines/specs/unpaywall.yaml +6 -0
- package/engines/specs/vam.yaml +17 -3
- package/engines/specs/weibo_hot.yaml +11 -1
- package/engines/specs/wolframalpha.yaml +3 -3
- package/engines/specs/xiaohongshu.yaml +2 -0
- package/engines/specs/zhihu.yaml +3 -18
- package/engines/specs/zhihu_kb.yaml +18 -0
- package/engines/specs/zhihu_questions.yaml +19 -0
- package/package.json +3 -2
- package/packages/dsh-plugin/README.md +9 -14
- package/packages/dsh-plugin/dsh/client.js +467 -1024
- package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
- package/packages/dsh-plugin/dsh/runner.js +2 -0
- package/packages/dsh-plugin/package.json +8 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
- package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
- package/packages/dsh-plugin/test/size-gate.test.js +2 -9
- package/scripts/adaptive.py +7 -1
- package/scripts/archive_run.py +112 -53
- package/scripts/argo_paths.py +40 -3
- package/scripts/badcase_ledger.py +108 -9
- package/scripts/build_concept_table.py +112 -55
- package/scripts/cache.py +5 -1
- package/scripts/caliber_isolation.py +60 -23
- package/scripts/circuit_breaker.py +56 -8
- package/scripts/cli_io.py +20 -2
- package/scripts/config_cache.py +31 -0
- package/scripts/daemon.py +146 -51
- package/scripts/dormant_ledger.py +23 -9
- package/scripts/engine_dispatch.py +3 -3
- package/scripts/engine_env.py +182 -1
- package/scripts/engine_families.py +50 -7
- package/scripts/engine_states.py +3 -50
- package/scripts/engine_validate.py +13 -45
- package/scripts/engines.py +15 -31
- package/scripts/engines_base.py +42 -58
- package/scripts/engines_builders.py +0 -15
- package/scripts/engines_builders_batch10.py +346 -100
- package/scripts/engines_builders_batch11.py +2 -75
- package/scripts/engines_builders_batch9.py +15 -24
- package/scripts/engines_builders_cn.py +0 -194
- package/scripts/engines_builders_feeds.py +55 -5
- package/scripts/engines_builders_intl.py +15 -115
- package/scripts/engines_builders_pixiv.py +2 -16
- package/scripts/engines_builders_search.py +7 -14
- package/scripts/engines_builders_tech.py +5 -14
- package/scripts/engines_builders_weather.py +236 -0
- package/scripts/engines_fields.py +91 -0
- package/scripts/engines_http.py +135 -0
- package/scripts/engines_mcp.py +383 -0
- package/scripts/engines_parsers.py +13 -369
- package/scripts/engines_schema_drift.py +260 -0
- package/scripts/evidence.py +13 -0
- package/scripts/evidence_loop.py +4 -3
- package/scripts/fetch_jsrun.py +15 -11
- package/scripts/fetch_v3.py +28 -28
- package/scripts/fulltext_store.py +42 -1
- package/scripts/fxtwitter_api.py +8 -7
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/general_pool.py +15 -4
- package/scripts/health_check.py +1 -1
- package/scripts/link_source.py +65 -24
- package/scripts/local_seek_adapter.py +57 -17
- package/scripts/mcp_handlers.py +53 -31
- package/scripts/mcp_handlers_surface.py +6 -18
- package/scripts/mcp_transport.py +1 -1
- package/scripts/min_version_scan.py +7 -3
- package/scripts/network_aware.py +7 -13
- package/scripts/pre-commit +45 -43
- package/scripts/query_understanding.py +30 -6
- package/scripts/quota.py +6 -1
- package/scripts/rank_signals.py +9 -0
- package/scripts/recompute.py +15 -5
- package/scripts/recovery.py +21 -15
- package/scripts/release.py +14 -26
- package/scripts/release_check.py +5 -25
- package/scripts/replay_eval.py +2 -2
- package/scripts/research_cli.py +40 -0
- package/scripts/research_notes.py +368 -0
- package/scripts/route.py +32 -70
- package/scripts/route_audit.py +259 -0
- package/scripts/route_combo.py +10 -4
- package/scripts/route_domains.py +150 -23
- package/scripts/route_lang.py +20 -7
- package/scripts/route_log.py +26 -9
- package/scripts/route_policy.py +85 -6
- package/scripts/route_telemetry_export.py +199 -0
- package/scripts/rrf_classic.py +5 -22
- package/scripts/search.py +2 -1
- package/scripts/search_attribution.py +33 -10
- package/scripts/search_entry.py +5 -1
- package/scripts/search_output.py +5 -4
- package/scripts/search_pipeline.py +12 -0
- package/scripts/search_rank.py +21 -11
- package/scripts/semantic_evidence.py +375 -168
- package/scripts/settings_page.py +3 -3
- package/scripts/social_engines/xiaohongshu_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +251 -43
- package/scripts/sogou_weixin_browser.py +5 -6
- package/scripts/source_audit.py +2 -2
- package/scripts/source_ledger.py +2 -15
- package/scripts/source_selection.py +45 -20
- package/scripts/straggler_policy.py +1 -2
- package/scripts/sync_backends.py +17 -0
- package/scripts/tfidf_router.py +23 -11
- package/scripts/time_utils.py +54 -1
- package/scripts/train.py +68 -2
- package/scripts/usage_log.py +26 -1
- package/sub-skills/argo-wide-research/SKILL.md +68 -0
- package/sub-skills/ego-search/SKILL.md +1 -1
- package/sub-skills/local-seek/scripts/seek_fts.py +58 -3
- package/scripts/caliber_dedupe.py +0 -66
- package/scripts/engines_builders_batch16.py +0 -13
- package/scripts/health_probe.py +0 -253
- package/scripts/social_engines/twitter_engine.py +0 -514
- package/scripts/sync_installs.py +0 -29
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""route_telemetry_export.py — 本地路由遥测脱敏导出飞轮(零原文/零隐私泄露)。
|
|
3
|
+
|
|
4
|
+
只从本机状态目录读取 `usage_log/route.jsonl`、`usage_log/query.jsonl` 与
|
|
5
|
+
`adaptive.db`,输出严格聚合的脱敏指标,用于离线诊断与回归设计,严禁包含:
|
|
6
|
+
- 原始查询文本(query / final_query)
|
|
7
|
+
- 本机绝对路径、用户名或环境变量值
|
|
8
|
+
- URL 凭据与特定实体标识
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
python3 scripts/route_telemetry_export.py
|
|
12
|
+
python3 scripts/route_telemetry_export.py --out tmp/telemetry_summary.json --min-samples 5
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import collections
|
|
19
|
+
import hashlib
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import sqlite3
|
|
23
|
+
import sys
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
SCRIPTS = Path(__file__).resolve().parent
|
|
28
|
+
if str(SCRIPTS) not in sys.path:
|
|
29
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
30
|
+
|
|
31
|
+
import argo_paths as _paths
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _iter_jsonl(path: Path) -> list[dict[str, Any]]:
|
|
35
|
+
if not path.is_file():
|
|
36
|
+
return []
|
|
37
|
+
rows: list[dict[str, Any]] = []
|
|
38
|
+
try:
|
|
39
|
+
for line in path.read_text(encoding="utf-8", errors="ignore").splitlines():
|
|
40
|
+
line = line.strip()
|
|
41
|
+
if not line:
|
|
42
|
+
continue
|
|
43
|
+
try:
|
|
44
|
+
obj = json.loads(line)
|
|
45
|
+
if isinstance(obj, dict):
|
|
46
|
+
rows.append(obj)
|
|
47
|
+
except json.JSONDecodeError:
|
|
48
|
+
continue
|
|
49
|
+
except OSError:
|
|
50
|
+
return []
|
|
51
|
+
return rows
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _adaptive_summary(db_path: Path, min_samples: int = 5) -> dict[str, Any]:
|
|
55
|
+
"""统计 adaptive.db 的空语言行占比与高空结果场景桶(无敏感文本)。"""
|
|
56
|
+
out = {
|
|
57
|
+
"total_rows": 0,
|
|
58
|
+
"empty_lang_rows": 0,
|
|
59
|
+
"high_empty_buckets": [],
|
|
60
|
+
}
|
|
61
|
+
if not db_path.is_file():
|
|
62
|
+
return out
|
|
63
|
+
conn: sqlite3.Connection | None = None
|
|
64
|
+
try:
|
|
65
|
+
conn = sqlite3.connect(str(db_path))
|
|
66
|
+
cols = {r[1] for r in conn.execute("PRAGMA table_info(engine_perf)").fetchall()}
|
|
67
|
+
if not cols:
|
|
68
|
+
return out
|
|
69
|
+
has_lang = "lang" in cols
|
|
70
|
+
has_domain = "domain" in cols
|
|
71
|
+
has_empty = "empty" in cols
|
|
72
|
+
total = conn.execute("SELECT COUNT(*) FROM engine_perf").fetchone()[0]
|
|
73
|
+
out["total_rows"] = int(total or 0)
|
|
74
|
+
if has_lang:
|
|
75
|
+
empty_lang = conn.execute(
|
|
76
|
+
"SELECT COUNT(*) FROM engine_perf WHERE lang = '' OR lang IS NULL"
|
|
77
|
+
).fetchone()[0]
|
|
78
|
+
out["empty_lang_rows"] = int(empty_lang or 0)
|
|
79
|
+
if has_domain and has_lang and has_empty:
|
|
80
|
+
rows = conn.execute(
|
|
81
|
+
"SELECT engine, domain, lang, COUNT(*) AS n, SUM(empty) AS emp "
|
|
82
|
+
"FROM engine_perf "
|
|
83
|
+
"GROUP BY engine, domain, lang "
|
|
84
|
+
"HAVING n >= ? "
|
|
85
|
+
"ORDER BY CAST(emp AS REAL) / n DESC, n DESC "
|
|
86
|
+
"LIMIT 20",
|
|
87
|
+
(max(1, int(min_samples)),),
|
|
88
|
+
).fetchall()
|
|
89
|
+
alerts = []
|
|
90
|
+
for eng, dom, lang, n, emp in rows:
|
|
91
|
+
emp_i = int(emp or 0)
|
|
92
|
+
rate = round(emp_i / max(n, 1), 3)
|
|
93
|
+
if rate >= 0.5:
|
|
94
|
+
alerts.append({
|
|
95
|
+
"engine": str(eng),
|
|
96
|
+
"domain": str(dom or "(none)"),
|
|
97
|
+
"effective_lang": str(lang or "(empty)"),
|
|
98
|
+
"samples": int(n),
|
|
99
|
+
"empty_count": emp_i,
|
|
100
|
+
"empty_rate": rate,
|
|
101
|
+
})
|
|
102
|
+
out["high_empty_buckets"] = alerts
|
|
103
|
+
except sqlite3.Error:
|
|
104
|
+
return out
|
|
105
|
+
finally:
|
|
106
|
+
if conn is not None:
|
|
107
|
+
conn.close()
|
|
108
|
+
return out
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def export_anonymized_telemetry(
|
|
112
|
+
state_dir: Path | str | None = None,
|
|
113
|
+
*,
|
|
114
|
+
min_samples: int = 5,
|
|
115
|
+
) -> dict[str, Any]:
|
|
116
|
+
"""导出严格脱敏的路由健康度与分桶统计报告(不含任何 query 或本机路径)。"""
|
|
117
|
+
root = Path(state_dir) if state_dir else _paths.state_root()
|
|
118
|
+
usage_override = os.environ.get("ARGO_USAGE_LOG_DIR", "").strip()
|
|
119
|
+
log_dir = Path(os.path.expanduser(usage_override)) if (usage_override and not state_dir) else (root / "usage_log")
|
|
120
|
+
|
|
121
|
+
route_rows = _iter_jsonl(log_dir / "route.jsonl")
|
|
122
|
+
query_rows = _iter_jsonl(log_dir / "query.jsonl")
|
|
123
|
+
|
|
124
|
+
lang_counts: collections.Counter[str] = collections.Counter()
|
|
125
|
+
domain_counts: collections.Counter[str] = collections.Counter()
|
|
126
|
+
intent_counts: collections.Counter[str] = collections.Counter()
|
|
127
|
+
skeleton_counts: collections.Counter[tuple[str, str, tuple[str, ...], str]] = collections.Counter()
|
|
128
|
+
fallback_count = 0
|
|
129
|
+
|
|
130
|
+
for row in route_rows:
|
|
131
|
+
dom = str(row.get("domain") or "general_search")
|
|
132
|
+
if dom in ("general_search", "fallback", ""):
|
|
133
|
+
fallback_count += 1
|
|
134
|
+
eff_lang = str(row.get("effective_lang") or row.get("lang_override") or row.get("primary_lang") or "unknown")
|
|
135
|
+
intents = tuple(sorted(str(x) for x in (row.get("intents") or []) if x))
|
|
136
|
+
eng = str(row.get("engine") or "unknown")
|
|
137
|
+
lang_counts[eff_lang] += 1
|
|
138
|
+
domain_counts[dom] += 1
|
|
139
|
+
for it in intents:
|
|
140
|
+
intent_counts[it] += 1
|
|
141
|
+
skeleton_counts[(dom, eff_lang, intents, eng)] += 1
|
|
142
|
+
|
|
143
|
+
total_route = len(route_rows)
|
|
144
|
+
zero_count_queries = sum(1 for r in query_rows if int(r.get("count") or 0) == 0)
|
|
145
|
+
|
|
146
|
+
skeletons = []
|
|
147
|
+
for (dom, lang, intents, eng), cnt in skeleton_counts.most_common(25):
|
|
148
|
+
sig_src = f"{dom}|{lang}|{','.join(intents)}|{eng}"
|
|
149
|
+
skel_id = hashlib.sha256(sig_src.encode("utf-8")).hexdigest()[:12]
|
|
150
|
+
skeletons.append({
|
|
151
|
+
"skeleton_id": skel_id,
|
|
152
|
+
"domain": dom,
|
|
153
|
+
"effective_lang": lang,
|
|
154
|
+
"intents": list(intents),
|
|
155
|
+
"engine": eng,
|
|
156
|
+
"count": cnt,
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
"schema_version": 1,
|
|
161
|
+
"privacy_guarantee": "aggregated_no_raw_query_no_paths",
|
|
162
|
+
"summary": {
|
|
163
|
+
"route_events": total_route,
|
|
164
|
+
"query_events": len(query_rows),
|
|
165
|
+
"query_zero_result_rate": round(zero_count_queries / len(query_rows), 3) if query_rows else 0.0,
|
|
166
|
+
"route_fallback_rate": round(fallback_count / total_route, 3) if total_route else 0.0,
|
|
167
|
+
"adaptive": _adaptive_summary(root / "adaptive.db", min_samples=min_samples),
|
|
168
|
+
},
|
|
169
|
+
"lang_distribution": dict(lang_counts.most_common()),
|
|
170
|
+
"domain_distribution": dict(domain_counts.most_common(20)),
|
|
171
|
+
"intent_distribution": dict(intent_counts.most_common()),
|
|
172
|
+
"anonymized_fingerprints": skeletons,
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def main() -> int:
|
|
177
|
+
parser = argparse.ArgumentParser(description="导出脱敏后的 Argo 路由遥测聚合报告")
|
|
178
|
+
parser.add_argument("--state-dir", default="", help="指定状态目录(默认自动发现)")
|
|
179
|
+
parser.add_argument("--min-samples", type=int, default=5, help="高空结果桶最小样本数")
|
|
180
|
+
parser.add_argument("--out", default="", help="可选输出 JSON 文件路径")
|
|
181
|
+
args = parser.parse_args()
|
|
182
|
+
|
|
183
|
+
payload = export_anonymized_telemetry(
|
|
184
|
+
args.state_dir or None,
|
|
185
|
+
min_samples=args.min_samples,
|
|
186
|
+
)
|
|
187
|
+
rendered = json.dumps(payload, ensure_ascii=False, indent=2)
|
|
188
|
+
if args.out:
|
|
189
|
+
out_path = Path(args.out)
|
|
190
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
191
|
+
out_path.write_text(rendered + "\n", encoding="utf-8")
|
|
192
|
+
print(f"已写入脱敏遥测摘要: {out_path}")
|
|
193
|
+
else:
|
|
194
|
+
print(rendered)
|
|
195
|
+
return 0
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if __name__ == "__main__":
|
|
199
|
+
raise SystemExit(main())
|
package/scripts/rrf_classic.py
CHANGED
|
@@ -10,6 +10,8 @@ from __future__ import annotations
|
|
|
10
10
|
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
|
+
from caliber_isolation import _dedupe_key, _merge_evidence
|
|
14
|
+
|
|
13
15
|
|
|
14
16
|
def rrf_classic(
|
|
15
17
|
ranked_lists: list[list[dict[str, Any]]],
|
|
@@ -28,35 +30,16 @@ def rrf_classic(
|
|
|
28
30
|
items: dict[str, dict[str, Any]] = {}
|
|
29
31
|
for _li, results in enumerate(ranked_lists):
|
|
30
32
|
for i, r in enumerate(results):
|
|
31
|
-
key = (
|
|
32
|
-
_canonical_url(r.get("url", ""))
|
|
33
|
-
or (f"__title__:{r.get('title', '')}" if r.get("title") else "")
|
|
34
|
-
or (f"__card__:{r.get('card_type', '')}" if r.get("card_type") else "")
|
|
35
|
-
or f"__idx__:{_li}:{i}"
|
|
36
|
-
)
|
|
33
|
+
key = _dedupe_key(r, _canonical_url, f"__idx__:{_li}:{i}")
|
|
37
34
|
scores[key] = scores.get(key, 0.0) + 1.0 / (k + i + 1)
|
|
38
35
|
eng = r.get("_engine") or r.get("source", "") or ""
|
|
39
36
|
if key not in items:
|
|
40
37
|
item = dict(r)
|
|
41
38
|
item["_rrf_score"] = 0.0
|
|
42
|
-
|
|
43
|
-
if eng:
|
|
44
|
-
cons.append(eng)
|
|
45
|
-
item["consensus_engines"] = cons
|
|
39
|
+
item["consensus_engines"] = [eng] if eng else []
|
|
46
40
|
items[key] = item
|
|
47
41
|
else:
|
|
48
|
-
|
|
49
|
-
new_txt = f"{r.get('title', '')} {r.get('snippet', '')}"
|
|
50
|
-
cur_txt = f"{cur.get('title', '')} {cur.get('snippet', '')}"
|
|
51
|
-
if len(new_txt) > len(cur_txt):
|
|
52
|
-
cur["title"] = r.get("title", cur.get("title"))
|
|
53
|
-
cur["snippet"] = r.get("snippet", cur.get("snippet"))
|
|
54
|
-
sources = {cur.get("source", ""), r.get("source", "")}
|
|
55
|
-
cur["source"] = "/".join(s for s in sources if s)
|
|
56
|
-
cons = list(cur.get("consensus_engines") or [])
|
|
57
|
-
if eng and eng not in cons:
|
|
58
|
-
cons.append(eng)
|
|
59
|
-
cur["consensus_engines"] = cons
|
|
42
|
+
_merge_evidence(items[key], r, extra_eng=eng)
|
|
60
43
|
ranked = sorted(scores.items(), key=lambda x: -x[1])
|
|
61
44
|
out = []
|
|
62
45
|
for key, _ in ranked:
|
package/scripts/search.py
CHANGED
|
@@ -932,7 +932,8 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
|
|
|
932
932
|
return _run_local_seek(q, max_n, search_dir, echo=not quiet)
|
|
933
933
|
|
|
934
934
|
result = shape_response(_ShapeContext(
|
|
935
|
-
|
|
935
|
+
# envelope 与 result["query"](:823)同口径:候选交接包不收 site:/-词 操作符原串
|
|
936
|
+
query=original_query, kind=kind, tier=tier, envelope=envelope, decision=decision,
|
|
936
937
|
extra_lim=extra_lim, cache=cache, include_domains=include_domains,
|
|
937
938
|
exclude_domains=exclude_domains, include_local=include_local, n=n,
|
|
938
939
|
run_local_seek=_local_seek_wrapper,
|
|
@@ -49,24 +49,28 @@ def usage_log_attribution(engine_latency: dict[str, Any] | None,
|
|
|
49
49
|
top_n: int = DEFAULT_TOP_N,
|
|
50
50
|
engine_outcomes: Iterable[dict[str, Any]] | None = None
|
|
51
51
|
) -> dict[str, Any]:
|
|
52
|
-
"""usage_log query 流的归因字段(慢源 Top-N + 各引擎交付条数 +
|
|
52
|
+
"""usage_log query 流的归因字段(慢源 Top-N + 各引擎交付条数 + 失败归类)。
|
|
53
53
|
|
|
54
54
|
返回 dict 以便调用方 **展开进日志记录**,未来新增归因维度(如
|
|
55
55
|
「等待预算被谁耗掉」「缓存未命中的原因分布」)时只扩这里,
|
|
56
56
|
主管线那一行 `**usage_log_attribution(...)` 不动——归因是会长大的,
|
|
57
57
|
写入点不该跟着长(主管线有模块大小门禁,见模块 docstring)。
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
失败类别只记「哪类」不记条数,``engine_errors`` 补齐「哪家引擎因何失败」。
|
|
60
60
|
"""
|
|
61
|
+
outcomes = list(engine_outcomes) if engine_outcomes is not None else None
|
|
61
62
|
out: dict[str, Any] = {
|
|
62
63
|
"engine_latency_top": top_engine_latency(engine_latency, top_n),
|
|
63
64
|
}
|
|
64
|
-
counts = engine_result_counts(
|
|
65
|
+
counts = engine_result_counts(outcomes)
|
|
65
66
|
if counts:
|
|
66
67
|
out["engine_results"] = counts
|
|
67
|
-
kinds = failure_kinds(
|
|
68
|
+
kinds = failure_kinds(outcomes)
|
|
68
69
|
if kinds:
|
|
69
70
|
out["failure_kinds"] = kinds
|
|
71
|
+
errs = engine_errors(outcomes)
|
|
72
|
+
if errs:
|
|
73
|
+
out["engine_errors"] = errs
|
|
70
74
|
return out
|
|
71
75
|
|
|
72
76
|
|
|
@@ -166,6 +170,16 @@ def engine_result_counts(engine_outcomes: Iterable[dict[str, Any]] | None,
|
|
|
166
170
|
return out
|
|
167
171
|
|
|
168
172
|
|
|
173
|
+
def _failure_rows(engine_outcomes: Iterable[dict[str, Any]] | None,
|
|
174
|
+
limit: int = 8) -> list[dict[str, Any]]:
|
|
175
|
+
try:
|
|
176
|
+
from output_transparency import build_failures
|
|
177
|
+
except ImportError: # pragma: no cover - 单文件分发时的降级
|
|
178
|
+
return []
|
|
179
|
+
return build_failures({"engine_outcomes": list(engine_outcomes or [])},
|
|
180
|
+
limit=limit)
|
|
181
|
+
|
|
182
|
+
|
|
169
183
|
def failure_kinds(engine_outcomes: Iterable[dict[str, Any]] | None,
|
|
170
184
|
limit: int = 6) -> list[str]:
|
|
171
185
|
"""本次调用的失败类别(去重、稳定排序),写进 usage_log 供长期归因。
|
|
@@ -174,15 +188,24 @@ def failure_kinds(engine_outcomes: Iterable[dict[str, Any]] | None,
|
|
|
174
188
|
output_transparency.build_failures(与 agent 档 failures 同一口径),
|
|
175
189
|
不在日志侧另写一份分类。
|
|
176
190
|
"""
|
|
177
|
-
|
|
178
|
-
from output_transparency import build_failures
|
|
179
|
-
except ImportError: # pragma: no cover - 单文件分发时的降级
|
|
180
|
-
return []
|
|
181
|
-
rows = build_failures({"engine_outcomes": list(engine_outcomes or [])},
|
|
182
|
-
limit=limit)
|
|
191
|
+
rows = _failure_rows(engine_outcomes, limit=limit)
|
|
183
192
|
return sorted({str(r.get("category") or "unknown") for r in rows})
|
|
184
193
|
|
|
185
194
|
|
|
195
|
+
def engine_errors(engine_outcomes: Iterable[dict[str, Any]] | None,
|
|
196
|
+
limit: int = 8) -> dict[str, str]:
|
|
197
|
+
"""按引擎提取失败归因映射 ``{engine: "category: detail"}``,供坏例账本定责。"""
|
|
198
|
+
out: dict[str, str] = {}
|
|
199
|
+
for r in _failure_rows(engine_outcomes, limit=limit):
|
|
200
|
+
eng = str(r.get("engine") or "").strip()
|
|
201
|
+
if not eng or eng in out:
|
|
202
|
+
continue
|
|
203
|
+
cat = str(r.get("category") or "unknown").strip()
|
|
204
|
+
detail = str(r.get("detail") or "").strip()
|
|
205
|
+
out[eng] = f"{cat}: {detail[:80]}" if detail else cat
|
|
206
|
+
return out
|
|
207
|
+
|
|
208
|
+
|
|
186
209
|
def aggregate_slow_engines(rows: Iterable[dict[str, Any]],
|
|
187
210
|
top_n: int = 5) -> list[dict[str, Any]]:
|
|
188
211
|
"""聚合多行日志的 engine_latency_top → 按累计耗时的慢源排行。
|
package/scripts/search_entry.py
CHANGED
|
@@ -164,7 +164,11 @@ def prepare(query: str, decision: dict[str, Any], max_results: int,
|
|
|
164
164
|
# 用归一化 ISO(7d 与等价绝对日期共享缓存;相对窗跨天自然过期不串旧数据)。
|
|
165
165
|
# 仅当组合内含带时间能力引擎时隔离:无时间字段引擎忽略时间窗、结果相同,
|
|
166
166
|
# 隔离只会降低命中率(7d/30d 查 octen/anysearch 命中同一缓存)。
|
|
167
|
-
time_aware
|
|
167
|
+
# 无时间窗时整段短路:`time_aware` 只被下面两行与后过滤读取,而两者
|
|
168
|
+
# 都以 since/until 非空为前提,此时无论如何取值都不影响结果。旧写法
|
|
169
|
+
# 无条件求值,让默认路径白付一次 307 份 spec 的全量解析。
|
|
170
|
+
time_aware = (bool(since_iso or until_iso)
|
|
171
|
+
and any(_is_time_capable(e) for e in engines))
|
|
168
172
|
if since_iso and time_aware:
|
|
169
173
|
cache_engine_key += f"|since={since_iso}"
|
|
170
174
|
if until_iso and time_aware:
|
package/scripts/search_output.py
CHANGED
|
@@ -12,6 +12,7 @@ from search_rank import filter_results_by_domains
|
|
|
12
12
|
from search_types import slot_record as dataclass
|
|
13
13
|
from snippet_clean import clean_snippet
|
|
14
14
|
import engine_states # 状态词表唯一真源(2026-11-09 收口)
|
|
15
|
+
from except_sets import OPT_IMPORT, SHAPE_BENIGN # 收窄词汇表(2026-11-13 裸吞收口)
|
|
15
16
|
from typing import Any
|
|
16
17
|
from output_transparency import ( # noqa: F401
|
|
17
18
|
_AGGREGATOR_HOSTS,
|
|
@@ -712,7 +713,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
|
|
|
712
713
|
result.setdefault("limitations", []).append(
|
|
713
714
|
f"证据门控本次跳过({type(e).__name__}):fetch_required/"
|
|
714
715
|
"evidence_loop 不可用,高后果域结论请自行核验")
|
|
715
|
-
except
|
|
716
|
+
except SHAPE_BENIGN:
|
|
716
717
|
pass
|
|
717
718
|
|
|
718
719
|
# 上游权威等级回填(DeepSeek 0-4):单引擎/对冲路径不走五维精排,
|
|
@@ -768,7 +769,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
|
|
|
768
769
|
from local_seek import local_seek_last_skipped
|
|
769
770
|
if local_seek_last_skipped():
|
|
770
771
|
result["local_seek_skipped"] = True
|
|
771
|
-
except
|
|
772
|
+
except OPT_IMPORT + SHAPE_BENIGN:
|
|
772
773
|
pass
|
|
773
774
|
if local_hits:
|
|
774
775
|
_seen_urls = {r.get("url") for r in (result.get("results") or [])
|
|
@@ -848,7 +849,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
|
|
|
848
849
|
sanitize_results_boundary)
|
|
849
850
|
sanitize_results_boundary(result.get("results"))
|
|
850
851
|
result["content_trust"] = CONTENT_TRUST_UNTRUSTED
|
|
851
|
-
except
|
|
852
|
+
except OPT_IMPORT + SHAPE_BENIGN:
|
|
852
853
|
pass
|
|
853
854
|
# 搜索期告警(issue #34 第 7 条):--json 下告警不能留在 stderr(调用方
|
|
854
855
|
# 2>&1 合并会破坏 JSON 解析),统一收进响应的 warnings[] 字段。住在
|
|
@@ -858,6 +859,6 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
|
|
|
858
859
|
warns = [w.strip() for w in drain_search_warnings() if w.strip()]
|
|
859
860
|
if warns:
|
|
860
861
|
result.setdefault("warnings", []).extend(warns)
|
|
861
|
-
except
|
|
862
|
+
except OPT_IMPORT + SHAPE_BENIGN:
|
|
862
863
|
pass
|
|
863
864
|
return result
|
|
@@ -79,6 +79,7 @@ import engine_states
|
|
|
79
79
|
from stage_timing import tick as _tick, tock as _tock
|
|
80
80
|
from time_utils import apply_time_window as _apply_time_window
|
|
81
81
|
from time_utils import sort_results_by_time as _sort_results
|
|
82
|
+
from time_utils import weather_chronological
|
|
82
83
|
|
|
83
84
|
|
|
84
85
|
@dataclass(frozen=True)
|
|
@@ -641,6 +642,17 @@ def postprocess(req: _SearchRequest, run: _SearchRun, hooks: Any) -> _SearchRun:
|
|
|
641
642
|
|
|
642
643
|
if merged:
|
|
643
644
|
merged = _apply_consensus_and_sort(merged, max_results)
|
|
645
|
+
# 天气结果按时间序收口:当前天气在前,逐日预报升序。放在最终截断
|
|
646
|
+
# 之后,避免五维 rerank 的新颖性把最远一天顶到最前(见函数 docstring)。
|
|
647
|
+
# 显式 `--engine open_meteo` 时 domain 会被置成 general,所以判据同时
|
|
648
|
+
# 看域、引擎列表与结果来源,不能只认 domain。
|
|
649
|
+
_weather_scope = (
|
|
650
|
+
domain == "weather_query"
|
|
651
|
+
or "open_meteo" in (engines or [])
|
|
652
|
+
or (bool(merged) and all(r.get("source") == "open_meteo" for r in merged))
|
|
653
|
+
)
|
|
654
|
+
if _weather_scope:
|
|
655
|
+
merged = weather_chronological(merged)
|
|
644
656
|
|
|
645
657
|
_attach_selection_signals(merged, mode, depth)
|
|
646
658
|
|
package/scripts/search_rank.py
CHANGED
|
@@ -28,6 +28,7 @@ import engine_states # 状态词表唯一真源(2026-11-09 收口)
|
|
|
28
28
|
|
|
29
29
|
from engine_env import env_flag, get_env
|
|
30
30
|
from url_canon import canonical_url as _canonical_url_impl
|
|
31
|
+
from except_sets import IO_BENIGN, SHAPE_BENIGN # 收窄词汇表(2026-11-13 裸吞收口)
|
|
31
32
|
|
|
32
33
|
# cache 延迟到首次真正需要相似度时再导入(2026-09-27,方案 B3):顶层 import
|
|
33
34
|
# 会把 cache.py 连带 sqlite3/shutil/tempfile 整条拉进每次 import search 的
|
|
@@ -72,6 +73,7 @@ from rank_signals import ( # noqa: E402,F401
|
|
|
72
73
|
score_completeness as _score_completeness,
|
|
73
74
|
score_relevance as _score_relevance,
|
|
74
75
|
title_stuffing_penalty as _title_stuffing_penalty,
|
|
76
|
+
upstream_score_boost as _upstream_score_boost,
|
|
75
77
|
)
|
|
76
78
|
|
|
77
79
|
# 中文/英文混合分词用的正则,延迟编译(首次 _tokens 时建)
|
|
@@ -281,8 +283,12 @@ def _content_similarity(a: str, b: str) -> float:
|
|
|
281
283
|
if _sim_fn is not None:
|
|
282
284
|
try:
|
|
283
285
|
return float(_sim_fn(a, b))
|
|
284
|
-
except Exception:
|
|
285
|
-
|
|
286
|
+
except Exception as e:
|
|
287
|
+
# 单条相似度计算失败按「无相似度」处理,回退 Jaccard;相似度查
|
|
288
|
+
# cache 的 sqlite(OperationalError 不在词汇表),保持宽口径仅可见化。
|
|
289
|
+
import logging
|
|
290
|
+
logging.getLogger("unified_search").debug(
|
|
291
|
+
f"query 相似度计算跳过: {type(e).__name__}")
|
|
286
292
|
import re as _re
|
|
287
293
|
sa, sb = set(_re.findall(r"[\u4e00-\u9fff]|[a-zA-Z0-9]+", a.lower())), set(_re.findall(r"[\u4e00-\u9fff]|[a-zA-Z0-9]+", b.lower()))
|
|
288
294
|
if not sa or not sb:
|
|
@@ -339,7 +345,7 @@ def minhash_dedupe(
|
|
|
339
345
|
try:
|
|
340
346
|
thr = float(os.environ.get("ARGO_MINHASH_THRESHOLD", str(threshold)))
|
|
341
347
|
threshold = max(0.5, min(0.98, thr))
|
|
342
|
-
except
|
|
348
|
+
except SHAPE_BENIGN:
|
|
343
349
|
pass
|
|
344
350
|
pool = sorted(
|
|
345
351
|
results,
|
|
@@ -470,7 +476,7 @@ def _note_rerank_failure(breaker, category: str, detail: str) -> None:
|
|
|
470
476
|
attribution={"category": category,
|
|
471
477
|
"reason": "语义精排端点不可用", "detail": detail},
|
|
472
478
|
)
|
|
473
|
-
except
|
|
479
|
+
except IO_BENIGN + SHAPE_BENIGN:
|
|
474
480
|
pass
|
|
475
481
|
|
|
476
482
|
def rerank_results(query: str, results: list[dict[str, Any]],
|
|
@@ -498,8 +504,13 @@ def rerank_results(query: str, results: list[dict[str, Any]],
|
|
|
498
504
|
from quota import get_quota_manager
|
|
499
505
|
if get_quota_manager().is_remote_exhausted("bocha"):
|
|
500
506
|
return results, engine_states.RERANK_SKIPPED_QUOTA
|
|
501
|
-
except Exception:
|
|
502
|
-
|
|
507
|
+
except Exception as e:
|
|
508
|
+
# quota 联动是侧信道:fail-open 是被测契约(test_quota_gate_fails_open
|
|
509
|
+
# _when_quota_unavailable 用 RuntimeError 桩验证),不收窄——except_sets
|
|
510
|
+
# 判定规则看 try 块失败的代价,quota 层可抛任意异常。
|
|
511
|
+
import logging
|
|
512
|
+
logging.getLogger("unified_search").debug(
|
|
513
|
+
f"quota 联动检查跳过(fail-open): {type(e).__name__}")
|
|
503
514
|
|
|
504
515
|
# 端点熔断:先问「还该不该打这一枪」。
|
|
505
516
|
#
|
|
@@ -546,7 +557,7 @@ def rerank_results(query: str, results: list[dict[str, Any]],
|
|
|
546
557
|
if breaker is not None:
|
|
547
558
|
try:
|
|
548
559
|
breaker.record_success(_RERANK_BREAKER_KEY)
|
|
549
|
-
except
|
|
560
|
+
except IO_BENIGN + SHAPE_BENIGN:
|
|
550
561
|
pass
|
|
551
562
|
rerank_results_list = data.get("data", {}).get("results", [])
|
|
552
563
|
if not rerank_results_list:
|
|
@@ -758,10 +769,9 @@ def local_five_dim_rerank(query: str, results: list[dict[str, Any]],
|
|
|
758
769
|
# prior——浮点加法顺序与改造前一致,金标对拍才可能零差异。
|
|
759
770
|
pool = enriched[:]
|
|
760
771
|
for e in pool:
|
|
761
|
-
e["_static4"] = (w["relevance"] * e["relevance"]
|
|
762
|
-
+ w["
|
|
763
|
-
+
|
|
764
|
-
+ w["completeness"] * e["completeness"])
|
|
772
|
+
e["_static4"] = (w["relevance"] * e["relevance"] + w["authority"] * e["authority"]
|
|
773
|
+
+ w["freshness"] * e["freshness"] + w["completeness"] * e["completeness"]
|
|
774
|
+
+ _upstream_score_boost(e["r"]))
|
|
765
775
|
# 来源侧惩罚(域级集中 / 跨域同质)作为静态分乘子(≤1)在**贪心之前**
|
|
766
776
|
# 应用:① 无需事后重排,且惩罚表为空时本行是 ×1.0、浮点上逐位无操作,
|
|
767
777
|
# 「无惩罚时与旧实现逐位一致」的不变式不被破坏;② K 剪枝上界
|