RAG with Thai Documents: Common Problems and How to Fix Them

Plants.work · · upskilling
RAG with Thai Documents: Common Problems and How to Fix Them

Thai has no spaces between words, so RAG fails in ways English doesn't. Common problems from word segmentation and chunking to transliterated terms, with fixes.

Your team followed an English RAG tutorial step by step, and it answers well on English documents. But once you load a Thai handbook, search starts missing things and answers land on the wrong topic. This isn't because the team did something wrong. It's because of the nature of the Thai language itself, which most tools were not originally designed for.

Why Thai is hard for RAG

The paper PyThaiNLP: Thai Natural Language Processing in Python (2023) explains that Thai, in its common written form, runs on without spaces or marks between words or between sentences. Word and sentence boundaries are therefore unclear, and grammar alone often cannot resolve the ambiguity. Systems designed around languages with spaces between words stumble at the very first step.

Problem 1: Word segmentation

Keyword search such as BM25 needs to know what a "word" is. If the system can't segment Thai, a query like "how many days of maternity leave" may be treated as one block of text and fail to find the document that uses a more formal phrase for leave to give birth.

Fixes

Problem 2: Chunks cut mid-sentence

Many text splitters use full stops or line breaks as cut points, but Thai does not use full stops to end sentences, and it uses spaces both to end sentences and to separate phrases. Chunks are therefore easily cut in the middle of an idea.

Fixes

Problem 3: Transliterations and mixed languages

Thai company documents often mix several spellings of "email" in Thai script with the English word "email", or use "OT" alongside the Thai term for overtime pay. Employees ask one way while documents say it another.

Fixes

Problem 4: Garbled text from PDFs

With some Thai PDFs, extracted text can have vowels and tone marks in the wrong positions or odd characters, depending on the font and how the file was created. Scanned files must first go through OCR that can read Thai.

Fixes

An example from a Thai organisation

A private hospital built RAG so nurses could search internal guidelines. In the first round, a nurse typed the everyday Thai phrase for "patient is allergic to a drug, how do I report it?", but the system found nothing, because the documents used the formal term for "adverse drug reaction" and the abbreviation "ADR". The team added a glossary mapping ward language to formal terms, added a Thai word segmenter to keyword search, and chunked documents by heading instead of character count. Search results improved without changing the language model at all.

Watch out for

Most tools weren't designed for Thai, so we have to design for Thai ourselves.

How to get started

  1. Collect at least 30 real Thai questions from employees, including casual phrasing and transliterated terms.
  2. Check the quality of text extracted from PDFs before doing anything else.
  3. Choose multilingual embedding models and compare them using that question set.
  4. Add a Thai word segmenter and a company glossary to keyword search.
  5. Re-measure after every change, and add missed questions to the test set.

If many of your documents are scans, read Document AI: extracting data from PDFs and scanned documents next. And to learn which AI models handle Thai well, read Claude AI and the Thai language on Plants.work.