🔗 Using OpenThai 2.0 Legal with RAG
The bare model is only half the system. OpenThai 2.0 Legal scores near-perfect (0.99 citation F1) when the right law sections are in the prompt — but closed-book answers come from model memory and can be wrong or incomplete. For real legal work, always pair it with retrieval. Our free hosted API already ships with RAG built in (hybrid search over a 39-law statute corpus, on by default) — this guide is for when you self-host the open weights and want the same grounding on your own infrastructure. Two ways, each under an hour.
Without retrieval (RAG), the model answers from knowledge stored in its weights. It may cite the wrong section or miss an applicable one, so every answer must be checked against the statute.
With retrieval (RAG), the model cites only the sections your retrieval system supplies. Accuracy therefore depends primarily on the quality of that retrieval — if the wrong sections are retrieved, the answer will follow them.
In both cases the model's output is decision support, not legal advice. A qualified professional should verify every citation against the current law before it is relied upon.
📚 Recommended Thai legal datasets
Good RAG starts with a good corpus. These are open, Thai, and legal-specific:
| Dataset | What it contains | License |
|---|---|---|
| WangchanX-Legal-ThaiCCL-RAG (VISTEC / AIResearch) | Thai Civil & Commercial Law Q&A built for RAG training and evaluation — queries paired with the exact supporting sections | Open (see card) |
| NitiBench (VISAI-AI) | The Thai legal benchmark this model is evaluated on — great for measuring your own RAG pipeline end to end | MIT |
| Thai statutes — Office of the Council of State | The authoritative source of current Thai statutory text (ประมวลกฎหมาย, พ.ร.บ.) for building your retrieval corpus | Public sector |
Tip: chunk statutes by section (มาตรา), not by fixed character count — one มาตรา per chunk with law_name + section metadata is exactly the format the model's citation contract expects.
Option A — Open WebUI (the most popular self-hosted LLM UI)
Open WebUI (~110k GitHub stars) is the fastest way to get a chat-with-your-documents interface with built-in RAG ("Knowledge"), user management, and OpenAI-compatible connections.

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 OpenThai 2.0 Legal
Get a free iApp API key first: register → API Keys → Create New API Key.
- Go to Admin Panel → Settings → Connections
- Under OpenAI API, click + to add a connection:
- API Base URL:
https://api.iapp.co.th/v3/llm/openthai2p0-legal - API Key: your iApp API key
- API Base URL:
- Save — the model
openthai2.0-legalappears in the model selector
Our gateway reads the key from either the Authorization: Bearer header (which Open WebUI sends) or an apikey header — both work.
3. Build your legal Knowledge base
- Go to Workspace → Knowledge → + Create a Knowledge base (e.g. "ประมวลกฎหมายแพ่งและพาณิชย์")
- Upload your statute files — ideally one มาตรา per chunk (see dataset tip above)
- In a chat with
openthai2.0-legal, type#and select your Knowledge base — or attach it permanently to a custom model in Workspace → Models
4. Ask, grounded
Open WebUI retrieves the relevant sections and injects them into the prompt — exactly the "open-book" setting where this model scores 0.99. Ask in Thai:
นาย ก. ขับรถประมาทชนรถนาย ข. ต้องรับผิดตามกฎหมายใด
The answer now cites the retrieved sections rather than relying on memory.
Option B — OpenThaiRAG (Thai-native RAG framework)
OpenThaiRAG by the OpenThaiGPT community (project page) is an open-source RAG framework built specifically for Thai: Milvus vector database + BAAI/bge-m3 embeddings (excellent Thai support) + vLLM serving.
git clone https://github.com/OpenThaiGPT/openthairag
cd openthairag
docker-compose up -d
Index your Thai legal documents (place .txt files in /docs, then run the indexer), and query:
curl --location 'http://localhost:5000/completions' \
--header 'Content-Type: application/json' \
--data '{"prompt": "ลักทรัพย์ในเวลากลางคืน ผิดมาตราใด", "max_tokens": 2048}'
Point its LLM backend at OpenThai 2.0 Legal — either our hosted endpoint (https://api.iapp.co.th/v3/llm/openthai2p0-legal with your API key) or your own vLLM serving the open weights — and both retrieval and generation run on Thai-optimized components end to end.
Which one should I pick?
| Open WebUI | OpenThaiRAG | |
|---|---|---|
| Best for | Teams that want a polished chat UI today | Builders who want a Thai-native pipeline they control |
| Retrieval | Built-in Knowledge (managed for you) | Milvus + BGE-M3 (tunable) |
| Effort | ~15 minutes | ~1 hour |
| Interface | Full web app, multi-user | REST API you integrate yourself |
For maximum citation accuracy in either stack, use the JSON citation system prompt from the model page — the model was RL-trained on exactly that contract.
Next steps
- Model page & live demo: OpenThai 2.0 Legal
- Launch story: blog post
- Evaluate your pipeline: run NitiBench against your RAG end to end
- Need help deploying? sale@iapp.co.th · Discord