Using OpenThai 2.0 Legal with RAG
At the end, OpenThai 2.0 Legal answers from the Thai statutes you index and cites the sections it used. With the right sections in the prompt it scores 0.99 citation F1, against 0.07 to 0.40 from memory alone. The hosted API already retrieves from a 39-law statute corpus by default; this guide is for your own documents or your own copy of the open weights.
Without retrieval the model answers from memory and may cite the wrong section or miss one. With retrieval it cites only the sections retrieval supplies, so a wrong retrieval gives a wrong answer. A qualified professional should check every citation against current law before it is relied on.
You need: Docker, and a free iApp API key (register, then API Keys → Create New API Key).
Get the statutes
- Office of the Council of State: the authoritative current text of Thai codes and Acts (ประมวลกฎหมาย, พ.ร.บ.).
- WangchanX-Legal-ThaiCCL-RAG (VISTEC / AIResearch, open licence): Civil and Commercial Code questions paired with the sections that answer them.
- NitiBench (VISAI-AI, MIT): the Thai legal benchmark the model is evaluated on, for scoring your pipeline end to end.
Split the statutes by section (มาตรา), one per chunk, with law_name and section as metadata: the format the model's citations were trained on.
Option A: Open WebUI
Open WebUI gives a multi-user chat app with retrieval built in, in about 15 minutes.
1. Run Open WebUI
docker run -d -p 3000:8080 \
-v open-webui:/app/backend/data \
--name open-webui --restart always \
ghcr.io/open-webui/open-webui:main
Open http://localhost:3000 and create the admin account.
2. Connect the model
In Admin Panel → Settings → Connections, add an OpenAI API connection with these values and save; openthai2.0-legal appears in the model selector.
API Base URL https://api.iapp.co.th/v3/llm/openthai2p0-legal
API Key your iApp API key
3. Add the statutes
In Workspace → Knowledge, choose + Create a Knowledge base (for example ประมวลกฎหมายแพ่งและพาณิชย์) and upload the statute files, one section per chunk.
4. Ask
In a chat with openthai2.0-legal, type #, pick the knowledge base and ask in Thai; the answer cites the retrieved sections.
นาย ก. ขับรถประมาทชนรถนาย ข. ต้องรับผิ ดตามกฎหมายใด
Option B: OpenThaiRAG
OpenThaiRAG is the OpenThaiGPT community's open-source RAG framework for Thai (project page): a REST API you integrate yourself, in about an hour.
1. Start it
git clone https://github.com/OpenThaiGPT/openthairag
cd openthairag
docker-compose up -d
2. Point it at the model
Set its LLM backend to the hosted endpoint below with your API key, or to your own vLLM server running the open weights.
https://api.iapp.co.th/v3/llm/openthai2p0-legal
3. Index the statutes
Put the statutes in /docs as .txt files and run the indexer.
4. Ask
curl --location 'http://localhost:5000/completions' \
--header 'Content-Type: application/json' \
--data '{"prompt": "ลักทรัพย์ในเวลากลางคืน ผิดมาตราใด", "max_tokens": 2048}'
Next steps
For the most accurate citations in either option, use the JSON citation system prompt on the model page; the model was trained with reinforcement learning on that format. Background is in the launch post. For help with a deployment: sale@iapp.co.th · Discord.