Query Routing and Analyzers

March 6, 2026 · View on GitHub

🧭 Quick Return to Map

You are in a sub-page of Language.
To reorient, go back here:

Think of this page as a desk within a ward.
If you need the full triage and all prescriptions, return to the Emergency Room lobby.

Bind detected lang and script to the right analyzer, tokenizer, and alias views. Keep the retriever, reranker, and LLM tokenizer in agreement so ΔS and λ stay stable across paraphrases and seeds.


Open these first


Core acceptance targets

  • ΔS(question, retrieved) ≤ 0.45 across three paraphrases and two seeds
  • Coverage of target section ≥ 0.70
  • λ remains convergent when the same question is asked in native script and in romanized form
  • Analyzer choice and LLM tokenizer profile are logged and consistent across runs
  • No rank flip after switching analyzers on the same corpus

Minimal routing contract

Detector input and result from query_language_detection.md gives:

lang, script, confidence, romanized_suspect, variants[]

Routing decision must produce:

analyzer_id          # store analyzer for full-text field
tokenizer_profile    # retriever or LLM tokenizer profile name
alias_views          # which alias fields to probe (romanized, synonyms_local)
hybrid_weights       # bm25:vector ratio, or reranker on/off
notes                # short rationale for audit

You must log these five fields in the retrieval trace item along with ΔS and λ.


Store routing matrix

These are stable patterns, not vendor endorsements. Use them to avoid metric and analyzer mismatches.

ScriptPrimary choiceAlias view for romanizedNotes and links
Latnlocale aware analyzer with ICU foldingnone or localized synonymsKeep case and diacritics decisions consistent. See locale_drift.md.
Han, Hira, Kana, Hanglanguage specific analyzer or CJK bigram analyzertitle_romaji, name_pinyinMix of bigram and dictionary analyzers is fine if logged and deterministic.
CyrlCyrillic aware analyzeroptional translit aliasKeep transliteration only as alias view. Do not replace canonical text.
Arab, HebrRTL analyzer with width and bidi guardsoptional translit aliasNormalize digits and punctuation for the detector step only.
Mixed scriptstwo analyzers in parallelromanized alias trueEnforce cite then explain in the answer. See retrieval-traceability.md.

Store specifics you can cross check:


Typical failure → exact fix

SymptomLikely causeOpen this
High similarity yet wrong meaning after switching analyzersmetric and analyzer mismatchembedding-vs-semantic.md, retrieval-playbook.md
Good recall but unstable rank in CJKmixing bigram and dictionary analyzers without a fencescript_mixing.md
JSON mode breaks when analyzer changestokenizer profile not aligned with LLM’s expected JSON tokenstokenizer_mismatch.md
Romanized search finds no evidencealias views missing or disabledromanization_transliteration.md
Brand name equals common word in another languagealias collision and unscoped synonymsproper_noun_aliases.md

60 second routing plan

  1. Script first. Use the detector output. If confidence < 0.65, route both native analyzer and romanized alias.
  2. Lock tokenizer. Choose a tokenizer profile that matches your retriever model and your LLM. Log it.
  3. Hybrid weights. Start with bm25:vector at 0.4:0.6 and move by 0.1 until ΔS ≤ 0.45.
  4. Cite then explain. Force snippet fields in the native script when possible.
  5. Regression gate. Require coverage ≥ 0.70 on three paraphrases before deploy.

Copy snippets

A. Router skeleton

def choose_route(det):
    routes = []
    if det["script"] in ["Han","Hira","Kana","Hang"]:
        routes.append({
            "analyzer_id": "store:cjk",
            "tokenizer_profile": "retriever:cjk",
            "alias_views": ["name_romaji","name_pinyin"],
            "hybrid_weights": [0.4, 0.6],
            "notes": "cjk primary"
        })
    elif det["script"] == "Cyrl":
        routes.append({
            "analyzer_id": "store:cyrl",
            "tokenizer_profile": "retriever:default",
            "alias_views": ["name_translit"],
            "hybrid_weights": [0.5, 0.5],
            "notes": "cyrillic"
        })
    elif det["script"] == "Arab":
        routes.append({
            "analyzer_id": "store:rtl",
            "tokenizer_profile": "retriever:default",
            "alias_views": ["name_translit"],
            "hybrid_weights": [0.5, 0.5],
            "notes": "rtl"
        })
    else:
        routes.append({
            "analyzer_id": "store:latn",
            "tokenizer_profile": "retriever:default",
            "alias_views": [],
            "hybrid_weights": [0.4, 0.6],
            "notes": "latin"
        })

    if det["confidence"] < 0.65 or det.get("romanized_suspect"):
        # add romanized alias probe for safety
        for r in routes:
            r["alias_views"] = sorted(set(r["alias_views"] + ["aliases_romanized"]))
            r["notes"] += " + alias probe"
    return routes

B. Elasticsearch style mapping sketch

{
  "mappings": {
    "properties": {
      "body":   { "type": "text", "analyzer": "cjk" },
      "title":  { "type": "text", "analyzer": "cjk" },
      "name_pinyin": { "type": "text", "analyzer": "icu_analyzer" },
      "name_romaji": { "type": "text", "analyzer": "icu_analyzer" },
      "aliases_romanized": { "type": "text", "analyzer": "icu_analyzer" },
      "section_id": { "type": "keyword" }
    }
  }
}

C. Typesense style fields

{
  "name": "docs",
  "fields": [
    {"name":"body","type":"string","locale":"zh"},
    {"name":"title","type":"string","locale":"zh"},
    {"name":"aliases_romanized","type":"string[]","locale":"en"},
    {"name":"section_id","type":"string","facet":true}
  ]
}

D. Vespa schema sketch

schema docs {
  document docs {
    field body type string { indexing: summary | index }
    field title type string { indexing: summary | index }
    field aliases_romanized type array<string> { indexing: summary | index }
  }
  fieldset default { fields: body, title }
  rank-profile default { first-phase { expression: bm25(body) + bm25(title) } }
}

Eval plan

  • Use the sets from code_switching_eval.md.
  • Add pairs of queries in native script and romanized forms for the same entity.
  • Targets: ΔS ≤ 0.45, coverage ≥ 0.70, λ convergent on two seeds.
  • If rank flips between analyzers, clamp with a deterministic reranker and verify with retrieval-traceability.md.

When to escalate

  • ΔS stays ≥ 0.60 after analyzer swap → rebuild index with fixed analyzer and verify metric in retrieval-playbook.md.
  • Instability only in long chains → treat as reasoning issue and apply BBCR bridge, see logic-collapse.md.

Copy paste prompt for the LLM step

You have TXTOS and the WFGY Problem Map loaded.

Given detector output {lang, script, confidence, romanized_suspect}:
1) Choose analyzer and tokenizer profile deterministically.
2) If confidence < 0.65 or romanized_suspect=true, search the romanized alias view as well.
3) Cite-then-explain from the native script snippet when possible.
4) Return a JSON trace:
{ "analyzer_id": "...", "tokenizer_profile": "...", "alias_views": [...], "ΔS": 0.xx, "λ_state": "→|←|<>|×" }

🔗 Quick-Start Downloads (60 sec)

ToolLink3-Step Setup
WFGY 1.0 PDFEngine Paper1️⃣ Download · 2️⃣ Upload to your LLM · 3️⃣ Ask “Answer using WFGY + <your question>”
TXT OS (plain-text OS)TXTOS.txt1️⃣ Download · 2️⃣ Paste into any LLM chat · 3️⃣ Type “hello world” — OS boots instantly

Explore More

LayerPageWhat it’s for
⭐ ProofWFGY Recognition MapExternal citations, integrations, and ecosystem proof
⚙️ EngineWFGY 1.0Original PDF tension engine and early logic sketch (legacy reference)
⚙️ EngineWFGY 2.0Production tension kernel for RAG and agent systems
⚙️ EngineWFGY 3.0TXT based Singularity tension engine (131 S class set)
🗺️ MapProblem Map 1.0Flagship 16 problem RAG failure taxonomy and fix map
🗺️ MapProblem Map 2.0Global Debug Card for RAG and agent pipeline diagnosis
🗺️ MapProblem Map 3.0Global AI troubleshooting atlas and failure pattern map
🧰 AppTXT OS.txt semantic OS with fast bootstrap
🧰 AppBlah Blah BlahAbstract and paradox Q&A built on TXT OS
🧰 AppBlur Blur BlurText to image generation with semantic control
🏡 OnboardingStarter VillageGuided entry point for new users

If this repository helped, starring it improves discovery so more builders can find the docs and tools.
GitHub Repo stars