Languages
The assistant replies in English (en), Arabic (ar), or European Portuguese
(pt, pt-PT).
Audience: developers serving a multilingual audience. What you will accomplish: control reply language and understand auto-detection and RTL.
Set the language
Pass lang in the request body (see Chatting):
| Value | Behavior |
|---|---|
auto (default) | Detects the language of the input. |
en | Forces English. |
ar | Forces Arabic. |
pt | Forces European Portuguese (pt-PT spelling and vocabulary). |
Setting lang explicitly bypasses detection entirely — use it when you want certainty.
How auto-detection works
When lang is auto, a three-tier hybrid resolves the language:
- Arabic — detected by Unicode script (instant and definitive).
- Portuguese heuristic — distinctive diacritics (
ã õ á é í ó ú â ê ô à ç) are decisive; otherwise a Portuguese stopword-frequency ratio decides for sentences of at least four words. A single shared token (e.g. English “no”, also a Portuguese stopword) cannot flip the verdict. - Statistical fallback — only short, unaccented, genuinely ambiguous fragments fall through to an EN/PT statistical model. On any error it defaults to English, so a request never fails on detection.
The resolved language is returned in meta.lang.
Right-to-left (Arabic)
Arabic replies are right-to-left. In your UI, set the text direction for Arabic answers so they render correctly:
<div dir="rtl" lang="ar">…answer…</div>The reference web client in web/ renders RTL for Arabic automatically; mirror that in
your own UI by switching dir based on meta.lang.
Multi-turn follow-ups
Keep a stable X-User-Id and ask naturally. Before retrieval, the bot condenses
elliptical follow-ups into a standalone search query, so “and what about damaged items?”
resolves its pronouns against the prior turns and retrieves the right documents. This is
automatic on multi-turn chats and skipped on the first turn.
Verify your result
- Verify: An Arabic question returns an Arabic answer with
meta.lang=ar(whenauto). - Verify: Setting
lang: "pt"returns European Portuguese regardless of the input language. - Verify: A follow-up like “and for damaged items?” retrieves the right documents when the
X-User-Idis stable across turns.
Common mistakes and fixes
- Mixed-language input returns the wrong language → set
langexplicitly instead of relying onautofor short or code-switched inputs. - Follow-up retrieves nothing relevant → confirm you reused the same
X-User-Id; memory (and therefore follow-up condensing) is scoped per id and expires after the TTL. See Conversation memory.
Related next steps
- Control language per request in Chatting.
- Understand the memory TTL behind follow-ups in Conversation memory.