Skip to content
Nelson D’SouzaEmail me
Writing

Localise the data layer with the UI

Localisation checks the screen while the components under it still assume English. Hindi got zero passages. Why that stays quiet, and the fix measurement chose.

By · · 12 min read

  • RAG
  • Multilingual
  • AI Safety
In this note
  1. The same question, twice
  2. The trace data narrowed the boundary
  3. An English floor under a Hindi question
  4. Three fixes that measurement rejected
  5. Lower the threshold
  6. HyDE
  7. Detect the script instead of reading the preference
  8. Translate the query, keep the question
  9. The instrument that said the fix had failed
  10. The crisis check spoke only English
  11. Why bare nouns are the wrong fix
  12. The regex that read perfectly and matched nothing
  13. Lists of languages are policy
  14. Four things to run in a language before offering it

Theo Scriptura, my Bible study app, has a feature called Ask that answers questions from Scripture. A reader asks; it retrieves passages from the Bible and from commentary and writes an answer that cites them. Over several releases it was localised into Hindi, Spanish, Turkish and Indonesian: the interface strings, the four starting questions on the page, and the language of the answer itself. Every screen looked right in every language. The library underneath is 242,284 chunks of English commentary and theology, beside an English Bible text. It always was.

For Hindi readers, Ask answered its own starting questions fluently, in Hindi, by saying it didn’t have enough information. Nothing reported it. Localisation was checked where it shows, in the strings and the language of the answer, and nothing on screen says which language the corpus speaks. Three obvious fixes failed when measured. The one that shipped translates the retrieval query once, at the boundary, and it applies to any search or RAG feature whose underlying corpus is monolingual.

The same question, twice#

The measurement that exposed it was the same question asked twice against the live index:

QueryPassages retrieved
“What does the Bible say about anxiety?”5
The same question in Hindi0

Ask refuses to write an answer from fewer than two retrieved chunks. So zero passages produced a “knowledge gap” answer rather than an invented one. That was the one piece of luck. Hindi readers got an honest refusal.

The sharpest test used no query I’d invented. It used the four Hindi starting questions the page offers, the ones readers actually tap. Every one of them retrieved 0 passages and resolved 0 Bible references. Of the 7 non-Latin-script questions in the traces, 5 came from tapping a starting question.

Then I ran the anxiety question in Spanish and Indonesian:

LanguagePassagesOverlap with the English result
Indonesian54 of 5
Spanish44 of 5
Hindi0none

A Cyrillic-script question I found in the logs scored a top similarity of 0.4588 against a floor of 0.4, and survived by a hair.

That gradient is why it lasted. Latin-script languages degraded partially and quietly. Devanagari didn’t degrade; it vanished. If I’d checked one “representative” non-English language, I would have reported a feature that mostly worked. Each row is a single question, so the table shows the shape of the failure. It doesn’t measure a rate per language.

The trace data narrowed the boundary#

Read from the starting questions alone, the symptom looked like every Hindi question failing. The trace data said otherwise. Five of the seven non-Latin questions in the traces had retrieved 49 to 63 passages each, with a top score of exactly 1. A score of 1 is the signature of an exact match. Every one of those five contained a Bible reference written in Latin script, such as “John 1”, left over from an older version of the starting questions.

So the accurate boundary was narrower and stranger: a Hindi question retrieved nothing unless it happened to contain a Latin-script reference.

An English floor under a Hindi question#

Vector search turns the question into an embedding (a list of numbers that places text near text with similar meaning) and returns the corpus chunks whose embeddings are close enough. “Close enough” is a similarity floor, here 0.4, tuned for English questions against English passages.

In this embedding model, cross-language similarity is far weaker than same-language similarity. Spanish and Indonesian landed near the floor and partly above it; a Devanagari question landed below it entirely. My best explanation is shared surface: Spanish and Indonesian write in English’s alphabet and share names, cognates and subword pieces with it, and Hindi in Devanagari shares almost none. The Cyrillic question surviving at 0.4588 says script isn’t the whole story, and a handful of single questions can’t settle it. The floor is what turned “weaker” into “nothing”.

Retrieval is hybrid, and its other half couldn’t help either. The full-text search parses the question with Postgres’s English text-search configuration, and no English passage contains a Devanagari word. So search did its job: it returned an empty list, which is a legitimate answer to “what matches this?” The gap detector did its job on a true premise.

There was one more path that should have caught it. Retrieval also extracts Bible references from the question and fetches those chapters directly, by exact match. That’s what rescued the five questions above. But reference extraction was English-only too:

QuestionVector hitsReferences found
“John 1 का मुख्य संदेश क्या है?”10["John 1"]
“यूहन्ना 1 का मुख्य संदेश क्या है?”0[]

“यूहन्ना” is John. A reader who writes the book’s name in their own language got nothing from any path. Three paths shared one assumption, so they failed together.

The multilingual Ask pathArchitecture diagram with 7 nodes, 7 connections. Each step is listed as text below.Reader's question:crisis patterns peroffered languageCrisis resourcesTranslate the queryto EnglishHybrid search +references, EnglishlibraryAt least 2chunks?Answer in thereader's languageKnowledge-gap replycrisisnot EnglishEnglishor original on failureyesno
  1. Reader's question: crisis patterns per offered language to Crisis resources: “crisis”
  2. Reader's question: crisis patterns per offered language to Translate the query to English: “not English”
  3. Reader's question: crisis patterns per offered language to Hybrid search + references, English library: “English”
  4. Translate the query to English to Hybrid search + references, English library: “or original on failure”
  5. Hybrid search + references, English library to At least 2 chunks?
  6. At least 2 chunks? to Answer in the reader's language: “yes”
  7. At least 2 chunks? to Knowledge-gap reply: “no”
Fig. 1 The multilingual Ask path The safety check reads the reader's own words. Only the search query is translated, and the answer goes back in the reader's language. Translation failure falls back to the original query.

Three fixes that measurement rejected#

Each had a plausible reason to work, and each was checked against data before it shipped.

Lower the threshold#

The obvious move. If Hindi questions land below 0.4, let more through. On the Hindi anxiety question:

FloorTop result
0.4 (live)nothing
0.3“Darwiniana”
0.2“Bildad: Man Cannot Be Righteous”

That trades no context for wrong context. A fluent Hindi answer grounded in Darwin is worse than an honest “I don’t have enough on this”, because the reader can’t tell the difference. The floor was the one part working as intended.

HyDE#

HyDE (hypothetical document embeddings) has the model write a plausible answer first and searches with that instead of the question. It returned 0 results with it on and with it off. The hypothetical answer is written in the question’s language, so it lands in the same empty neighbourhood.

Detect the script instead of reading the preference#

This one was tempting, because it’s free and would also catch languages the product doesn’t offer. Any question in a non-Latin script gets translated.

Before building it, I read every non-Latin question in the store. There were 9 among 9,092. Three of the nine were English: readers asking about a passage and quoting the Greek word in it. Script detection would have translated those questions and destroyed the one word each reader was asking about. Its errors land on the most careful questions on the platform. The reader’s chosen interface language is the reliable signal, so that’s what the fix uses.

Four fixes and what each measuredFlowchart with 9 nodes, 8 connections. Each step is listed as text below.Hindi retrieves 0passagesFloor 0.3HyDEDetect scriptTranslate by UIlanguageDarwinianaStill 0Mangles Greekquotes10, 10, 8, 10rejectedrejectedrejectedshipped
  1. Hindi retrieves 0 passages to Floor 0.3
  2. Hindi retrieves 0 passages to HyDE
  3. Hindi retrieves 0 passages to Detect script
  4. Hindi retrieves 0 passages to Translate by UI language
  5. Floor 0.3 to Darwiniana: “rejected”
  6. HyDE to Still 0: “rejected”
  7. Detect script to Mangles Greek quotes: “rejected”
  8. Translate by UI language to 10, 10, 8, 10: “shipped”
Fig. 2 Four fixes and what each measured Three plausible fixes failed on real data. Translating at the boundary moved all four Hindi starters off zero (10, 10, 8, 10 passages) and returned relevant passages on the live anxiety check.

Translate the query, keep the question#

Translate the retrieval query into English. Keep the reader’s question for the answer. The module is small, and two details in it are the whole design.

export async function translateRetrievalQueryToEnglish(
  query: string,
  language: ProductLanguage | null | undefined
): Promise<string> {
  if (!language || language === DEFAULT_PRODUCT_LANGUAGE) return query
  if (!query.trim()) return query
  try {
    const response = await getAskHydeModel().invoke([
      { role: "system", content: SYSTEM_PROMPT },
      { role: "user", content: query },
    ])
    const text = typeof response.content === "string" ? response.content.trim() : ""
    if (!text || text.length > MAX_TRANSLATED_QUERY_LENGTH) return query // 300 chars
    return text
  } catch (error) {
    console.error("[RetrievalQueryLanguage] Translation failed, using the original query:", error)
    return query
  }
}

The call goes through getAskHydeModel(), the model the HyDE experiment above used. HyDE was rejected as a search strategy, and this module reuses its model for one short call.

English never enters it. The caller skips the module for English, so English questions get no extra model call, no added latency, no added cost and no change in behaviour. The test for that uses a sentinel: the mocked model would return a clearly different string, and the test asserts it never appears. A call count isn’t enough here. An unconfigured mock throws, the fallback returns the original query, and “unchanged” passes whether the module was skipped or failed.

Every failure returns the original query. An error, an empty reply, a non-string, or a translation over 300 characters falls back to the untranslated text—and while a thrown error is logged, exceeding the 300-character cap falls back silently. Likewise, because routing follows the UI preference rather than script detection, query/UI language mismatches aren’t translated. That reproduces the old behaviour for these questions, so the worst case of the fix is the status quo. The translation prompt also asks for book names in their standard English form, so “यूहन्ना 1” becomes “John 1”.

Translation fixed every path at once, because full-text search and reference extraction run on the same query. The query now arrives in the language every downstream component was written for.

After the fix, the four Hindi starting questions retrieved 10, 10, 8 and 10 passages, and two of them now resolve a Bible reference. Indonesian matched the English result in full. In production, tapping the Hindi anxiety suggestion came back in Hindi with eight sources, four from Scripture and four from theologians. Precision wasn’t audited across the other three Hindi starters, and Turkish retrieval wasn’t measured yet.

A change to an input is complete only when it reaches every consumer of that input, and this one had two. The request runs two retrievals, and the second one, for commentary, embeds the question rather than the query. The first version of the fix translated one and left the other in Hindi, inside the same file. The nearest consumer is the easiest one to miss, so the rule in the notes is to find every caller, including the ones in the file already open.

The cost is one short model call, about a hundred tokens, on non-English questions that miss the answer cache, which the module’s own notes put at under 1% of traffic. Retrieval waits for it, so those questions also pay its latency. The HyDE call that shares its model races a timeout; this call has none of its own, so a slow reply holds up retrieval instead of falling back to the original query. What it doesn’t solve: the corpus is still English, so every source an answer cites is an English text. Whether each of those sources is what its label says is a separate audit, the subject of Grounding is a supply chain.

The structural alternative, and the obvious objection, is a multilingual embedding model. That would mean re-embedding the whole library and re-tuning the floor, and it would still leave full-text search, reference extraction and the reranker, an English-trained cross-encoder, reading Hindi. Translating the query reaches all of them for one call.

The instrument that said the fix had failed#

To confirm the fix, I queried the trace table. The chunk counts for the answer I had just watched cite eight sources were all 0.

They were 0 in all 11,958 rows ever written. Eleven of fourteen columns added for retrieval tracing were written by nothing and read by nothing. The working numbers lived in a JSON column next to them. A dead column doesn’t look missing. It looks like a measurement, and for a moment it was evidence that a visibly working fix had failed. The zeros described the tracing code.

The crisis check spoke only English#

Retrieval wasn’t the first component in this path found assuming English. A day earlier, the most serious one had turned up. Ask checks every question for signs that the reader is in crisis, and when it finds them, it answers with care and helpline resources instead of a Bible study answer.

That check matched English only. Measured against the deployed module, an explicit English statement was detected. The same intent in Hindi, Indonesian, Spanish and Turkish was not. Neither was “I am thinking about ending my life” in English, because the pattern was /end (my|it all)/, which needs a space straight after “end”. A localisation review turned out to be the cheapest moment to re-read the original patterns too.

Why bare nouns are the wrong fix#

The obvious fix is to add each language’s word for suicide. The code says why that’s wrong. Crisis patterns run before the academic-context check, deliberately, because they are too important to skip, and that check only ever guards the milder topics. So nothing downstream keeps a theological question out of the crisis path. A reader asking what the Bible says about suicide, in Indonesian, would get a crisis response to a study question.

The module already had a rule: first-person phrasing is the strongest indicator of personal distress. So each language got first-person phrases, the equivalents of “I want to end my life” and “I don’t want to live”. A study question uses the bare noun and doesn’t match. Verified in both directions: 14 crisis phrases detected, and 4 theological questions in the same languages not treated as crisis. (English still matches the bare word suicide, an older choice for recall that this change left alone, so an English study question on the subject does get the care response.)

A crisis check for every offered languageFlowchart with 7 nodes, 7 connections. Each step is listed as text below.Reader's question,as writtenCrisis patternin any offeredlanguage?Care response withhelplinesAcademicquestion?Mildersensitive-topicchecksTopic-specificresponseNormal answer pathyesnoyesnomatchno match
  1. Reader's question, as written to Crisis pattern in any offered language?
  2. Crisis pattern in any offered language? to Care response with helplines: “yes”
  3. Crisis pattern in any offered language? to Academic question?: “no”
  4. Academic question? to Normal answer path: “yes”
  5. Academic question? to Milder sensitive-topic checks: “no”
  6. Milder sensitive-topic checks to Topic-specific response: “match”
  7. Milder sensitive-topic checks to Normal answer path: “no match”
Fig. 3 A crisis check for every offered language Crisis patterns are checked first and never skipped, so their precision has to come from the patterns themselves. First-person phrasing is what separates a reader in distress from a reader studying a topic.

It shipped before a native speaker had reviewed it, and the commit said so. The asymmetry decided that. Detection in these languages was zero, so an imperfect pattern could only improve on it. Its failure mode is a reader shown helpline resources they didn’t need. The failure mode it removes is someone in crisis receiving a Bible answer. Native speakers have since reviewed the patterns.

The regex that read perfectly and matched nothing#

This is a known JavaScript trap, and it survives review because the pattern reads correctly. The first Turkish pattern started with \b, a word boundary, followed by a word beginning with “ö”. It never matched a real phrase. In JavaScript, \b is ASCII-only: it needs an ASCII word character on one side, and “ö” isn’t one. So /\bö/ can never match at the start of a word, which is the only place it was meant to. The fix was to remove the leading \b, so /\bö/ became /ö/, which matches at the “ö” itself. A test now pins every phrase in every offered language, plus the theological questions that must not trigger. It was shown failing against the English-only patterns first.

Lists of languages are policy#

One layer up, the same class of bug was hiding in plain arrays. The product has one policy for which languages each surface offers. Six places held their own copy of part of it, mostly ["hi", "es"], and went stale when Turkish and Indonesian were added. A reader whose stored preference was Turkish or Indonesian was never redirected to their language on the blog, and silently got English.

Typecheck was green throughout, and the reason is worth knowing. If Lang is "hi" | "es" | "id", then const xs: Lang[] = ["hi", "es"] is legal TypeScript: an array of a union doesn’t have to contain every member. A Record<Lang, string> does. The compiler names every missing key. That’s why the table of language names had its Indonesian entry and none of the arrays did. The guarantee has a limit, though: a Record is only exhaustive over a union of keys. The Indonesian book-name table is a Record<string, string>, so it type-checked while missing the singular “Psalm”, the spelling behind 247 passages of the plan corpus. Completeness there needs a data test that compares key sets.

The fix derives every list from the policy, and splits it into two questions that had been conflated. Surface asks which languages a page’s interface is translated into: /ask and /discover serve all four. Coverage asks which languages the content exists in. Measured over 72 published posts:

SpanishHindiIndonesianTurkish
72/7272/7271/721/72

So the blog index offers Spanish and Hindi, and Indonesian is one post short. Offering Turkish would drop a reader into English on 71 of 72 posts.

One language policy, two questionsArchitecture diagram with 6 nodes, 5 connections. Each step is listed as text below.PRODUCT_LANGUAGE_SURFACESSurface: is theinterface translated?Coverage: does thecontent exist?Ask and DiscoverpagesCache, scripts, SQLparameterBlog index
  1. PRODUCT_LANGUAGE_SURFACES to Surface: is the interface translated?
  2. PRODUCT_LANGUAGE_SURFACES to Coverage: does the content exist?
  3. Surface: is the interface translated? to Ask and Discover pages
  4. Surface: is the interface translated? to Cache, scripts, SQL parameter
  5. Coverage: does the content exist? to Blog index
Fig. 4 One language policy, two questions Every list asks the policy instead of holding a copy. Interface pages ask which languages the surface is translated into; content pages ask which languages the content actually exists in.

Postgres can’t read a TypeScript policy, so any language list written in SQL is a second source of truth by construction. The SQL function now takes the list as a parameter.

Four things to run in a language before offering it#

Interface language and corpus language are independent, and only one of them shows up in a screenshot. A feature that invites a new audience inherits every check written for the old one. Most of the failures above would have shown up in one of four runs in the new language, made against the real system rather than looked at on screen:

  • the page’s own starting questions, through retrieval, counting passages and resolved references
  • a reference written with the book name in that language
  • the crisis phrases and the theological questions that must not trigger, against the deployed module
  • every list of languages, checked against the policy it should derive from

Built in: Theo Scriptura

All writing