Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

docs(integrations): the lang_guess table must report what current main routes

Aashishb59c32093ae1
diff --git a/docs/langchain.md b/docs/langchain.md
index 9c6f6a34..7ae5d0c4 100644
--- a/docs/langchain.md
+++ b/docs/langchain.md
@@ -501,22 +501,29 @@ Both are per node, like the budgets, and unset means unsent: leave one out and t
`Router(task=...)` / `Router(lang_guess=...)` stays in charge rather than being overwritten with
`None`. `batch()` sends them with every request in the batch, `abatch()` on the same path.
-**What the hint moves, measured.** Sixteen German support queries through `Router._route` on
-`6d942c9` -- routing only, so no checkpoint is loaded and no answer is taken -- counted by which
-checkpoint the decision lands on:
+**What the hint moves, measured.** Sixteen German support queries through `Router.route` on
+`6880462` (0.4.2) -- routing only, so no checkpoint is loaded and no answer is taken -- counted by
+which checkpoint the decision lands on:
| German queries | no hint | `lang_guess="de"` |
|---|---|---|
-| 8 written without umlauts or `ß` | 6 answered on `english` | 8 on `multilingual` |
-| 8 carrying umlauts or `ß` | 2 answered on `english` | 8 on `multilingual` |
-
-Detection is a good guesser when the text gives it letters to work with; `Zahlung fehlgeschlagen`
-brings it to its stated abstention (`"Latin script, language not identified and no non-English
-letters; using default (english)"`), and `Was kostet die MwSt?` to a wrong read (`"English Latin
-text"`). A caller that knows the language from a user id or an `Accept-Language` header knows better
-than that, which is the whole argument for the hint. What is *not* claimed here is what the two
-checkpoints then score on those queries -- that needs weights and a labelled set, and this table is
-about which one answers, not how well.
+| 8 written without umlauts or `ß` | 1 read as English | 0 read as English |
+| 8 carrying umlauts or `ß` | 0 read as English | 0 read as English |
+
+The one miss is `Was kostet die MwSt?`, which detection reads as `"English Latin text"`: an
+abbreviation-heavy short query with no diacritics and no stopword signal. Diacritics settle it on
+their own, so the eight `umlauts or ß` queries all leave `english` without any help from the hint.
+Plain German prose that detection cannot place does not reach the English checkpoint either any
+more -- an undecided Latin script now abstains to the multilingual one (`"Latin script, language
+not identified and no non-English letters; using default (multilingual)"`, asserted in
+`tests/test_router.py`), so the residual gap the hint closes is the false-English read, not the
+undecided one. A caller that knows the language from a user id or an `Accept-Language` header still
+knows better than any guess, which is the argument for the hint. What is *not* claimed here is what
+the two checkpoints then score on those queries -- that needs weights and a labelled set, and this
+table is about which one answers, not how well.
+
+`tests/test_langchain.py` re-runs these sixteen queries against the live router and asserts the
+hint half of the table, so the numbers above cannot quietly go stale behind this paragraph.
**A recorded `before`.** On `6d942c9`, in real (installed `langchain-core`) mode, a node built with
both hints and a budget, answering through a runner that prints what `predict` received:
diff --git a/docs/llamaindex.md b/docs/llamaindex.md
index 1c5e2a24..b1aaf8e6 100644
--- a/docs/llamaindex.md
+++ b/docs/llamaindex.md
@@ -217,11 +217,13 @@ workflow rather than waiting for auto task detection to recognise the question i
takes a language code -- or a callable of the query being selected against -- from something that
already knows it, consulted after an explicit `lang` and before core's own script detection; any
non-English code routes to the multilingual checkpoint. A German-documented index is the case the
-hint is for: measured on sixteen German support queries, detection leaves 6 of the 8 written without
-umlauts and 2 of the 8 carrying them on the `english` checkpoint, while `lang_guess="de"` moves all
-16 to `multilingual`. See the [LangChain
-integration](langchain.md#9-which-checkpoint-answers) for that table and its
-reason strings.
+hint is for, but the gap is narrower than it looks: measured on sixteen German support queries
+through `Router.route` on `6880462`, one of the eight written without umlauts reaches `english`
+(`Was kostet die MwSt?`, read as "English Latin text"), and none of the eight carrying umlauts or
+`ß` does -- diacritics settle it, and an undecided Latin script now abstains to `multilingual`
+rather than to `english`. `lang_guess="de"` takes that last one off `english` too. See the [LangChain
+integration](langchain.md#9-which-checkpoint-answers) for that table, its reason strings, and the
+check that re-runs the sixteen queries.
```python
selector = LayaSingleSelector(
diff --git a/tests/test_langchain.py b/tests/test_langchain.py
index 4d60d800..5b1d146f 100644
--- a/tests/test_langchain.py
+++ b/tests/test_langchain.py
@@ -1627,6 +1627,42 @@ except ValueError as exc:
"RouteIgnoringHintsRouter.route" in str(exc), str(exc))
+# The `docs/langchain.md` "What the hint moves, measured" table, re-run against the live router.
+# Routing only: `route` decides without loading a checkpoint, so this costs no weights and no
+# forward pass. The assertion is the guarantee the hint gives -- a caller that says "de" gets the
+# multilingual checkpoint for every one of these. The no-hint column is printed, not pinned: it is
+# the current detection heuristic's behaviour, and a run that fixes #54 should move the print, not
+# turn the suite red.
+from laya.router import Router as _RoutingRouter # noqa: E402
+
+_DE_NO_DIACRITICS = [
+ "Zahlung fehlgeschlagen", "Wo finde ich meine Rechnung", "Ich kann mich nicht anmelden",
+ "Die App startet nicht", "Wie aendere ich meine Adresse", "Bestellung noch nicht angekommen",
+ "Ich brauche eine Kuendigung", "Was kostet die MwSt?",
+]
+_DE_DIACRITIC = [
+ "Rechnung für die MwSt stimmt nicht", "Paßwort zurücksetzen geht nicht",
+ "Größe des Pakets passt nicht", "Kündigung per E-Mail senden",
+ "Gehälter ohne Umlaute im Profil", "Wie viel kostet der Versand heute",
+ "Ich möchte meine Adresse ändern", "Wo muß ich das Formular einreichen",
+]
+_DE_ALL = _DE_NO_DIACRITICS + _DE_DIACRITIC
+_Q_GUESS = {"a": {"type": "noul", "instructions": "Is `text` a support question?"}}
+_rt = _RoutingRouter()
+
+
+def _on_english(texts, **kw):
+ return [t for t in texts if _rt.route({"text": t}, _Q_GUESS, **kw)["model"] == "english"]
+
+
+print("\n lang_guess table, this run (queries read as English):")
+for _label, _qs in (("without umlauts or ß", _DE_NO_DIACRITICS), ("with umlauts or ß", _DE_DIACRITIC)):
+ print(" %-24s no hint %d, lang_guess=\"de\" %d %s"
+ % (_label, len(_on_english(_qs)), len(_on_english(_qs, lang_guess="de")), _on_english(_qs)))
+check("routing/with the de hint no German query is read as English",
+ _on_english(_DE_ALL, lang_guess="de"), [])
+
+
# --------------------------------------------------------------- Summary
print(f"PASS: {len(PASS)}")
print(f"FAIL: {len(FAIL)}")