Skip to content

feat(wiki-mcp): add catalog IDF weighting and ask_hub search_terms query expansion - #256

Open
humandebri wants to merge 3 commits into
mainfrom
feat/hub-router-idf-and-query-expansion
Open

humandebri wants to merge 3 commits into
mainfrom
feat/hub-router-idf-and-query-expansion

Conversation

@humandebri

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #253 (fix/hub-router-katakana-and-multilingual-fallback). Addresses vocabulary mismatch and high-frequency generic-term over-matching in ask_hub without per-dataset hardcoding or extra LLM calls:

  1. Optional search_terms parameter on ask_hub (zero-cost caller LLM query expansion):

    • Added search_terms?: string[] (max 12 terms) to askHubInputSchema in workers/wiki-mcp/src/index.ts and AskHubInput in workers/wiki-mcp/src/hub-router.ts.
    • Guides calling agents to expand colloquial / everyday wording into canonical domain terms, statutes, technical concepts, or multilingual synonyms.
    • Merged without double-counting into candidate routing (mergeQueryTokens), prioritized in queryContext entities, and tried first on zero-hit fallback so article-level terms are not shadowed by broader DB-name tokens.
  2. Catalog IDF weighting (catalogIdfWeight):

    • Applies smooth bounded IDF damping (0.2 + 0.8 * log(N / df) / log(N) for N >= 3, 1.0 for df <= 1 or N < 3) to both ASCII (postingsList.length) and CJK (tokenTouched.length) matches in O(1) time and O(1) extra space.
    • Prevents universal boilerplate / generic catalog terms (e.g. 日本, 会社, hub:dataset) from falsely attracting colloquial queries while preserving 100% weight for unique domain terms and keeping the 1,000-DB benchmark >500x faster than naive scan.

Verification

  • tsc --noEmit: 0 errors.
  • vitest run: 18/18 files, 343/343 tests passed (including updated 80-trial randomized EN/CJK property test with IDF parity, IDF damping + search_terms unit tests, MCP schema verification, and 525.0x inverted-index benchmark speedup).
  • Live E2E practical test against 8 public IC Hub DBs (6 colloquial queries with zero legal jargon): 6/6 routed to the exact expected DB at rank fix/mirror link normalization #1.

@humandebri
humandebri force-pushed the feat/hub-router-idf-and-query-expansion branch 2 times, most recently from 040484f to 87f97b2 Compare December 3, 2026 06:08
@humandebri
humandebri force-pushed the feat/hub-router-idf-and-query-expansion branch from 87f97b2 to 2c50c41 Compare December 3, 2026 06:37
@humandebri
humandebri deleted the branch fix/hub-router-katakana-and-multilingual-fallback December 3, 2026 06:37
@humandebri humandebri closed this Dec 3, 2026
@humandebri humandebri reopened this Dec 3, 2026
@humandebri
humandebri changed the base branch from fix/hub-router-katakana-and-multilingual-fallback to main December 3, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant