argo-search 2.10.1 → 2.11.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 +48 -11
- package/README.es.md +48 -11
- package/README.ja.md +48 -11
- package/README.ko.md +47 -10
- package/README.md +48 -31
- package/SKILL.md +16 -15
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +18 -6
- package/backends/engine_concept_vectors.json +3104 -0
- package/backends/engine_registry.yaml +38 -13
- package/backends/quota_profiles.json +30 -10
- package/bin/argo +6 -0
- package/config.yaml +98 -31
- package/docs/ENGINE_CATALOG.md +11 -8
- package/docs/RELEASE_NOTES_v2.10.2.md +48 -0
- package/docs/RELEASE_NOTES_v2.11.2.md +50 -0
- package/engines/specs/animetrace.yaml +35 -0
- package/engines/specs/google_lens.yaml +50 -0
- package/engines/specs/saucenao.yaml +45 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/dsh/diagnostics.js +8 -3
- package/packages/dsh-plugin/dsh/index.js +12 -7
- package/packages/dsh-plugin/dsh/runner.js +79 -47
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/index.test.js +64 -0
- package/scripts/argo_engine_registry.py +30 -4
- package/scripts/argo_paths.py +7 -1
- package/scripts/budget.py +13 -3
- 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/circuit_breaker.py +25 -3
- package/scripts/concept_lookup.py +212 -0
- package/scripts/engine_dispatch.py +2 -1
- package/scripts/engine_families.py +7 -3
- package/scripts/engines.py +34 -9
- package/scripts/engines_base.py +17 -2
- package/scripts/engines_builders.py +0 -1
- package/scripts/engines_builders_intl.py +4 -4
- package/scripts/engines_builders_reverse_image.py +783 -0
- package/scripts/engines_builders_skill.py +87 -10
- package/scripts/engines_builders_tech.py +0 -78
- package/scripts/extend_route_labels.py +239 -0
- package/scripts/extend_route_labels_by_capability.py +344 -0
- package/scripts/extend_route_labels_by_language.py +306 -0
- package/scripts/gen_routing_snapshot.py +22 -3
- package/scripts/job.py +2 -1
- package/scripts/lang_detect.py +12 -3
- package/scripts/lint_spec_contracts.py +110 -0
- package/scripts/lint_stub_targets.py +130 -0
- package/scripts/local_image.py +3 -3
- package/scripts/local_seek.py +13 -3
- package/scripts/mcp_compact.py +5 -0
- package/scripts/mcp_transport.py +1 -1
- package/scripts/net_proxy.py +47 -0
- package/scripts/numeric_verify.py +330 -0
- package/scripts/plan.py +36 -4
- package/scripts/pre-commit +21 -13
- package/scripts/quota.py +109 -10
- package/scripts/rank_signals.py +48 -4
- package/scripts/ranking_eval.py +23 -1
- package/scripts/regression_p0p1.py +7 -2
- 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 +242 -5
- package/scripts/route_primary.py +101 -0
- package/scripts/search.py +14 -12
- package/scripts/search_cli.py +89 -7
- package/scripts/search_output.py +59 -1
- package/scripts/search_pipeline.py +20 -15
- package/scripts/snippet_clean.py +60 -0
- package/scripts/social_engines/twitter_engine.py +159 -42
- package/scripts/social_engines/xiaohongshu_engine.py +36 -1
- package/scripts/tfidf_router.py +52 -2
- package/scripts/train.py +15 -0
- package/scripts/verify_with.py +124 -0
- 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 +152 -36
- package/sub-skills/local-seek/scripts/seek_rank.py +191 -11
|
@@ -52,6 +52,8 @@ import time
|
|
|
52
52
|
from datetime import datetime
|
|
53
53
|
from pathlib import Path
|
|
54
54
|
|
|
55
|
+
from seek_rank import _ZH_EN_ALIASES # 中英工程词对齐(词源单点在 seek_rank)
|
|
56
|
+
|
|
55
57
|
CONFIG_DIR = Path(__file__).resolve().parent.parent / "config"
|
|
56
58
|
DOMAINS_FILE = CONFIG_DIR / "domains.yaml"
|
|
57
59
|
|
|
@@ -77,8 +79,9 @@ DEFAULT_EXCLUDES = [
|
|
|
77
79
|
# 「明明有却搜不到」这种更糟的失败模式。
|
|
78
80
|
NOISE_TIER = [
|
|
79
81
|
"repos", "repo", "third_party", "thirdparty", "vendors",
|
|
80
|
-
"__tests__", "__test__", "
|
|
81
|
-
"
|
|
82
|
+
"__tests__", "__test__", "tests", "test", "testdata", "test_data",
|
|
83
|
+
"fixtures", "fixture", "__mocks__", "__snapshots__", "e2e",
|
|
84
|
+
"benchmark", "benchmarks",
|
|
82
85
|
"tmp", "temp", ".tmp", "tmpdir", "archive", "archives", ".trash",
|
|
83
86
|
"2026-*", # 本工作区的日期归档目录:研究产物,非源码
|
|
84
87
|
]
|
|
@@ -311,7 +314,7 @@ _ENV_FALSY = ("0", "off", "no", "false", "disable", "disabled")
|
|
|
311
314
|
|
|
312
315
|
# 重排开启时的池子上限:评分几百行在毫秒级(seek_rank 单遍计数),而浅池
|
|
313
316
|
# 会让「每文件只轮到 1 行」、文件内最相关的深行进不了评分视野。
|
|
314
|
-
_POOL_CAP_MAX =
|
|
317
|
+
_POOL_CAP_MAX = 800
|
|
315
318
|
|
|
316
319
|
|
|
317
320
|
def _rerank_wanted(raw_query: str, context: int, count: bool,
|
|
@@ -354,35 +357,114 @@ def _rerank_content(rows, raw_query: str, context: int, count: bool,
|
|
|
354
357
|
return rows
|
|
355
358
|
|
|
356
359
|
|
|
357
|
-
|
|
358
|
-
"""
|
|
360
|
+
_POOL_ZH_EN: dict[str, str] = {
|
|
361
|
+
"\u672c\u5730": "local", "\u641c\u7d22": "search", "\u68c0\u7d22": "seek", "\u7f13\u5b58": "cache",
|
|
362
|
+
"\u8def\u7531": "route", "\u6392\u5e8f": "rank", "\u91cd\u6392": "rerank", "\u566a\u58f0": "noise",
|
|
363
|
+
"\u62fc\u97f3": "pinyin", "\u8bc1\u636e": "evidence", "\u6293\u53d6": "fetch", "\u7194\u65ad": "breaker",
|
|
364
|
+
"\u805a\u5408": "search_engines", "\u5e76\u53d1": "concurrency", "\u9650\u6d41": "ratelimit",
|
|
365
|
+
"\u8d85\u65f6": "timeout", "\u91cd\u8bd5": "retry", "\u5f02\u6b65": "async", "\u961f\u5217": "queue",
|
|
366
|
+
"\u7d22\u5f15": "index", "\u5411\u91cf": "vector", "\u6743\u91cd": "weight", "\u9608\u503c": "threshold",
|
|
367
|
+
"\u5ef6\u8fdf": "latency", "\u541e\u5410": "throughput", "\u6743\u9650": "permission", "\u8ba4\u8bc1": "auth",
|
|
368
|
+
"\u52a0\u5bc6": "crypto", "\u89e3\u6790": "parse", "\u5e8f\u5217": "serialize", "\u8fdb\u7a0b": "process",
|
|
369
|
+
"\u7ebf\u7a0b": "thread", "\u9501": "lock", "\u8c03\u5ea6": "dispatch", "\u964d\u7ea7": "fallback",
|
|
370
|
+
"\u6062\u590d": "recovery", "\u53bb\u91cd": "dedup", "\u65f6\u6548": "freshness", "\u6743\u5a01": "authority",
|
|
371
|
+
"\u914d\u989d": "quota", "\u95e8\u7981": "gate", "\u6570\u636e": "data", "\u5b9a\u65f6": "schedule",
|
|
372
|
+
"\u7b56\u7565": "policy", "\u6307\u6807": "metrics", "\u7ec8\u7aef": "cli", "\u63a5\u53e3": "api",
|
|
373
|
+
"\u6e32\u67d3": "render", "\u89c6\u9891": "video", "\u5b57\u5e55": "subtitle", "\u7ec4\u4ef6": "component",
|
|
374
|
+
"\u5185\u5b58": "memory", "\u65e5\u5fd7": "log", "\u90e8\u7f72": "deploy", "\u7f51\u7edc": "network",
|
|
375
|
+
"\u4ee3\u7406": "proxy", "\u6570\u636e\u5e93": "db",
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
_DEF_LINE_RE = re.compile(
|
|
379
|
+
r"^\s*(?:(?:async|pub|export|public|private|protected|static|inline|const)\s+)*"
|
|
380
|
+
r"(?:def|class|fn|func|struct|interface|enum|type|trait|mod)\s+[A-Za-z_]"
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _line_buf_key(item: tuple[int, str]) -> tuple[int, int, str]:
|
|
385
|
+
ln, txt = item
|
|
386
|
+
if _DEF_LINE_RE.match(txt):
|
|
387
|
+
pri = 0
|
|
388
|
+
elif txt.lstrip().startswith(("#", "//", "/*", "*")):
|
|
389
|
+
pri = 2
|
|
390
|
+
else:
|
|
391
|
+
pri = 1
|
|
392
|
+
return pri, ln, txt
|
|
393
|
+
|
|
359
394
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
395
|
+
def _select_pool(candidates, cap: int, per_file: int = 8,
|
|
396
|
+
raw_query: str = "") -> list:
|
|
397
|
+
"""有界池的**按文件轮转配额 + 词覆盖度优先**选择(2026-10-07 方案甲,2026-10-30 升级)。
|
|
363
398
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
「单文件超 per_file 行的深处行」可能落选——对行粒度输出这是可接受的
|
|
368
|
-
取舍,深层行本就该用 --context / --outline 精读。
|
|
399
|
+
流式阶段按文件收集候选(单文件有界缓冲 32 行,零字符串转换开销);
|
|
400
|
+
仅当总候选超 cap 或单文件超 per_file 时,按「行内词元覆盖数 + 路径互补词元数」
|
|
401
|
+
精选每文件代表行并按文件覆盖度轮转入池。
|
|
369
402
|
"""
|
|
370
|
-
|
|
403
|
+
raw_by_file: dict[str, list[tuple[int, str]]] = {}
|
|
404
|
+
buf_limit = max(per_file * 4, 32)
|
|
405
|
+
total_cands = 0
|
|
371
406
|
for fp, ln, txt in candidates:
|
|
372
|
-
|
|
373
|
-
|
|
407
|
+
total_cands += 1
|
|
408
|
+
rows = raw_by_file.setdefault(fp, [])
|
|
409
|
+
if len(rows) < buf_limit:
|
|
374
410
|
rows.append((ln, txt))
|
|
375
|
-
elif
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
411
|
+
elif buf_limit > 1:
|
|
412
|
+
worst = max(rows, key=_line_buf_key)
|
|
413
|
+
if _line_buf_key((ln, txt)) < _line_buf_key(worst):
|
|
414
|
+
rows[rows.index(worst)] = (ln, txt)
|
|
415
|
+
|
|
416
|
+
if not raw_by_file:
|
|
417
|
+
return []
|
|
418
|
+
|
|
419
|
+
# 快路:总候选未超池上限且每文件均未超配额时,直接按基准序返回(零分词开销)
|
|
420
|
+
if total_cands <= cap and all(len(v) <= per_file for v in raw_by_file.values()):
|
|
421
|
+
return [(fp, ln, txt) for fp in sorted(raw_by_file) for ln, txt in sorted(raw_by_file[fp])]
|
|
422
|
+
|
|
423
|
+
q_terms: list[str] = []
|
|
424
|
+
if raw_query:
|
|
425
|
+
pats, _ = build_patterns(raw_query, exact=False)
|
|
426
|
+
for p in pats:
|
|
427
|
+
pl = p.lower()
|
|
428
|
+
if len(pl) >= 2 and pl not in q_terms:
|
|
429
|
+
q_terms.append(pl)
|
|
430
|
+
en = _POOL_ZH_EN.get(pl)
|
|
431
|
+
if en and en not in q_terms:
|
|
432
|
+
q_terms.append(en)
|
|
433
|
+
q_terms = q_terms[:8]
|
|
434
|
+
|
|
435
|
+
by_file: dict[str, list[tuple[int, str]]] = {}
|
|
436
|
+
file_cov: dict[str, int] = {}
|
|
437
|
+
for fp, rows in raw_by_file.items():
|
|
438
|
+
if not q_terms:
|
|
439
|
+
rows.sort()
|
|
440
|
+
by_file[fp] = rows[:per_file]
|
|
441
|
+
file_cov[fp] = 0
|
|
442
|
+
continue
|
|
443
|
+
fp_low = fp.lower()
|
|
444
|
+
p_mask = 0
|
|
445
|
+
for idx, qt in enumerate(q_terms):
|
|
446
|
+
if qt in fp_low:
|
|
447
|
+
p_mask |= 1 << idx
|
|
448
|
+
f_mask = p_mask
|
|
449
|
+
scored: list[tuple[int, int, int, str]] = []
|
|
450
|
+
for ln, txt in rows:
|
|
451
|
+
txt_low = (txt or "").lower()
|
|
452
|
+
l_mask = 0
|
|
453
|
+
for idx, qt in enumerate(q_terms):
|
|
454
|
+
if qt in txt_low:
|
|
455
|
+
l_mask |= 1 << idx
|
|
456
|
+
f_mask |= l_mask
|
|
457
|
+
scored.append((-(p_mask | l_mask).bit_count(), -(l_mask & ~p_mask).bit_count(), ln, txt))
|
|
458
|
+
scored.sort()
|
|
459
|
+
by_file[fp] = [(ln, txt) for _, _, ln, txt in scored[:per_file]]
|
|
460
|
+
file_cov[fp] = f_mask.bit_count()
|
|
461
|
+
|
|
462
|
+
ordered_files = sorted(by_file, key=lambda fp: (-file_cov[fp], fp))
|
|
380
463
|
out: list = []
|
|
381
|
-
# 文件按路径序轮转,各出 1 行填池——池内文件多样性优先于单文件深度
|
|
382
464
|
consumed: dict[str, int] = {fp: 0 for fp in by_file}
|
|
383
465
|
while len(out) < cap:
|
|
384
466
|
progressed = False
|
|
385
|
-
for fp in
|
|
467
|
+
for fp in ordered_files:
|
|
386
468
|
i = consumed[fp]
|
|
387
469
|
if i < len(by_file[fp]):
|
|
388
470
|
ln, txt = by_file[fp][i]
|
|
@@ -404,9 +486,10 @@ def _finish_content(candidates, raw_query, context, count, fixed,
|
|
|
404
486
|
排序口径,输出 schema 才能逐位一致。
|
|
405
487
|
"""
|
|
406
488
|
cap = max(max_results, min(max_results * 4, 400))
|
|
407
|
-
|
|
489
|
+
want_rerank = _rerank_wanted(raw_query, context, count, fixed)
|
|
490
|
+
if want_rerank:
|
|
408
491
|
cap = max(cap, _POOL_CAP_MAX) # 重排开启:池子放宽,深行进得了评分视野
|
|
409
|
-
out = _select_pool(candidates, cap)
|
|
492
|
+
out = _select_pool(candidates, cap, raw_query=raw_query if want_rerank else "")
|
|
410
493
|
out.sort() # 基准序 = (路径,行号,内容):重排关闭时与 2026-10-06 口径逐位一致
|
|
411
494
|
# BM25F 相关度重排(2026-10-07,方案甲):池子的**选择**口径不变(与发射序
|
|
412
495
|
# 无关),变的只是池内**呈现次序**——基线实测多词查询的 top5 常被配置/
|
|
@@ -421,7 +504,7 @@ def _finish_content(candidates, raw_query, context, count, fixed,
|
|
|
421
504
|
|
|
422
505
|
def rg_search(patterns, path, excludes, exts, context, count, max_results,
|
|
423
506
|
fixed, raw_query="", dots=False, drop_noise=True, timeout=None,
|
|
424
|
-
since_ts=None, until_ts=None, fts_ok=True):
|
|
507
|
+
since_ts=None, until_ts=None, fts_ok=True, symbol=False):
|
|
425
508
|
timeout = _RUN_DEFAULT_TIMEOUT_S if timeout is None else timeout
|
|
426
509
|
|
|
427
510
|
# FTS5 持久索引快路(opt-in,ARGO_LOCAL_FTS=1,2026-10-10 方案乙):只在
|
|
@@ -463,6 +546,8 @@ def rg_search(patterns, path, excludes, exts, context, count, max_results,
|
|
|
463
546
|
else:
|
|
464
547
|
return None, ("本机 rg 未编译 PCRE2,不支持 look-around/反向引用语法,"
|
|
465
548
|
"请简化查询(如去掉 (?=、(?! 等结构)")
|
|
549
|
+
if symbol:
|
|
550
|
+
cmd.append("-w")
|
|
466
551
|
if count:
|
|
467
552
|
cmd.append("--count-matches")
|
|
468
553
|
elif context > 0:
|
|
@@ -491,9 +576,15 @@ def rg_search(patterns, path, excludes, exts, context, count, max_results,
|
|
|
491
576
|
if proc.returncode == 1:
|
|
492
577
|
return [], None # 无匹配,正常
|
|
493
578
|
if proc.returncode == 2:
|
|
494
|
-
#
|
|
495
|
-
|
|
496
|
-
|
|
579
|
+
# 返回码 2 =「有结果,但过程中报了错」(悬空软链 os error 2、权限
|
|
580
|
+
# 不足等):rg 跳过出错路径继续搜,stdout 里其余文件的匹配照常有效
|
|
581
|
+
# ——与 _structural_search 同口径,有结果就放行下方正常解析,不再
|
|
582
|
+
# 整个放弃(2026-10-31 实测:--dot 搜含悬空软链的 ~/.agents/skills,
|
|
583
|
+
# 一条「No such file or directory」让整个查询空手而归)。stderr 的
|
|
584
|
+
# 路径级警告由 rg 自行打印,不进 err——上层 err 非 None 即判失败。
|
|
585
|
+
if not (proc.stdout or "").strip():
|
|
586
|
+
err = (proc.stderr or "").strip()
|
|
587
|
+
return [], f"rg 错误: {err[:200]}" if err else "rg 执行错误"
|
|
497
588
|
if count:
|
|
498
589
|
# 全量收集后按命中数降序取前 N:rg --count-matches 的输出顺序是
|
|
499
590
|
# 目录遍历序,直接截断会让「哪些文件命中最多」系统性答错——
|
|
@@ -769,7 +860,11 @@ def fd_search(query, path, exts, max_results, dots=False, timeout=None,
|
|
|
769
860
|
cmd += ["-e", e]
|
|
770
861
|
cmd += [query, str(path)]
|
|
771
862
|
proc = run(cmd, timeout=timeout)
|
|
772
|
-
if proc is None
|
|
863
|
+
if proc is None:
|
|
864
|
+
return [], "fd 执行失败"
|
|
865
|
+
# fd 对个别路径出错(悬空软链等)退出码落到 0/1 之外,但 stdout 里其余
|
|
866
|
+
# 匹配照常有效——有结果就解析,与 rg_search 同口径(2026-10-31)。
|
|
867
|
+
if proc.returncode not in (0, 1) and not (proc.stdout or "").strip():
|
|
773
868
|
return [], "fd 执行失败"
|
|
774
869
|
# 时间窗在截断前过滤(先截后滤会漏报,与 rg 路径同理)
|
|
775
870
|
lines = [p for p in proc.stdout.splitlines()
|
|
@@ -1245,6 +1340,8 @@ def run_query(argv=None, time_budget=None) -> tuple[str, int]:
|
|
|
1245
1340
|
ap.add_argument("--json", action="store_true", help="JSON 输出")
|
|
1246
1341
|
ap.add_argument("--max", type=int, default=0, help="最大结果数(默认读配置)")
|
|
1247
1342
|
ap.add_argument("--exact", action="store_true", help="关闭中文扩展(精确匹配)")
|
|
1343
|
+
ap.add_argument("--symbol", action="store_true",
|
|
1344
|
+
help="符号/词边界精确匹配(rg -w,过滤子串噪音)")
|
|
1248
1345
|
ap.add_argument("--exclude", action="append", default=[], metavar="GLOB",
|
|
1249
1346
|
help="额外排除 glob(可重复指定,如 --exclude eval_seek.py)")
|
|
1250
1347
|
ap.add_argument("--since", default=None,
|
|
@@ -1338,6 +1435,8 @@ def run_query(argv=None, time_budget=None) -> tuple[str, int]:
|
|
|
1338
1435
|
start = time.time()
|
|
1339
1436
|
results, err = [], None
|
|
1340
1437
|
patterns, fixed = build_patterns(args.query, args.exact)
|
|
1438
|
+
if args.symbol:
|
|
1439
|
+
patterns, fixed = [args.query], is_literal(args.query)
|
|
1341
1440
|
# 时间窗时间戳只解析一次,下传各搜索器在**截断前**过滤
|
|
1342
1441
|
since_ts, until_ts = parse_time(args.since), parse_time(args.until)
|
|
1343
1442
|
|
|
@@ -1397,9 +1496,8 @@ def run_query(argv=None, time_budget=None) -> tuple[str, int]:
|
|
|
1397
1496
|
err = "fd 未安装:按文件名搜索需要 fd(内容搜索走 rg/grep)"
|
|
1398
1497
|
else:
|
|
1399
1498
|
mode = "deep" if (args.context > 0 or args.count) else "fast"
|
|
1400
|
-
# FTS
|
|
1401
|
-
|
|
1402
|
-
fts_ok = not exts and not args.exclude
|
|
1499
|
+
# FTS 快路资格:带扩展名过滤、自定义排除或符号搜索时关闭(快路不做 rg 侧 glob 与 -w 过滤)。
|
|
1500
|
+
fts_ok = not exts and not args.exclude and not args.symbol
|
|
1403
1501
|
if not args.exact and len(patterns) > 1:
|
|
1404
1502
|
# 中文扩展遵循「先窄后宽」:先精确匹配,命中不足才放宽到扩展词
|
|
1405
1503
|
_dn = not args.include_noise
|
|
@@ -1408,14 +1506,14 @@ def run_query(argv=None, time_budget=None) -> tuple[str, int]:
|
|
|
1408
1506
|
is_literal(args.query), args.query, args.dot,
|
|
1409
1507
|
drop_noise=_dn, timeout=time_budget,
|
|
1410
1508
|
since_ts=since_ts, until_ts=until_ts,
|
|
1411
|
-
fts_ok=fts_ok)
|
|
1509
|
+
fts_ok=fts_ok, symbol=args.symbol)
|
|
1412
1510
|
if not results and not err:
|
|
1413
1511
|
results, err = rg_search(patterns, path, excludes, exts,
|
|
1414
1512
|
args.context, args.count, max_results,
|
|
1415
1513
|
fixed, args.query, args.dot, drop_noise=_dn,
|
|
1416
1514
|
timeout=time_budget,
|
|
1417
1515
|
since_ts=since_ts, until_ts=until_ts,
|
|
1418
|
-
fts_ok=fts_ok)
|
|
1516
|
+
fts_ok=fts_ok, symbol=args.symbol)
|
|
1419
1517
|
if results:
|
|
1420
1518
|
mode += "+扩展"
|
|
1421
1519
|
else:
|
|
@@ -1425,7 +1523,25 @@ def run_query(argv=None, time_budget=None) -> tuple[str, int]:
|
|
|
1425
1523
|
drop_noise=not args.include_noise,
|
|
1426
1524
|
timeout=time_budget,
|
|
1427
1525
|
since_ts=since_ts, until_ts=until_ts,
|
|
1428
|
-
fts_ok=fts_ok)
|
|
1526
|
+
fts_ok=fts_ok, symbol=args.symbol)
|
|
1527
|
+
# 中英对齐回落(2026-10-31):alias 只进打分层时纯英文语料连候选池
|
|
1528
|
+
# 都进不了(rg 字面零命中,打分无从发力);无条件注入检索层又会用
|
|
1529
|
+
# 对齐噪音挤掉既有命中(eval_rank 0.8258→0.7857 实测回退)。折中取
|
|
1530
|
+
# 「先窄后宽」同款语义:原 patterns 空手时才带对齐词元重搜一次。
|
|
1531
|
+
if not results and not err:
|
|
1532
|
+
alias_pats = list(patterns) + [
|
|
1533
|
+
en for p in patterns for en in _ZH_EN_ALIASES.get(p, ())
|
|
1534
|
+
if en not in patterns]
|
|
1535
|
+
if alias_pats != patterns:
|
|
1536
|
+
results, err = rg_search(alias_pats, path, excludes, exts,
|
|
1537
|
+
args.context, args.count, max_results,
|
|
1538
|
+
fixed, args.query, args.dot,
|
|
1539
|
+
drop_noise=not args.include_noise,
|
|
1540
|
+
timeout=time_budget,
|
|
1541
|
+
since_ts=since_ts, until_ts=until_ts,
|
|
1542
|
+
fts_ok=fts_ok, symbol=args.symbol)
|
|
1543
|
+
if results:
|
|
1544
|
+
mode += "+中英"
|
|
1429
1545
|
|
|
1430
1546
|
# 注:噪声档**只降权不排除**(见 _apply_noise_floor),所以这里没有
|
|
1431
1547
|
# 「搜不到就回落重搜」的分支——噪声内容始终在结果池里,只是排在真源之后。
|
|
@@ -51,8 +51,8 @@ from collections import Counter
|
|
|
51
51
|
_CJK_RUN = r"[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+"
|
|
52
52
|
# T1 主切词:字母数字连续串(不含 _ . 等分隔符)+ CJK 连续串
|
|
53
53
|
_RUN_RE = re.compile(r"[A-Za-z0-9]+|" + _CJK_RUN)
|
|
54
|
-
# camelCase
|
|
55
|
-
_CAMEL_RE = re.compile(r"[a-
|
|
54
|
+
# camelCase 与字母数字边界细分:小写段、数字段、驼峰大写段
|
|
55
|
+
_CAMEL_RE = re.compile(r"[a-z]+|[0-9]+|[A-Z](?=[a-z])[a-z]*|[A-Z]+(?![a-z])")
|
|
56
56
|
_CJK_ONLY_RE = re.compile("^" + _CJK_RUN + "$")
|
|
57
57
|
|
|
58
58
|
# BM25 常数(与 local-search/bm25.py 同口径:Okapi k1=1.5 b=0.75)
|
|
@@ -84,12 +84,129 @@ _PHRASE_BONUS = 3.0
|
|
|
84
84
|
_PHRASE_BONUS_CAP = 6.0
|
|
85
85
|
_NAME_PHRASE_BONUS = 4.0 # 文件名直接命中查询短语时的定位加成
|
|
86
86
|
|
|
87
|
+
# Markdown 标题行(#、##、### 等)主题加成:仅对 Markdown 文档生效(避免把 Python/Shell/YAML
|
|
88
|
+
# 的顶层 # 注释行误判为章节标题)。
|
|
89
|
+
_HEADING_RE = re.compile(r"^\s{0,3}#{1,6}\s+.*$")
|
|
90
|
+
_HEADING_BONUS = 3.5
|
|
91
|
+
_MD_EXTS = (".md", ".mdx", ".markdown")
|
|
92
|
+
|
|
93
|
+
# 代码符号定义行先验(Zoekt / Blackbird 思路,零 AST 依赖):函数/类/结构体定义或模块常量赋值
|
|
94
|
+
# 命中查询词时显著优先于普通调用行与注释顺带提及。
|
|
95
|
+
_DEF_RE = re.compile(
|
|
96
|
+
r"^\s*(?:(?:async|pub|export|public|private|protected|static|inline|const)\s+)*"
|
|
97
|
+
r"(?:def|class|fn|func|struct|interface|enum|type|trait|mod)\s+([A-Za-z_]\w*)"
|
|
98
|
+
r"|^\s*([A-Za-z_][A-Za-z0-9_]{1,})\s*(?::\s*[^=]+)?=\s*[^=]"
|
|
99
|
+
)
|
|
100
|
+
_DEF_BONUS = 4.5
|
|
101
|
+
_DEF_SYM_BONUS = 3.0
|
|
102
|
+
|
|
103
|
+
# 轻量中英工程核心概念对齐:中文词元同时匹配英文路径与文件名段(用 unicode 转义避免本文件被 rg 字面扫中自污染)
|
|
104
|
+
_ZH_EN_ALIASES: dict[str, tuple[str, ...]] = {
|
|
105
|
+
"\u672c\u5730": ("local",),
|
|
106
|
+
"\u641c\u7d22": ("search", "seek"),
|
|
107
|
+
"\u68c0\u7d22": ("search", "seek"),
|
|
108
|
+
"\u805a\u5408": ("search", "v3", "merge"),
|
|
109
|
+
"\u7f13\u5b58": ("cache",),
|
|
110
|
+
"\u8bed\u4e49": ("similarity", "semantic"),
|
|
111
|
+
"\u8def\u7531": ("route", "router"),
|
|
112
|
+
"\u6392\u5e8f": ("rank", "sort"),
|
|
113
|
+
"\u91cd\u6392": ("rerank", "rank"),
|
|
114
|
+
"\u566a\u58f0": ("noise",),
|
|
115
|
+
"\u62fc\u97f3": ("pinyin",),
|
|
116
|
+
"\u8bc1\u636e": ("evidence",),
|
|
117
|
+
"\u6293\u53d6": ("fetch", "crawl"),
|
|
118
|
+
"\u7194\u65ad": ("breaker", "circuit"),
|
|
119
|
+
"\u914d\u7f6e": ("config",),
|
|
120
|
+
"\u56fe\u7247": ("image",),
|
|
121
|
+
"\u95e8\u7981": ("gate",),
|
|
122
|
+
# 通用工程高频(2026-10-31 补:实测「视频字幕」查 remotion 系列全 miss,
|
|
123
|
+
# 原表偏 argo 仓工程词,通用词是盲区)
|
|
124
|
+
"\u6e32\u67d3": ("render",),
|
|
125
|
+
"\u89c6\u9891": ("video",),
|
|
126
|
+
"\u5b57\u5e55": ("subtitle", "caption"),
|
|
127
|
+
"\u7ec4\u4ef6": ("component",),
|
|
128
|
+
"\u63a5\u53e3": ("interface", "api"),
|
|
129
|
+
"\u7ebf\u7a0b": ("thread",),
|
|
130
|
+
"\u5185\u5b58": ("memory",),
|
|
131
|
+
"\u65e5\u5fd7": ("log", "logging"),
|
|
132
|
+
"\u90e8\u7f72": ("deploy",),
|
|
133
|
+
"\u7f51\u7edc": ("network",),
|
|
134
|
+
"\u4ee3\u7406": ("proxy",),
|
|
135
|
+
"\u8ba4\u8bc1": ("auth", "token"),
|
|
136
|
+
"\u6570\u636e\u5e93": ("database", "db"),
|
|
137
|
+
# 高频软件工程概念扩展
|
|
138
|
+
"\u5e76\u53d1": ("concurrency", "parallel", "concurrent"),
|
|
139
|
+
"\u9650\u6d41": ("ratelimit", "throttle", "rate_limit"),
|
|
140
|
+
"\u8d85\u65f6": ("timeout", "deadline"),
|
|
141
|
+
"\u91cd\u8bd5": ("retry", "backoff"),
|
|
142
|
+
"\u5f02\u6b65": ("async", "await", "future"),
|
|
143
|
+
"\u961f\u5217": ("queue", "mq"),
|
|
144
|
+
"\u7d22\u5f15": ("index", "fts", "indexing"),
|
|
145
|
+
"\u5411\u91cf": ("vector", "embedding"),
|
|
146
|
+
"\u6743\u91cd": ("weight", "priority"),
|
|
147
|
+
"\u9608\u503c": ("threshold", "limit"),
|
|
148
|
+
"\u5ef6\u8fdf": ("latency", "delay"),
|
|
149
|
+
"\u541e\u5410": ("throughput", "tps"),
|
|
150
|
+
"\u6743\u9650": ("permission", "auth", "rbac"),
|
|
151
|
+
"\u52a0\u5bc6": ("encrypt", "crypto", "cipher"),
|
|
152
|
+
"\u89e3\u6790": ("parse", "parser"),
|
|
153
|
+
"\u5e8f\u5217": ("serialize", "json"),
|
|
154
|
+
"\u8fdb\u7a0b": ("process", "daemon", "worker"),
|
|
155
|
+
"\u9501": ("lock", "mutex"),
|
|
156
|
+
"\u8c03\u5ea6": ("dispatch", "schedule", "scheduler"),
|
|
157
|
+
"\u964d\u7ea7": ("fallback", "degrade"),
|
|
158
|
+
"\u6062\u590d": ("recovery", "heal", "reclaim"),
|
|
159
|
+
"\u53bb\u91cd": ("dedup", "dedupe"),
|
|
160
|
+
"\u65f6\u6548": ("freshness", "timestamp"),
|
|
161
|
+
"\u6743\u5a01": ("authority", "trust"),
|
|
162
|
+
"\u914d\u989d": ("quota", "limit"),
|
|
163
|
+
"\u6570\u636e": ("data", "storage"),
|
|
164
|
+
"\u5b9a\u65f6": ("cron", "timer", "schedule"),
|
|
165
|
+
"\u7b56\u7565": ("policy", "strategy"),
|
|
166
|
+
"\u6307\u6807": ("metrics", "metric"),
|
|
167
|
+
"\u7ec8\u7aef": ("terminal", "cli"),
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
_LOOKUP_INSTANCE = None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _get_concept_lookup():
|
|
174
|
+
"""按需延迟加载 concept_lookup(零依赖 fail-open)。"""
|
|
175
|
+
global _LOOKUP_INSTANCE
|
|
176
|
+
if _LOOKUP_INSTANCE is None:
|
|
177
|
+
try:
|
|
178
|
+
import sys
|
|
179
|
+
from pathlib import Path
|
|
180
|
+
cur_file = Path(__file__).resolve()
|
|
181
|
+
argo_root = cur_file.parents[3]
|
|
182
|
+
scripts_dir = str(argo_root / "scripts")
|
|
183
|
+
if scripts_dir not in sys.path:
|
|
184
|
+
sys.path.insert(0, scripts_dir)
|
|
185
|
+
from concept_lookup import get_concept_lookup
|
|
186
|
+
_LOOKUP_INSTANCE = get_concept_lookup()
|
|
187
|
+
except Exception:
|
|
188
|
+
_LOOKUP_INSTANCE = False
|
|
189
|
+
return _LOOKUP_INSTANCE if _LOOKUP_INSTANCE is not False else None
|
|
190
|
+
|
|
191
|
+
# 跨字段协同加成(Minimal Span / Coordination Level):单条结果的 (name ∪ dir ∪ line) 覆盖越多不同查询词元越优先
|
|
192
|
+
_ROW_COORD_WEIGHT = 5.0
|
|
193
|
+
|
|
87
194
|
|
|
88
195
|
def _split_camel(run: str) -> list[str]:
|
|
89
|
-
"""
|
|
90
|
-
if run.islower() or run.isdigit():
|
|
196
|
+
"""驼峰与字母数字细分:BM25Okapi → bm / 25 / bm25 / okapi;bm25 → bm / 25。"""
|
|
197
|
+
if (run.isalpha() and run.islower()) or run.isdigit():
|
|
91
198
|
return []
|
|
92
|
-
|
|
199
|
+
parts = [m.group(0).lower() for m in _CAMEL_RE.finditer(run)]
|
|
200
|
+
if len(parts) <= 1:
|
|
201
|
+
return []
|
|
202
|
+
out = list(parts)
|
|
203
|
+
# 相邻「字母段 + 数字段」合并(如 BM25Okapi 产出 bm25,对齐文件名 bm25.py)
|
|
204
|
+
for i in range(len(parts) - 1):
|
|
205
|
+
if parts[i].isalpha() and parts[i + 1].isdigit():
|
|
206
|
+
merged = parts[i] + parts[i + 1]
|
|
207
|
+
if merged != run.lower():
|
|
208
|
+
out.append(merged)
|
|
209
|
+
return out
|
|
93
210
|
|
|
94
211
|
|
|
95
212
|
def _tokens(text: str, *, camel: bool = False) -> list[str]:
|
|
@@ -111,11 +228,11 @@ def _tokens(text: str, *, camel: bool = False) -> list[str]:
|
|
|
111
228
|
def _row_fields(fp: str, text: str) -> dict[str, Counter]:
|
|
112
229
|
"""一行命中在三字段下的词频表。fp 无目录段时 dir 为空表。"""
|
|
113
230
|
fp = fp.rstrip("/")
|
|
114
|
-
|
|
231
|
+
dirpart, _, name = fp.rpartition("/")
|
|
115
232
|
fields = {
|
|
116
233
|
"name": Counter(_tokens(name, camel=True)),
|
|
117
234
|
"dir": Counter(_tokens(dirpart, camel=True)),
|
|
118
|
-
"line": Counter(_tokens(text or "")),
|
|
235
|
+
"line": Counter(_tokens(text or "", camel=True)),
|
|
119
236
|
}
|
|
120
237
|
return fields
|
|
121
238
|
|
|
@@ -135,6 +252,13 @@ def rank_rows(rows: list[tuple[str, int, str]], raw_query: str,
|
|
|
135
252
|
if not q_tf or not rows:
|
|
136
253
|
return rows
|
|
137
254
|
|
|
255
|
+
# 跨语言标识符对齐词元(降权权重 0.65,辅助中文查询命中英文代码路径/符号)
|
|
256
|
+
q_eff: dict[str, float] = {k: float(v) for k, v in q_tf.items()}
|
|
257
|
+
for qt in list(q_tf):
|
|
258
|
+
for en in _ZH_EN_ALIASES.get(qt, ()):
|
|
259
|
+
if en not in q_eff:
|
|
260
|
+
q_eff[en] = 0.65
|
|
261
|
+
|
|
138
262
|
# 逐字短语表:完整 CJK 连续串 + 较长 ASCII 连续串(行文本做子串检查用)
|
|
139
263
|
phrases = [m.group(0).lower()
|
|
140
264
|
for m in re.finditer(r"[A-Za-z0-9_\-+#.]{3,}|" + _CJK_RUN,
|
|
@@ -159,7 +283,28 @@ def rank_rows(rows: list[tuple[str, int, str]], raw_query: str,
|
|
|
159
283
|
for term in f_tf[f]:
|
|
160
284
|
f_df[term] += 1
|
|
161
285
|
|
|
286
|
+
# 概念向量对齐扩展:从候选项路径高频词元中,寻找与查询词元高度语义对齐的词(余弦 >= 0.75)
|
|
287
|
+
concept_expanded: dict[str, set[str]] = {}
|
|
288
|
+
lookup = _get_concept_lookup()
|
|
289
|
+
if lookup and lookup.is_available:
|
|
290
|
+
for qt in list(q_tf):
|
|
291
|
+
vq = lookup.get_vector(qt)
|
|
292
|
+
if vq is None:
|
|
293
|
+
continue
|
|
294
|
+
matched = set()
|
|
295
|
+
cand_vocab = set(df["name"]) | set(df["dir"])
|
|
296
|
+
for cand in cand_vocab:
|
|
297
|
+
if cand in q_eff:
|
|
298
|
+
continue
|
|
299
|
+
vt = lookup.get_vector(cand)
|
|
300
|
+
if vt is not None and lookup.vector_cosine(vq, vt) >= 0.75:
|
|
301
|
+
q_eff[cand] = 0.60
|
|
302
|
+
matched.add(cand)
|
|
303
|
+
if matched:
|
|
304
|
+
concept_expanded[qt] = matched
|
|
305
|
+
|
|
162
306
|
scores: list[float] = []
|
|
307
|
+
n_q_primary = max(len(q_tf), 1)
|
|
163
308
|
for i, f_tf in enumerate(row_fields):
|
|
164
309
|
total = 0.0
|
|
165
310
|
for f, w, b in _FIELDS:
|
|
@@ -169,7 +314,7 @@ def rank_rows(rows: list[tuple[str, int, str]], raw_query: str,
|
|
|
169
314
|
dl = sum(tf_map.values())
|
|
170
315
|
norm = _K1 * (1.0 - b + b * dl / avgdl[f])
|
|
171
316
|
f_df = df[f]
|
|
172
|
-
for qt, qtf in
|
|
317
|
+
for qt, qtf in q_eff.items():
|
|
173
318
|
tf = tf_map.get(qt)
|
|
174
319
|
if not tf:
|
|
175
320
|
continue
|
|
@@ -177,21 +322,56 @@ def rank_rows(rows: list[tuple[str, int, str]], raw_query: str,
|
|
|
177
322
|
# BM25+:饱和项加下界 δ(只对命中的词,未命中不送底分)
|
|
178
323
|
sat = (tf * (_K1 + 1.0)) / (tf + norm)
|
|
179
324
|
total += w * qtf * (sat + _DELTA) * idf
|
|
180
|
-
|
|
325
|
+
fp = rows[i][0]
|
|
326
|
+
total += _TOPIC_PRIOR_WEIGHT * math.log1p(file_hits[fp])
|
|
327
|
+
# 单行三字段协同覆盖度(name ∪ dir ∪ line 覆盖了多少查询词/跨语言映射词)
|
|
328
|
+
row_voc = set(f_tf["name"]) | set(f_tf["dir"]) | set(f_tf["line"])
|
|
329
|
+
covered = sum(1.0 for qt in q_tf if qt in row_voc or any(
|
|
330
|
+
en in row_voc for en in _ZH_EN_ALIASES.get(qt, ())) or any(
|
|
331
|
+
ce in row_voc for ce in concept_expanded.get(qt, ())))
|
|
332
|
+
if covered > 1.0:
|
|
333
|
+
total += _ROW_COORD_WEIGHT * (covered / n_q_primary)
|
|
181
334
|
if phrases:
|
|
182
335
|
low_line = (rows[i][2] or "").lower()
|
|
183
|
-
fp_low = (
|
|
336
|
+
fp_low = (fp or "").lower()
|
|
184
337
|
name_low = fp_low.rpartition("/")[2] or fp_low
|
|
185
338
|
name_hits = sum(1 for ph in phrases if ph in name_low)
|
|
186
339
|
line_hits = sum(1 for ph in phrases if ph in low_line)
|
|
187
340
|
total += min(name_hits, 2) * _NAME_PHRASE_BONUS + min(line_hits, 2) * _PHRASE_BONUS
|
|
341
|
+
if line_hits >= 2:
|
|
342
|
+
hit_pos = [low_line.find(ph) for ph in phrases if ph in low_line]
|
|
343
|
+
if max(hit_pos) - min(hit_pos) <= 10:
|
|
344
|
+
total += 2.5 # 多词紧邻跨度加成(Min-Span Proximity)
|
|
345
|
+
raw_line = rows[i][2] or ""
|
|
346
|
+
fp_low = (fp or "").lower()
|
|
347
|
+
# 文档标题感知:仅对 Markdown 文件生效,避免误奖代码注释
|
|
348
|
+
if fp_low.endswith(_MD_EXTS) and _HEADING_RE.match(raw_line) and f_tf["line"]:
|
|
349
|
+
if any(qt in f_tf["line"] for qt in q_eff):
|
|
350
|
+
total += _HEADING_BONUS
|
|
351
|
+
# 代码定义行感知:函数/类/常量定义行优先于普通调用与注释
|
|
352
|
+
m_def = _DEF_RE.match(raw_line)
|
|
353
|
+
if m_def and f_tf["line"] and any(qt in f_tf["line"] for qt in q_eff):
|
|
354
|
+
total += _DEF_BONUS
|
|
355
|
+
sym = (m_def.group(1) or m_def.group(2) or "").lower()
|
|
356
|
+
if sym and any(qt in sym for qt in q_eff):
|
|
357
|
+
total += _DEF_SYM_BONUS
|
|
188
358
|
if boost_fn is not None:
|
|
189
359
|
try:
|
|
190
|
-
total += boost_fn(
|
|
360
|
+
total += boost_fn(fp)
|
|
191
361
|
except Exception:
|
|
192
362
|
pass # 注入的加成失败不拖累打分本体
|
|
193
363
|
scores.append(total)
|
|
194
364
|
|
|
365
|
+
# 同文件多行命中边际递减(第 3 条起温和衰减,防单文件 8 行霸屏 Top-5)
|
|
366
|
+
by_fp: dict[str, list[int]] = {}
|
|
367
|
+
for idx, (fp, _ln, _txt) in enumerate(rows):
|
|
368
|
+
by_fp.setdefault(fp, []).append(idx)
|
|
369
|
+
for idxs in by_fp.values():
|
|
370
|
+
if len(idxs) > 2:
|
|
371
|
+
idxs.sort(key=lambda idx: (-scores[idx], rows[idx][1]))
|
|
372
|
+
for rank_in_file, idx in enumerate(idxs[2:], start=2):
|
|
373
|
+
scores[idx] /= (1.0 + 0.35 * (rank_in_file - 1))
|
|
374
|
+
|
|
195
375
|
order = sorted(range(n_rows),
|
|
196
376
|
key=lambda i: (-scores[i], rows[i][0], rows[i][1]))
|
|
197
377
|
return [rows[i] for i in order]
|