argo-search 1.0.1 → 2.9.7
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/LICENSE +201 -21
- package/README.en.md +822 -0
- package/README.es.md +864 -0
- package/README.ja.md +864 -0
- package/README.ko.md +864 -0
- package/README.md +867 -320
- package/SKILL.md +135 -0
- package/assets/readme/hero.svg +121 -0
- package/assets/readme/made-with-beautify.svg +10 -0
- package/assets/readme/proof-routes.svg +73 -0
- package/assets/readme/settings-keys.png +0 -0
- package/assets/readme/settings-tools.png +0 -0
- package/assets/readme/why-better.svg +104 -0
- package/assets/readme/workflow.svg +83 -0
- package/backends/domain_profiles.json +2308 -96
- package/backends/engine_registry.yaml +3314 -503
- package/backends/query_synonyms_cn.json +35 -0
- package/backends/quota_profiles.json +2409 -161
- package/backends/source_types_cn.json +83 -0
- package/backends/text_lexicon.json +44 -0
- package/bin/argo +703 -0
- package/bin/argo.js +71 -39
- package/config.yaml +4976 -363
- package/cordis.patch.yml +21 -0
- package/data/countries.json +40 -0
- package/data/lang_matrix/lang_capability.json +842 -0
- package/data/lang_matrix/matrix_2026-09-10.json +11921 -0
- package/data/regions_cn.json +1 -0
- package/docs/ADDING_NEW_ENGINE.md +184 -0
- package/docs/ARGO_INTRO.md +124 -0
- package/docs/DATA_SOURCE_GAPS.md +81 -0
- package/docs/DESIGN_LOCAL_DATA_FUSION.md +90 -0
- package/docs/ENGINE_CATALOG.md +564 -0
- package/docs/MCP_SETUP.md +106 -0
- package/docs/PLATFORM_PATHS.md +111 -0
- package/docs/RELEASE_NOTES_v2.8.0.md +71 -0
- package/docs/RELEASE_NOTES_v2.8.2.md +63 -0
- package/docs/RELEASE_NOTES_v2.8.3.md +55 -0
- package/docs/RELEASE_NOTES_v2.8.4.md +79 -0
- package/docs/RELEASE_NOTES_v2.8.5.md +102 -0
- package/docs/RELEASE_NOTES_v2.8.6.md +66 -0
- package/docs/RELEASE_NOTES_v2.8.7.md +65 -0
- package/docs/RELEASE_NOTES_v2.8.8.md +67 -0
- package/docs/RELEASE_NOTES_v2.8.9.md +67 -0
- package/docs/RELEASE_NOTES_v2.9.0.md +64 -0
- package/docs/SEARCH_ARCHIVE.md +115 -0
- package/docs/assets/architecture.svg +104 -0
- package/docs/assets/hero.svg +98 -0
- package/docs/engines/bangumi.md +27 -0
- package/docs/engines/biorxiv.md +27 -0
- package/docs/engines/clawhub.md +27 -0
- package/docs/engines/crt_sh.md +27 -0
- package/docs/engines/datacite.md +27 -0
- package/docs/engines/deps_dev.md +27 -0
- package/docs/engines/douban_movie.md +27 -0
- package/docs/engines/endoflife.md +27 -0
- package/docs/engines/flk_law.md +27 -0
- package/docs/engines/fxtwitter.md +27 -0
- package/docs/engines/google_news.md +27 -0
- package/docs/engines/gov_regulations.md +27 -0
- package/docs/engines/guqian.md +27 -0
- package/docs/engines/hackernews.md +27 -0
- package/docs/engines/iplant.md +27 -0
- package/docs/engines/keenable.md +27 -0
- package/docs/engines/met_museum.md +27 -0
- package/docs/engines/nasa_images.md +27 -0
- package/docs/engines/netease_music.md +27 -0
- package/docs/engines/npm.md +27 -0
- package/docs/engines/nvd.md +27 -0
- package/docs/engines/openreview.md +27 -0
- package/docs/engines/openstd.md +27 -0
- package/docs/engines/parallel_free.md +27 -0
- package/docs/engines/people_daily.md +27 -0
- package/docs/engines/realtime_index.md +27 -0
- package/docs/engines/sec_edgar.md +27 -0
- package/docs/engines/seltz.md +27 -0
- package/docs/engines/skillsmp.md +27 -0
- package/docs/engines/sspai.md +27 -0
- package/docs/engines/std_samr.md +27 -0
- package/docs/engines/train.md +27 -0
- package/docs/engines/un_comtrade.md +27 -0
- package/docs/engines/wikisource.md +27 -0
- package/docs/engines/zdic.md +27 -0
- package/docs/engines/zenodo.md +27 -0
- package/docs/engines/zhihu_hot_app.md +27 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +176 -0
- package/engines/README.md +10 -0
- package/engines/_template_cli.yaml +39 -0
- package/engines/_template_http.yaml +37 -0
- package/engines/plugins/_template_plugin.py +50 -0
- package/engines/specs/_cisa_kev.yaml +54 -0
- package/engines/specs/_osv.yaml +63 -0
- package/engines/specs/aljazeera.yaml +43 -0
- package/engines/specs/antara.yaml +43 -0
- package/engines/specs/artic.yaml +20 -0
- package/engines/specs/aviation_weather.yaml +39 -0
- package/engines/specs/bangumi.yaml +21 -0
- package/engines/specs/biorxiv.yaml +24 -0
- package/engines/specs/carbon_intensity.yaml +32 -0
- package/engines/specs/cinii.yaml +44 -0
- package/engines/specs/clawhub.yaml +49 -0
- package/engines/specs/cleveland.yaml +19 -0
- package/engines/specs/cn_ai_news.yaml +43 -0
- package/engines/specs/core.yaml +35 -0
- package/engines/specs/crt_sh.yaml +38 -0
- package/engines/specs/ct24.yaml +43 -0
- package/engines/specs/datacite.yaml +27 -0
- package/engines/specs/datagov_uk.yaml +41 -0
- package/engines/specs/ddgs_images.yaml +45 -0
- package/engines/specs/deepseek_search.yaml +74 -0
- package/engines/specs/deezer.yaml +20 -0
- package/engines/specs/deps_dev.yaml +21 -0
- package/engines/specs/digup.yaml +36 -0
- package/engines/specs/doi.yaml +39 -0
- package/engines/specs/douban_movie.yaml +22 -0
- package/engines/specs/dw_news.yaml +47 -0
- package/engines/specs/egov_law.yaml +21 -0
- package/engines/specs/elpais.yaml +43 -0
- package/engines/specs/endoflife.yaml +21 -0
- package/engines/specs/energy_charts.yaml +21 -0
- package/engines/specs/factcheck_org.yaml +52 -0
- package/engines/specs/faz.yaml +43 -0
- package/engines/specs/federal_register.yaml +57 -0
- package/engines/specs/firecrawl.yaml +53 -0
- package/engines/specs/flk_law.yaml +24 -0
- package/engines/specs/folha.yaml +43 -0
- package/engines/specs/france24.yaml +44 -0
- package/engines/specs/full_fact.yaml +47 -0
- package/engines/specs/fxtwitter.yaml +31 -0
- package/engines/specs/gbfs_nyc.yaml +32 -0
- package/engines/specs/gdacs.yaml +21 -0
- package/engines/specs/gdelt.yaml +64 -0
- package/engines/specs/google_news.yaml +22 -0
- package/engines/specs/gov_regulations.yaml +38 -0
- package/engines/specs/guardian_rss.yaml +59 -0
- package/engines/specs/hurriyet.yaml +43 -0
- package/engines/specs/iplant.yaml +25 -0
- package/engines/specs/jikan.yaml +24 -0
- package/engines/specs/jolpica.yaml +20 -0
- package/engines/specs/k10plus.yaml +20 -0
- package/engines/specs/keenable.yaml +44 -0
- package/engines/specs/lefigaro.yaml +43 -0
- package/engines/specs/listenbrainz.yaml +19 -0
- package/engines/specs/matichon.yaml +43 -0
- package/engines/specs/met_museum.yaml +21 -0
- package/engines/specs/nasa_images.yaml +45 -0
- package/engines/specs/netease_music.yaml +38 -0
- package/engines/specs/nhk.yaml +43 -0
- package/engines/specs/nhtsa_vpic.yaml +20 -0
- package/engines/specs/noaa_swpc.yaml +20 -0
- package/engines/specs/nvd.yaml +38 -0
- package/engines/specs/obis.yaml +20 -0
- package/engines/specs/opencitations.yaml +52 -0
- package/engines/specs/openf1.yaml +21 -0
- package/engines/specs/openfoodfacts.yaml +45 -0
- package/engines/specs/openligadb.yaml +20 -0
- package/engines/specs/openreview.yaml +37 -0
- package/engines/specs/openstd.yaml +21 -0
- package/engines/specs/people_daily.yaml +22 -0
- package/engines/specs/realtime_index.yaml +34 -0
- package/engines/specs/ror.yaml +20 -0
- package/engines/specs/satnogs.yaml +20 -0
- package/engines/specs/sec_edgar.yaml +46 -0
- package/engines/specs/skillsmp.yaml +50 -0
- package/engines/specs/sogou_weixin_browser.yaml +30 -0
- package/engines/specs/soilgrids.yaml +25 -0
- package/engines/specs/sspai.yaml +36 -0
- package/engines/specs/stackexchange.yaml +46 -0
- package/engines/specs/std_samr.yaml +21 -0
- package/engines/specs/tass.yaml +43 -0
- package/engines/specs/tle_mirror.yaml +21 -0
- package/engines/specs/train.yaml +37 -0
- package/engines/specs/tvmaze.yaml +20 -0
- package/engines/specs/twitter_syndication.yaml +31 -0
- package/engines/specs/un_comtrade.yaml +23 -0
- package/engines/specs/unpaywall.yaml +54 -0
- package/engines/specs/vnpress.yaml +43 -0
- package/engines/specs/weather.yaml +32 -0
- package/engines/specs/who_don.yaml +21 -0
- package/engines/specs/who_gho.yaml +20 -0
- package/engines/specs/wikimedia_commons.yaml +34 -0
- package/engines/specs/wikisource.yaml +22 -0
- package/engines/specs/worms.yaml +19 -0
- package/engines/specs/x_trending.yaml +34 -0
- package/engines/specs/yna.yaml +43 -0
- package/engines/specs/ynet.yaml +43 -0
- package/engines/specs/zbmath.yaml +40 -0
- package/engines/specs/zdic.yaml +22 -0
- package/engines/specs/zenodo.yaml +27 -0
- package/engines/specs/zhihu_hot_app.yaml +35 -0
- package/mcp/clients.yaml +74 -0
- package/package.json +51 -12
- package/packages/dsh-plugin/README.md +134 -0
- package/packages/dsh-plugin/cordis.patch.yml +48 -0
- package/packages/dsh-plugin/dsh/client.js +1244 -0
- package/packages/dsh-plugin/dsh/index.js +2290 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +743 -0
- package/packages/dsh-plugin/package.json +38 -0
- package/packages/dsh-plugin/test/client.test.js +232 -0
- package/packages/dsh-plugin/test/config.test.js +30 -0
- package/packages/dsh-plugin/test/index.test.js +1338 -0
- package/references/query-templates.md +96 -0
- package/references/query-templates.yaml +118 -0
- package/scripts/ab_eval.py +219 -0
- package/scripts/ab_eval_p0p1.py +266 -0
- package/scripts/adaptive.py +271 -70
- package/scripts/answer.py +154 -0
- package/scripts/archive_run.py +591 -0
- package/scripts/argo_engine_registry.py +172 -0
- package/scripts/argo_paths.py +728 -0
- package/scripts/article.py +136 -0
- package/scripts/arxiv_source.py +201 -0
- package/scripts/badcase_ledger.py +252 -0
- package/scripts/batch_probe.py +241 -0
- package/scripts/benchmark.py +19 -0
- package/scripts/bounded_run.py +144 -0
- package/scripts/browser_auth.py +323 -0
- package/scripts/burstiness_detector.py +147 -0
- package/scripts/cache.py +1078 -67
- package/scripts/cache_guard.py +271 -0
- package/scripts/cache_key_vdom.py +56 -0
- package/scripts/cache_similarity.py +170 -0
- package/scripts/caliber_isolation.py +195 -0
- package/scripts/calibrate_lowquality.py +210 -0
- package/scripts/candidate_envelope.py +366 -0
- package/scripts/chrome_cdp.py +871 -0
- package/scripts/circuit_breaker.py +389 -0
- package/scripts/citations.py +334 -0
- package/scripts/cite_cli.py +59 -0
- package/scripts/cjk_tokens.py +95 -0
- package/scripts/clarify.py +47 -24
- package/scripts/cli_io.py +240 -0
- package/scripts/config.py +683 -45
- package/scripts/config_cache.py +402 -0
- package/scripts/conn_pool.py +220 -0
- package/scripts/content_security.py +685 -0
- package/scripts/content_signals.py +730 -0
- package/scripts/crawl.py +74 -35
- package/scripts/daemon.py +866 -0
- package/scripts/digup_bridge.py +214 -0
- package/scripts/engine_admission.py +366 -0
- package/scripts/engine_dispatch.py +1019 -0
- package/scripts/engine_env.py +534 -0
- package/scripts/engine_failure.py +411 -0
- package/scripts/engine_families.py +732 -0
- package/scripts/engine_policy.py +218 -0
- package/scripts/engine_requires.py +190 -0
- package/scripts/engine_status.py +322 -0
- package/scripts/engine_validate.py +638 -0
- package/scripts/engines.py +778 -294
- package/scripts/engines_base.py +1521 -0
- package/scripts/engines_builders.py +298 -0
- package/scripts/engines_builders_batch10.py +159 -0
- package/scripts/engines_builders_batch11.py +174 -0
- package/scripts/engines_builders_batch12.py +103 -0
- package/scripts/engines_builders_batch13.py +340 -0
- package/scripts/engines_builders_batch9.py +1468 -0
- package/scripts/engines_builders_cn.py +2283 -0
- package/scripts/engines_builders_data.py +2923 -0
- package/scripts/engines_builders_data_macro.py +775 -0
- package/scripts/engines_builders_feeds.py +255 -0
- package/scripts/engines_builders_intl.py +1239 -0
- package/scripts/engines_builders_search.py +440 -0
- package/scripts/engines_builders_tech.py +1360 -0
- package/scripts/evidence.py +588 -162
- package/scripts/evidence_loop.py +592 -0
- package/scripts/evidence_tier.py +298 -0
- package/scripts/except_sets.py +25 -0
- package/scripts/extract.py +55 -16
- package/scripts/fact_align.py +207 -0
- package/scripts/fact_crosscheck.py +230 -0
- package/scripts/fetch.py +25 -12
- package/scripts/fetch_browser.py +87 -0
- package/scripts/fetch_jsrun.py +122 -0
- package/scripts/fetch_quality.py +225 -0
- package/scripts/fetch_render_tinyfish.py +117 -0
- package/scripts/fetch_v3.py +1779 -0
- package/scripts/focus_extract.py +350 -0
- package/scripts/fulltext_store.py +169 -0
- package/scripts/fxtwitter_api.py +325 -0
- package/scripts/gen_engine_catalog.py +364 -0
- package/scripts/gen_native_tools.py +91 -0
- package/scripts/gen_routing_snapshot.py +184 -0
- package/scripts/health_check.py +140 -402
- package/scripts/health_probe.py +23 -8
- package/scripts/hot_state.py +134 -0
- package/scripts/http_client.py +1053 -0
- package/scripts/image_ops.py +430 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/image_vision/vision_probe.swift +126 -0
- package/scripts/install.ps1 +148 -0
- package/scripts/install.sh +206 -0
- package/scripts/job.py +1186 -0
- package/scripts/jump_resolver.py +235 -0
- package/scripts/lang_capability.py +150 -0
- package/scripts/lang_detect.py +289 -0
- package/scripts/lang_matrix_probe.py +329 -0
- package/scripts/lang_pref.py +311 -0
- package/scripts/link_source.py +340 -0
- package/scripts/local_engines.py +321 -0
- package/scripts/local_image.py +970 -0
- package/scripts/local_seek.py +366 -0
- package/scripts/macro_countries.py +82 -0
- package/scripts/matrix_search_eval.py +1105 -0
- package/scripts/mcp_diag.py +8 -3
- package/scripts/mcp_handlers.py +1074 -0
- package/scripts/mcp_handlers_surface.py +157 -0
- package/scripts/mcp_launch.sh +122 -0
- package/scripts/mcp_server.py +118 -417
- package/scripts/mcp_setup.py +407 -0
- package/scripts/mcp_tools.py +330 -0
- package/scripts/mcp_transport.py +191 -0
- package/scripts/min_version_scan.py +335 -0
- package/scripts/net_proxy.py +258 -0
- package/scripts/network_aware.py +152 -0
- package/scripts/paper.py +274 -0
- package/scripts/pdf_extract.py +518 -0
- package/scripts/phrase_filter.py +66 -0
- package/scripts/plan.py +422 -0
- package/scripts/postprocess_signals.py +150 -0
- package/scripts/pre-commit +48 -0
- package/scripts/query_enhance.py +157 -0
- package/scripts/query_operators.py +196 -0
- package/scripts/query_rewriter.py +116 -7
- package/scripts/query_signals.py +300 -0
- package/scripts/query_templates.py +167 -0
- package/scripts/query_understanding.py +411 -0
- package/scripts/query_variants.py +298 -0
- package/scripts/quota.py +488 -76
- package/scripts/rank_signals.py +775 -0
- package/scripts/ranking_eval.py +319 -0
- package/scripts/readability_extract.py +433 -0
- package/scripts/recompute.py +415 -0
- package/scripts/recovery.py +616 -0
- package/scripts/recovery_l0.py +160 -0
- package/scripts/redskill/redskill_engine.py +332 -0
- package/scripts/regression_p0p1.py +318 -0
- package/scripts/replay_eval.py +640 -0
- package/scripts/rerank_tfidf.py +225 -0
- package/scripts/research.py +591 -403
- package/scripts/research_cli.py +361 -0
- package/scripts/research_dossier.py +492 -0
- package/scripts/research_expand.py +146 -0
- package/scripts/research_gates.py +272 -0
- package/scripts/research_report.py +209 -0
- package/scripts/research_strategy.py +37 -0
- package/scripts/research_work_packages.py +195 -0
- package/scripts/result_lang.py +311 -0
- package/scripts/robots_guard.py +259 -0
- package/scripts/route.py +921 -254
- package/scripts/route_bangs.py +40 -0
- package/scripts/route_cache.py +225 -0
- package/scripts/route_combo.py +910 -0
- package/scripts/route_domains.py +328 -0
- package/scripts/route_lang.py +605 -0
- package/scripts/route_log.py +63 -0
- package/scripts/route_policy.py +250 -0
- package/scripts/rrf_classic.py +66 -0
- package/scripts/screenshot.py +73 -0
- package/scripts/search.py +897 -405
- package/scripts/search_attribution.py +88 -0
- package/scripts/search_benchmark.py +407 -0
- package/scripts/search_cli.py +627 -0
- package/scripts/search_entry.py +389 -0
- package/scripts/search_output.py +606 -0
- package/scripts/search_pipeline.py +1077 -0
- package/scripts/search_rank.py +991 -0
- package/scripts/search_types.py +27 -12
- package/scripts/seek_locator.py +68 -0
- package/scripts/semantic_evidence.py +215 -0
- package/scripts/serp_guard.py +228 -0
- package/scripts/serp_kill_log.py +51 -0
- package/scripts/single_flight.py +120 -0
- package/scripts/social_engines/__init__.py +10 -0
- package/scripts/social_engines/bilibili_engine.py +131 -0
- package/scripts/social_engines/hackernews_engine.py +113 -0
- package/scripts/social_engines/reddit_engine.py +172 -0
- package/scripts/social_engines/twitter_engine.py +397 -0
- package/scripts/social_engines/v2ex_engine.py +101 -0
- package/scripts/social_engines/weibo_engine.py +128 -0
- package/scripts/social_engines/xiaohongshu_engine.py +137 -0
- package/scripts/social_engines/zhihu_engine.py +139 -0
- package/scripts/social_research.py +201 -0
- package/scripts/sogou_weixin_browser.py +318 -0
- package/scripts/source_ledger.py +249 -0
- package/scripts/stage_timing.py +58 -0
- package/scripts/stats_cli.py +95 -0
- package/scripts/straggler_policy.py +60 -0
- package/scripts/stylometry_detector.py +231 -0
- package/scripts/sync_backends.py +353 -0
- package/scripts/sync_installs.py +29 -0
- package/scripts/template_cli.py +127 -0
- package/scripts/text_lexicon.py +72 -0
- package/scripts/tfidf_router.py +109 -37
- package/scripts/time_utils.py +233 -0
- package/scripts/topic_research_profiles.py +643 -0
- package/scripts/train.py +737 -0
- package/scripts/tweet.py +596 -0
- package/scripts/url_canon.py +217 -0
- package/scripts/url_optimize.py +56 -0
- package/scripts/url_safety.py +236 -0
- package/scripts/usage_log.py +116 -0
- package/scripts/usage_log_clean.py +113 -0
- package/scripts/v2ex_nodes.py +311 -0
- package/scripts/variant_recall.py +188 -0
- package/scripts/watch.py +205 -0
- package/scripts/wechat_article.py +258 -0
- package/scripts/wide_research.py +402 -0
- package/scripts/wx.py +349 -0
- package/scripts/x_article_fetch.py +141 -0
- package/scripts/x_search.py +234 -0
- package/scripts/x_trending.py +189 -0
- package/scripts/yaml_load.py +67 -0
- package/sub-skills/ego-search/SKILL.md +253 -0
- package/sub-skills/ego-search/references/browser-runtime.md +43 -0
- package/sub-skills/ego-search/references/install.md +67 -0
- package/sub-skills/ego-search/references/original-ego-upgrade.md +51 -0
- package/sub-skills/ego-search/scripts/ego_search.py +800 -0
- package/sub-skills/ego-search/scripts/merge.py +226 -0
- package/sub-skills/ego-search/scripts/quality.py +64 -0
- package/sub-skills/ego-search/scripts/runtime.py +172 -0
- package/sub-skills/ego-search/scripts/safety.py +109 -0
- package/sub-skills/ego-search/scripts/serp_spec.py +109 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +374 -0
- package/sub-skills/ego-search/tests/test_query_normalize.py +68 -0
- package/sub-skills/js-run/SKILL.md +67 -0
- package/sub-skills/js-run/scripts/jsrun.py +112 -0
- package/sub-skills/js-run/scripts/shim.js +188 -0
- package/sub-skills/js-run/tests/fixtures/challenge_like.js +27 -0
- package/sub-skills/js-run/tests/test_jsrun.py +165 -0
- package/sub-skills/local-search/SKILL.md +50 -53
- package/sub-skills/local-search/bm25.py +162 -0
- package/sub-skills/local-search/config.yaml +152 -55
- package/sub-skills/local-search/engine_registry.py +91 -26
- package/sub-skills/local-search/{health_check.py → local_health_check.py} +140 -10
- package/sub-skills/local-search/local_search_adapter.py +13 -2
- package/sub-skills/local-search/parse_maps.yaml +40 -42
- package/sub-skills/local-search/search_v3.py +1182 -65
- package/sub-skills/local-search/smart_router.py +47 -7
- package/sub-skills/local-seek/SKILL.md +110 -0
- package/sub-skills/local-seek/config/domains.yaml +20 -0
- package/sub-skills/local-seek/references/auto-behaviors.md +24 -0
- package/sub-skills/local-seek/references/fd-mdfind-recipes.md +62 -0
- package/sub-skills/local-seek/references/git-integration.md +54 -0
- package/sub-skills/local-seek/references/remote-handoff.md +46 -0
- package/sub-skills/local-seek/references/rg-recipes.md +96 -0
- package/sub-skills/local-seek/references/strategies.md +52 -0
- package/sub-skills/local-seek/references/structural-search.md +59 -0
- package/sub-skills/local-seek/scripts/eval_rank.py +216 -0
- package/sub-skills/local-seek/scripts/eval_seek.py +224 -0
- package/sub-skills/local-seek/scripts/seek.py +1465 -0
- package/sub-skills/local-seek/scripts/seek_frecency.py +126 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +430 -0
- package/sub-skills/local-seek/scripts/seek_rank.py +193 -0
- package/sub-skills/local-seek/tests/test_content_rank.py +222 -0
- package/sub-skills/local-seek/tests/test_determinism_20261006.py +145 -0
- package/sub-skills/local-seek/tests/test_noise_tier.py +101 -0
- package/sub-skills/local-seek/tests/test_pcre2_probe.py +136 -0
- package/sub-skills/local-seek/tests/test_rank_pinyin.py +77 -0
- package/sub-skills/local-seek/tests/test_regression_20261003.py +169 -0
- package/sub-skills/local-seek/tests/test_regression_20261006.py +146 -0
- package/sub-skills/local-seek/tests/test_seek_degradation.py +111 -0
- package/sub-skills/local-seek/tests/test_seek_fts.py +313 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""research_dossier.py — 取证包合成。
|
|
3
|
+
|
|
4
|
+
产出 kind=dossier。key_findings 是检索头条,不是研究结论。
|
|
5
|
+
SERP snippet 不得标成 verifiable。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
from typing import Any
|
|
13
|
+
from urllib.parse import urlparse, parse_qsl, urlunparse
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from evidence import compute_credibility
|
|
17
|
+
except ImportError: # pragma: no cover
|
|
18
|
+
compute_credibility = None # type: ignore
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from evidence import score_authority
|
|
22
|
+
except ImportError: # pragma: no cover
|
|
23
|
+
score_authority = None # type: ignore
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from fact_align import align_facts
|
|
27
|
+
except ImportError: # pragma: no cover
|
|
28
|
+
align_facts = None # type: ignore
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
_COVERAGE_OK_MIN = 3
|
|
32
|
+
_COVERAGE_PARTIAL_MIN = 1
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def detect_cross_references(
|
|
36
|
+
results: list[dict[str, Any]],
|
|
37
|
+
min_sources: int = 2,
|
|
38
|
+
min_ngram_len: int = 3,
|
|
39
|
+
) -> list[dict[str, Any]]:
|
|
40
|
+
"""检测多个来源的交叉引用(n-gram 重叠)。"""
|
|
41
|
+
ngram_sources: dict[str, set[str]] = {}
|
|
42
|
+
for r in results:
|
|
43
|
+
url = r.get("url", "")
|
|
44
|
+
domain = urlparse(url).netloc.lower() if url else "unknown"
|
|
45
|
+
if domain.startswith("www."):
|
|
46
|
+
domain = domain[4:]
|
|
47
|
+
text = f"{r.get('title', '')} {r.get('snippet', '')}"
|
|
48
|
+
en_tokens = re.findall(r"[a-zA-Z]+", text.lower())
|
|
49
|
+
cn_chars = re.findall(r"[\u4e00-\u9fff]+", text)
|
|
50
|
+
cn_tokens = []
|
|
51
|
+
for seg in cn_chars:
|
|
52
|
+
for i in range(len(seg) - min_ngram_len + 1):
|
|
53
|
+
cn_tokens.append(seg[i:i + min_ngram_len])
|
|
54
|
+
all_tokens = en_tokens + cn_tokens
|
|
55
|
+
for n in range(min_ngram_len, min(min_ngram_len + 1, len(all_tokens) + 1)):
|
|
56
|
+
for i in range(len(all_tokens) - n + 1):
|
|
57
|
+
ngram = " ".join(all_tokens[i:i + n])
|
|
58
|
+
if len(ngram) >= 4:
|
|
59
|
+
ngram_sources.setdefault(ngram, set()).add(domain)
|
|
60
|
+
|
|
61
|
+
cross_refs = []
|
|
62
|
+
for ngram, domains in ngram_sources.items():
|
|
63
|
+
if len(domains) >= min_sources:
|
|
64
|
+
cross_refs.append({
|
|
65
|
+
"ngram": ngram,
|
|
66
|
+
"source_count": len(domains),
|
|
67
|
+
"domains": sorted(domains),
|
|
68
|
+
})
|
|
69
|
+
cross_refs.sort(key=lambda x: x["source_count"], reverse=True)
|
|
70
|
+
return cross_refs[:10]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def coverage_status(sr: dict[str, Any]) -> str:
|
|
74
|
+
results = sr.get("results") or []
|
|
75
|
+
n = len(results)
|
|
76
|
+
if n >= _COVERAGE_OK_MIN:
|
|
77
|
+
return "COVERED"
|
|
78
|
+
if n >= _COVERAGE_PARTIAL_MIN:
|
|
79
|
+
return "PARTIAL"
|
|
80
|
+
return "NOT_COVERED"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def evidence_tier(source: str, source_grades: dict[str, Any] | None) -> str:
|
|
84
|
+
if not source:
|
|
85
|
+
return "unknown"
|
|
86
|
+
grades = source_grades or {}
|
|
87
|
+
for tier, items in (
|
|
88
|
+
("primary", grades.get("primary") or grades.get("一手") or []),
|
|
89
|
+
("secondary", grades.get("secondary") or grades.get("权威") or []),
|
|
90
|
+
("tertiary", grades.get("tertiary") or grades.get("参考") or []),
|
|
91
|
+
):
|
|
92
|
+
if not isinstance(items, list):
|
|
93
|
+
continue
|
|
94
|
+
for it in items:
|
|
95
|
+
if not isinstance(it, str):
|
|
96
|
+
continue
|
|
97
|
+
if source == it or source.startswith(it) or it in source:
|
|
98
|
+
return tier
|
|
99
|
+
s = source.lower()
|
|
100
|
+
if any(k in s for k in (
|
|
101
|
+
"arxiv", "openalex", "crossref", "semantic_scholar",
|
|
102
|
+
"pubmed", "europepmc", "github", "cninfo", "fred",
|
|
103
|
+
"worldbank", "nbs_stats", "sina_quote", "tencent_quote",
|
|
104
|
+
)):
|
|
105
|
+
return "primary"
|
|
106
|
+
if any(k in s for k in (
|
|
107
|
+
"zhihu", "eastmoney", "byted", "bocha", "octen",
|
|
108
|
+
"cls_telegraph", "em_global_news", "jin10",
|
|
109
|
+
)):
|
|
110
|
+
return "secondary"
|
|
111
|
+
if any(k in s for k in (
|
|
112
|
+
"twitter", "reddit", "weibo", "bilibili", "xiaohongshu",
|
|
113
|
+
"douban", "v2ex", "hackernews", "local_sogou", "local_baidu",
|
|
114
|
+
)):
|
|
115
|
+
return "tertiary"
|
|
116
|
+
return "unknown"
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def canonical_url(url: str) -> str:
|
|
120
|
+
"""URL 归一化(薄转发到 url_canon 唯一来源),供同源去重。
|
|
121
|
+
|
|
122
|
+
本函数曾自带一份实现(去 www/尾斜杠、查询参数用 '&' 手工拼接而非
|
|
123
|
+
urlencode),与融合层 search._canonical_url 的键不一致——融合层已合并
|
|
124
|
+
的同稿链接,进了 dossier 又被算成两条。现统一到 url_canon。
|
|
125
|
+
"""
|
|
126
|
+
from url_canon import canonical_url as _impl
|
|
127
|
+
return _impl(url)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def build_local_sources(file_inputs: list[dict[str, Any]] | None) -> list[dict[str, Any]]:
|
|
131
|
+
"""本地一手数据文件入账(来源记录登记,内容不入账)。
|
|
132
|
+
|
|
133
|
+
每条:ref([L1] 前缀与 URLs 的 [1] 区分)、规范 path、sha256、size、
|
|
134
|
+
mtime、kind、role。读取失败的文件跳过(不入账、不中断取证)。
|
|
135
|
+
"""
|
|
136
|
+
if not file_inputs:
|
|
137
|
+
return []
|
|
138
|
+
out: list[dict[str, Any]] = []
|
|
139
|
+
for i, fi in enumerate(file_inputs, 1):
|
|
140
|
+
path = str(fi.get("path") or "")
|
|
141
|
+
try:
|
|
142
|
+
digest = _sha256_file(path)
|
|
143
|
+
mtime = int(os.path.getmtime(path))
|
|
144
|
+
except OSError:
|
|
145
|
+
continue
|
|
146
|
+
out.append({
|
|
147
|
+
"ref": f"[L{i}]",
|
|
148
|
+
"type": "file",
|
|
149
|
+
"path": path,
|
|
150
|
+
"sha256": digest,
|
|
151
|
+
"size": int(fi.get("size") or os.path.getsize(path)),
|
|
152
|
+
"mtime": mtime,
|
|
153
|
+
"kind": fi.get("kind") or "",
|
|
154
|
+
"role": fi.get("role") or "data",
|
|
155
|
+
"note": "本地一手文件:已登记哈希与血缘,内容未入库;"
|
|
156
|
+
"引用时标注文件路径与行号",
|
|
157
|
+
})
|
|
158
|
+
return out
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _sha256_file(path: str, chunk: int = 256 * 1024) -> str:
|
|
162
|
+
import hashlib
|
|
163
|
+
h = hashlib.sha256()
|
|
164
|
+
with open(path, "rb") as f:
|
|
165
|
+
while True:
|
|
166
|
+
block = f.read(chunk)
|
|
167
|
+
if not block:
|
|
168
|
+
break
|
|
169
|
+
h.update(block)
|
|
170
|
+
return h.hexdigest()
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def build_recomputed_values(
|
|
174
|
+
recompute_results: list[dict[str, Any]] | None,
|
|
175
|
+
) -> list[dict[str, Any]]:
|
|
176
|
+
"""recompute 产物入账:运行记录(含脚本摘要、输出尾部、提取值)。
|
|
177
|
+
|
|
178
|
+
数值提取失败/空输出的条目仍入账(ok=False 时是审计痕迹)。
|
|
179
|
+
"""
|
|
180
|
+
if not recompute_results:
|
|
181
|
+
return []
|
|
182
|
+
out = []
|
|
183
|
+
for i, r in enumerate(recompute_results, 1):
|
|
184
|
+
try:
|
|
185
|
+
from recompute import extract_values
|
|
186
|
+
values = extract_values(str(r.get("stdout") or ""))
|
|
187
|
+
except Exception:
|
|
188
|
+
values = []
|
|
189
|
+
out.append({
|
|
190
|
+
"ref": f"[R{i}]",
|
|
191
|
+
"package_id": r.get("package_id") or "",
|
|
192
|
+
"ok": bool(r.get("ok")),
|
|
193
|
+
"skipped_reason": r.get("skipped_reason"),
|
|
194
|
+
"timed_out": bool(r.get("timed_out")),
|
|
195
|
+
"values": values,
|
|
196
|
+
"stdout_tail": str(r.get("stdout") or "")[-300:],
|
|
197
|
+
"stderr_tail": str(r.get("stderr") or "")[-200:],
|
|
198
|
+
"elapsed_ms": r.get("elapsed_ms"),
|
|
199
|
+
"note": "数值由本地数据重算得出;与检索数字冲突时以重算为准并标注",
|
|
200
|
+
})
|
|
201
|
+
return out
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def _build_source_leads(
|
|
205
|
+
sub_results: list[dict[str, Any]],
|
|
206
|
+
source_grades: dict[str, Any] | None,
|
|
207
|
+
) -> list[dict[str, Any]]:
|
|
208
|
+
"""检索线索。snippet 不是主张,一律 unverified_snippet。"""
|
|
209
|
+
records = []
|
|
210
|
+
for sr in sub_results:
|
|
211
|
+
results = sr.get("results") or []
|
|
212
|
+
if not results:
|
|
213
|
+
records.append({
|
|
214
|
+
"claim": sr.get("intent", ""),
|
|
215
|
+
"evidence_tier": "unknown",
|
|
216
|
+
"verification_method": "no_results",
|
|
217
|
+
"result": "unverifiable",
|
|
218
|
+
"reason": "no_results",
|
|
219
|
+
})
|
|
220
|
+
continue
|
|
221
|
+
# 取每包 top-3 建线索,避免一手/高后果源排位靠后时漏判
|
|
222
|
+
for best in results[:3]:
|
|
223
|
+
url = best.get("url") or ""
|
|
224
|
+
source = best.get("source") or ""
|
|
225
|
+
snippet = (best.get("snippet") or best.get("title") or "")[:120]
|
|
226
|
+
tier = evidence_tier(source, source_grades)
|
|
227
|
+
method_parts = [f"evidence_tier={tier}"]
|
|
228
|
+
if len(results) >= 2:
|
|
229
|
+
method_parts.append("multi_source")
|
|
230
|
+
if any(c.isdigit() for c in (snippet or "")):
|
|
231
|
+
method_parts.append("has_numbers")
|
|
232
|
+
records.append({
|
|
233
|
+
"claim": snippet or best.get("title") or sr.get("intent", ""),
|
|
234
|
+
"source": source,
|
|
235
|
+
"url": url,
|
|
236
|
+
"evidence_tier": tier,
|
|
237
|
+
"verification_method": "+".join(method_parts),
|
|
238
|
+
"result": "unverified_snippet",
|
|
239
|
+
"reason": "serp_snippet_is_not_a_claim",
|
|
240
|
+
})
|
|
241
|
+
return records
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _build_cross_verification(
|
|
245
|
+
merged: list[dict[str, Any]],
|
|
246
|
+
query: str,
|
|
247
|
+
sub_results: list[dict[str, Any]],
|
|
248
|
+
) -> dict[str, Any]:
|
|
249
|
+
base = {
|
|
250
|
+
"credibility_available": False,
|
|
251
|
+
"corroboration_level": "unknown",
|
|
252
|
+
"cross_score": 0.0,
|
|
253
|
+
"conflicts": [],
|
|
254
|
+
"unverified_count": 0,
|
|
255
|
+
}
|
|
256
|
+
try:
|
|
257
|
+
if compute_credibility is None:
|
|
258
|
+
return base
|
|
259
|
+
scored = compute_credibility(merged, query)
|
|
260
|
+
cross = scored.get("cross_validation") or {}
|
|
261
|
+
scored_results = scored.get("results") or []
|
|
262
|
+
if not scored_results:
|
|
263
|
+
return base
|
|
264
|
+
conflicts: list[dict[str, Any]] = []
|
|
265
|
+
unverified = 0
|
|
266
|
+
for sr in sub_results:
|
|
267
|
+
results = sr.get("results") or []
|
|
268
|
+
# 两个坑,缺一不可:
|
|
269
|
+
#
|
|
270
|
+
# 1) 字段名。此前读 `authority.source_type`——它从未存在。
|
|
271
|
+
# evidence.score_authority 的返回键是
|
|
272
|
+
# {score, reason, tier, domain, is_serp}(实测)。tier 取值
|
|
273
|
+
# high/medium/low/very_low,语义与原来想要的 blog/forum/social
|
|
274
|
+
# 同类:低层级即需人工复核。
|
|
275
|
+
# 2) 数据源。`credibility` 只挂在 merged 上(compute_credibility 的
|
|
276
|
+
# 输入是 merged,不是各子查询的原始结果),所以直接读
|
|
277
|
+
# sr["results"] 上的 credibility 恒为 None。这里按 URL 现算权威
|
|
278
|
+
# 层级——score_authority 带进程内缓存,不额外联网/读盘。
|
|
279
|
+
#
|
|
280
|
+
# 两处叠在一起时这段是**死代码**:tiers 恒空 → conflicts 恒空 →
|
|
281
|
+
# research_report 的「⚠ 混入低证据层级来源」永远不打印。
|
|
282
|
+
tiers = []
|
|
283
|
+
for r in results[:5]:
|
|
284
|
+
if not isinstance(r, dict):
|
|
285
|
+
continue
|
|
286
|
+
t = (r.get("credibility") or {}).get("authority", {}).get("tier")
|
|
287
|
+
if not t and score_authority is not None:
|
|
288
|
+
try:
|
|
289
|
+
t = score_authority(r.get("url") or "").get("tier")
|
|
290
|
+
except Exception:
|
|
291
|
+
t = None
|
|
292
|
+
if t:
|
|
293
|
+
tiers.append(t)
|
|
294
|
+
if len(tiers) >= 2 and any(t in ("low", "very_low") for t in tiers):
|
|
295
|
+
conflicts.append({
|
|
296
|
+
"dimension": sr.get("intent", ""),
|
|
297
|
+
"sub_query": sr.get("sub_query", ""),
|
|
298
|
+
"detail": "同一维度内混入低证据层级来源,需人工复核",
|
|
299
|
+
})
|
|
300
|
+
if not results:
|
|
301
|
+
unverified += 1
|
|
302
|
+
return {
|
|
303
|
+
"credibility_available": True,
|
|
304
|
+
"corroboration_level": cross.get("corroboration_level", "unknown"),
|
|
305
|
+
"cross_score": float(cross.get("score", 0.0)),
|
|
306
|
+
"agreement_count": cross.get("agreement_count", 0),
|
|
307
|
+
"unique_domains": cross.get("unique_domains", 0),
|
|
308
|
+
"content_domains": cross.get("content_domains", 0),
|
|
309
|
+
"detail": cross.get("detail", ""),
|
|
310
|
+
"top_sources": [
|
|
311
|
+
{
|
|
312
|
+
"url": r.get("url", ""),
|
|
313
|
+
"source": r.get("source", ""),
|
|
314
|
+
"final": r.get("credibility", {}).get("final", 0.0),
|
|
315
|
+
}
|
|
316
|
+
for r in scored_results[:5]
|
|
317
|
+
if r.get("url")
|
|
318
|
+
],
|
|
319
|
+
"conflicts": conflicts,
|
|
320
|
+
"unverified_count": unverified,
|
|
321
|
+
}
|
|
322
|
+
except Exception:
|
|
323
|
+
return base
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def build_dossier(
|
|
327
|
+
query: str,
|
|
328
|
+
collection: dict[str, Any],
|
|
329
|
+
gaps: list[str],
|
|
330
|
+
source_grades: dict[str, Any] | None = None,
|
|
331
|
+
mode: str = "auto",
|
|
332
|
+
depth: str = "balanced",
|
|
333
|
+
file_inputs: list[dict[str, Any]] | None = None,
|
|
334
|
+
recompute_results: list[dict[str, Any]] | None = None,
|
|
335
|
+
) -> dict[str, Any]:
|
|
336
|
+
"""合成取证包。兼容旧名 synthesize_report。"""
|
|
337
|
+
merged = collection["merged_results"]
|
|
338
|
+
sub_results = collection["sub_results"]
|
|
339
|
+
|
|
340
|
+
key_findings = []
|
|
341
|
+
for sr in sub_results:
|
|
342
|
+
if sr["results"]:
|
|
343
|
+
best = sr["results"][0]
|
|
344
|
+
key_findings.append({
|
|
345
|
+
"aspect": sr["intent"],
|
|
346
|
+
"strategy": sr["strategy"],
|
|
347
|
+
"top_result": {
|
|
348
|
+
"title": best.get("title", ""),
|
|
349
|
+
"url": best.get("url", ""),
|
|
350
|
+
"snippet": (best.get("snippet", "") or "")[:200],
|
|
351
|
+
"score": best.get("score", 0),
|
|
352
|
+
"source": best.get("source", ""),
|
|
353
|
+
},
|
|
354
|
+
"result_count": len(sr["results"]),
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
source_counts: dict[str, int] = {}
|
|
358
|
+
for r in merged:
|
|
359
|
+
src = r.get("source", "unknown")
|
|
360
|
+
source_counts[src] = source_counts.get(src, 0) + 1
|
|
361
|
+
|
|
362
|
+
url_sub_query_count: dict[str, int] = {}
|
|
363
|
+
for sr in sub_results:
|
|
364
|
+
for r in sr.get("results", []):
|
|
365
|
+
cu = canonical_url(r.get("url") or "") or (r.get("url") or "")
|
|
366
|
+
if cu:
|
|
367
|
+
url_sub_query_count[cu] = url_sub_query_count.get(cu, 0) + 1
|
|
368
|
+
|
|
369
|
+
citations = []
|
|
370
|
+
sources = []
|
|
371
|
+
seen_canon: set[str] = set()
|
|
372
|
+
ref = 0
|
|
373
|
+
for r in merged:
|
|
374
|
+
url = r.get("url") or ""
|
|
375
|
+
if not url:
|
|
376
|
+
continue
|
|
377
|
+
canon = canonical_url(url) or url
|
|
378
|
+
if canon in seen_canon:
|
|
379
|
+
continue
|
|
380
|
+
seen_canon.add(canon)
|
|
381
|
+
ref += 1
|
|
382
|
+
title = r.get("title") or ""
|
|
383
|
+
eng = r.get("source") or ""
|
|
384
|
+
sq_count = url_sub_query_count.get(canon, 1)
|
|
385
|
+
citations.append({
|
|
386
|
+
"id": f"[{ref}]",
|
|
387
|
+
"ref": ref,
|
|
388
|
+
"title": title,
|
|
389
|
+
"url": url,
|
|
390
|
+
"canonical_url": canon,
|
|
391
|
+
"source": eng,
|
|
392
|
+
"score": r.get("score", 0),
|
|
393
|
+
"snippet": (r.get("snippet") or "")[:160] or None,
|
|
394
|
+
"corroboration": {
|
|
395
|
+
"sub_query_count": sq_count,
|
|
396
|
+
"single_source": sq_count <= 1,
|
|
397
|
+
},
|
|
398
|
+
})
|
|
399
|
+
sources.append({
|
|
400
|
+
"ref": ref,
|
|
401
|
+
"title": title[:160],
|
|
402
|
+
"url": url,
|
|
403
|
+
"engine": eng,
|
|
404
|
+
"score": r.get("score"),
|
|
405
|
+
"snippet": (r.get("snippet") or "")[:160] or None,
|
|
406
|
+
"corroboration": {
|
|
407
|
+
"sub_query_count": sq_count,
|
|
408
|
+
"single_source": sq_count <= 1,
|
|
409
|
+
},
|
|
410
|
+
})
|
|
411
|
+
if ref >= 15:
|
|
412
|
+
break
|
|
413
|
+
|
|
414
|
+
url_to_ref = {c["url"]: c["ref"] for c in citations if c.get("url")}
|
|
415
|
+
for kf in key_findings:
|
|
416
|
+
top = kf.get("top_result") or {}
|
|
417
|
+
u = top.get("url") or ""
|
|
418
|
+
if u and u in url_to_ref:
|
|
419
|
+
top["ref"] = url_to_ref[u]
|
|
420
|
+
kf["citation_refs"] = [url_to_ref[u]]
|
|
421
|
+
else:
|
|
422
|
+
kf["citation_refs"] = []
|
|
423
|
+
|
|
424
|
+
all_results = []
|
|
425
|
+
for sr in sub_results:
|
|
426
|
+
all_results.extend(sr["results"])
|
|
427
|
+
cross_refs = detect_cross_references(all_results)
|
|
428
|
+
|
|
429
|
+
coverage_map = []
|
|
430
|
+
for sr in sub_results:
|
|
431
|
+
results = sr.get("results") or []
|
|
432
|
+
engines = {r.get("source") for r in results if r.get("source")}
|
|
433
|
+
coverage_map.append({
|
|
434
|
+
"dimension": sr.get("intent", ""),
|
|
435
|
+
"sub_query": sr.get("sub_query") or sr.get("query") or "",
|
|
436
|
+
"status": coverage_status(sr),
|
|
437
|
+
"result_count": len(results),
|
|
438
|
+
"engine_count": len(engines),
|
|
439
|
+
"package_id": sr.get("package_id"),
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
blind_spots = [
|
|
443
|
+
{"dimension": cm["dimension"], "reason": "无结果"}
|
|
444
|
+
for cm in coverage_map if cm["status"] == "NOT_COVERED"
|
|
445
|
+
]
|
|
446
|
+
blind_spots += [
|
|
447
|
+
{"dimension": cm["dimension"], "reason": "单来源覆盖"}
|
|
448
|
+
for cm in coverage_map
|
|
449
|
+
if cm["status"] == "PARTIAL" and cm["engine_count"] <= 1
|
|
450
|
+
]
|
|
451
|
+
if not blind_spots and coverage_map:
|
|
452
|
+
blind_spots.append({"dimension": "全局", "reason": "无显式未覆盖维度"})
|
|
453
|
+
|
|
454
|
+
source_leads = _build_source_leads(sub_results, source_grades)
|
|
455
|
+
cross_verification = _build_cross_verification(merged, query, sub_results)
|
|
456
|
+
|
|
457
|
+
fact_alignment = None
|
|
458
|
+
if align_facts is not None:
|
|
459
|
+
try:
|
|
460
|
+
fact_alignment = align_facts(
|
|
461
|
+
merged, min_results=3, mode=mode, depth=depth
|
|
462
|
+
)
|
|
463
|
+
except Exception:
|
|
464
|
+
fact_alignment = None
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
"kind": "dossier",
|
|
468
|
+
"query": query,
|
|
469
|
+
"key_findings": key_findings,
|
|
470
|
+
"total_sources": collection["total_results"],
|
|
471
|
+
"engines_used": collection["engines_used"],
|
|
472
|
+
"source_distribution": source_counts,
|
|
473
|
+
"citations": citations,
|
|
474
|
+
"sources": sources,
|
|
475
|
+
"local_sources": build_local_sources(file_inputs),
|
|
476
|
+
"recomputed_values": build_recomputed_values(recompute_results),
|
|
477
|
+
"cross_references": cross_refs,
|
|
478
|
+
"coverage_map": coverage_map,
|
|
479
|
+
"source_leads": source_leads,
|
|
480
|
+
"verification_records": source_leads,
|
|
481
|
+
"cross_verification": cross_verification,
|
|
482
|
+
"fact_alignment": fact_alignment,
|
|
483
|
+
"blind_spots": blind_spots,
|
|
484
|
+
"gaps": gaps,
|
|
485
|
+
"elapsed_ms": collection["elapsed_ms"],
|
|
486
|
+
"sub_query_count": len(sub_results),
|
|
487
|
+
"protocol": "references/research-protocol.md",
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
# 旧名:测试与 MCP 仍 import synthesize_report
|
|
492
|
+
synthesize_report = build_dossier
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""research_expand.py — 检索扩词(不是问题树)。
|
|
3
|
+
|
|
4
|
+
把原 decompose_query 的正则启发式收成扩词器。
|
|
5
|
+
Agent 的 MECE 问题树走 research_work_packages,不要把扩词当研究拆解。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
def expand_query(query: str, num_sub: int = 4) -> list[dict[str, str]]:
|
|
12
|
+
"""按关键词特征扩检索词。产出的是搜索变体,不是可验证子问题。"""
|
|
13
|
+
sub_queries: list[dict[str, str]] = []
|
|
14
|
+
|
|
15
|
+
has_chinese = any("\u4e00" <= c <= "\u9fff" for c in query)
|
|
16
|
+
has_english = any(c.isascii() and c.isalpha() for c in query)
|
|
17
|
+
|
|
18
|
+
if has_chinese and has_english:
|
|
19
|
+
eng_words = " ".join(w for w in query.split() if w.isascii() and len(w) > 2)
|
|
20
|
+
if eng_words:
|
|
21
|
+
sub_queries.append({
|
|
22
|
+
"query": eng_words,
|
|
23
|
+
"intent": "英文核心概念搜索",
|
|
24
|
+
"strategy": "english_focused",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
# 「{query} {year} latest update」分支已删除:year_match 来自查询本身,
|
|
28
|
+
# 查询必然已含该年份,拼出的变体对引擎就是原查询 + 噪声词(实测相对
|
|
29
|
+
# 原查询新信息率仅 0.18,纯冗余且抢占子查询槽位)。年份限定语义已由
|
|
30
|
+
# 原查询表达,时间窗过滤走 search 的 --since/--until。
|
|
31
|
+
|
|
32
|
+
compare_match = re.search(r"(?:vs| versus |对比|比较|和|与|及)", query, re.I)
|
|
33
|
+
if compare_match:
|
|
34
|
+
parts = re.split(r"(?:vs| versus |对比|比较|和|与|及)", query, flags=re.I)
|
|
35
|
+
for part in parts[:2]:
|
|
36
|
+
part = part.strip()
|
|
37
|
+
if part and len(part) > 2:
|
|
38
|
+
sub_queries.append({
|
|
39
|
+
"query": part,
|
|
40
|
+
"intent": f"独立搜索:{part[:20]}",
|
|
41
|
+
"strategy": "split_compare",
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
how_match = re.search(r"(?:如何|怎么|how|why|为什么|最佳实践|best practice)", query, re.I)
|
|
45
|
+
if how_match:
|
|
46
|
+
sub_queries.append({
|
|
47
|
+
"query": f"{query} tutorial guide best practices",
|
|
48
|
+
"intent": "教程/最佳实践",
|
|
49
|
+
"strategy": "tutorial",
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
bug_match = re.search(
|
|
53
|
+
r"(?:bug|error|问题|报错|故障|issue|panic|crash|exception)", query, re.I
|
|
54
|
+
)
|
|
55
|
+
if bug_match:
|
|
56
|
+
sub_queries.append({
|
|
57
|
+
"query": f"{query} solution fix workaround community",
|
|
58
|
+
"intent": "社区解决方案",
|
|
59
|
+
"strategy": "community_fix",
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
academic_match = re.search(
|
|
63
|
+
r"(?:论文|paper|arxiv|学术|综述|review|survey|研究)", query, re.I
|
|
64
|
+
)
|
|
65
|
+
if academic_match:
|
|
66
|
+
sub_queries.append({
|
|
67
|
+
"query": f"{query} arxiv semantic scholar 2024 2025",
|
|
68
|
+
"intent": "学术文献补充",
|
|
69
|
+
"strategy": "academic",
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
security_match = re.search(
|
|
73
|
+
r"(?:CVE|漏洞|vulnerability|security|exploit|PoC)", query, re.I
|
|
74
|
+
)
|
|
75
|
+
if security_match:
|
|
76
|
+
sub_queries.append({
|
|
77
|
+
"query": f"{query} NVD exploit PoC advisory",
|
|
78
|
+
"intent": "安全数据源补充",
|
|
79
|
+
"strategy": "security",
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
finance_match = re.search(
|
|
83
|
+
r"(?:股价|财报|年报|中报|季报|业绩|营收|利润|基金|股票|行情|金融"
|
|
84
|
+
r"|financial|earnings|stock|revenue)", query, re.I
|
|
85
|
+
)
|
|
86
|
+
if finance_match:
|
|
87
|
+
sub_queries.append({
|
|
88
|
+
"query": f"{query} 东方财富 雪球 研报",
|
|
89
|
+
"intent": "金融数据补充",
|
|
90
|
+
"strategy": "finance",
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
# anchor:原查询本身永远占一席(唯一保证与用户意图对齐的子查询,
|
|
94
|
+
# 也是 dossier 的 baseline)。模板产出不含原查询文本时补上。
|
|
95
|
+
if len(sub_queries) < num_sub and all(
|
|
96
|
+
sq["query"] != query for sq in sub_queries):
|
|
97
|
+
sub_queries.append({
|
|
98
|
+
"query": query,
|
|
99
|
+
"intent": "综合搜索",
|
|
100
|
+
"strategy": "general",
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return _deduplicate_sub_queries(sub_queries[:num_sub])
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _deduplicate_sub_queries(sub_queries: list[dict[str, str]]) -> list[dict[str, str]]:
|
|
107
|
+
"""按「新信息率」去重子查询。
|
|
108
|
+
|
|
109
|
+
旧判据(与已有集合 Jaccard>0.6 判重)与扩词目的相反:Jaccard 衡量
|
|
110
|
+
重合度,扩词的价值恰恰是增量。实测(2026-09-20,char 粒度):
|
|
111
|
+
「{query} 2024 latest update」0.83 —— 杀掉了原查询本身(anchor);
|
|
112
|
+
「{query} arxiv semantic scholar ...」0.77 —— 杀掉了带 3 个英文
|
|
113
|
+
新词的学术变体;
|
|
114
|
+
「what is {query} and how does it work」套中文实体 0.59 —— 冗余
|
|
115
|
+
壳反而存活。
|
|
116
|
+
判据改为:子查询的新 token(未出现在已有集合)占比 <0.25 判冗余;
|
|
117
|
+
direct/general(=原查询)是 anchor,永不剔除。
|
|
118
|
+
|
|
119
|
+
token 粒度:英文按词、中文按双字组。旧实现的中文单字粒度下任意扩展
|
|
120
|
+
都摊薄重合度(0.5-0.59 全在阈值下),判据对中文形同虚设。
|
|
121
|
+
"""
|
|
122
|
+
def _tokens(q: str) -> set[str]:
|
|
123
|
+
chars = re.findall(r"[\u4e00-\u9fff]", q.lower())
|
|
124
|
+
words = re.findall(r"[a-zA-Z]+", q.lower())
|
|
125
|
+
return set(words) | {chars[i] + chars[i + 1] for i in range(len(chars) - 1)}
|
|
126
|
+
|
|
127
|
+
def _novelty(tokens: set[str], covered: set[str]) -> float:
|
|
128
|
+
if not tokens:
|
|
129
|
+
return 1.0
|
|
130
|
+
return len(tokens - covered) / len(tokens)
|
|
131
|
+
|
|
132
|
+
anchor = {"direct", "general"}
|
|
133
|
+
unique: list[dict[str, str]] = []
|
|
134
|
+
covered: set[str] = set()
|
|
135
|
+
for sq in sub_queries:
|
|
136
|
+
toks = _tokens(sq["query"])
|
|
137
|
+
if unique and sq.get("strategy") not in anchor \
|
|
138
|
+
and _novelty(toks, covered) < 0.25:
|
|
139
|
+
continue
|
|
140
|
+
unique.append(sq)
|
|
141
|
+
covered |= toks
|
|
142
|
+
return unique
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# 旧名保留给测试与外部 import
|
|
146
|
+
decompose_query = expand_query
|