Wish
Nakthong
03 / 07

Thai RAG with Evaluation

Thai question answering over 40 Wikipedia articles, built so that its quality can be measured instead of judged from a few demo questions.

Back to projects
  • 80 / 80

    questions where Gemini embeddings put the source passage in the top 3

  • 4 of 80

    questions where BM25 missed it in its top 3

  • 10 / 10

    out-of-corpus questions refused

01

The problem

A RAG demo that answers three questions well proves very little. I wanted to know which way of finding passages works best for Thai, and to see exactly where each one fails.

Thai has no spaces between words, so ordinary keyword search needs word segmentation first, and the choice between keyword, embedding and hybrid search is not obvious.

02

What I built

  • A corpus of 40 Thai Wikipedia articles (provinces and well-known places), cut into 1,698 section-aware chunks of up to 700 characters.
  • Three retrievers: BM25 over PyThaiNLP word segmentation, Gemini embeddings with cosine similarity, and both merged with reciprocal rank fusion.
  • Answers written by Gemini from the retrieved passages only, with numbered citations, and "ไม่พบข้อมูลในเอกสาร" (not found in the documents) when the passages do not hold the answer.
  • 33 tests that run without an API key.
03

How I measured it

  • 80 questions generated from sampled passages, one per passage and at most three per article. Each question records its source passage as the gold answer.
  • Retrieval: whether the exact source passage is in the top 1, 3 or 5 (hit@k), mean reciprocal rank (MRR), and whether any passage from the right article was found.
  • 10 hand-written questions about things outside the corpus, to test refusal.
  • Answer quality judged by Gemini for correctness and faithfulness to the passages.
Retrieval results on the 80 questions
RetrieverHit@1Hit@3Hit@5MRR
BM250.8380.9500.9630.898
Vector0.8871.0001.0000.942
Hybrid0.9000.9880.9880.942
04

What I found

  • Vector search found the source passage in the top 3 for every question. BM25 missed 4 of 80.
  • Hybrid put the exact passage first most often, but it tied vector on MRR and was slightly worse at picking the right article. On this question set hybrid did not clearly beat vector, and one question is 1.25 points, so I treat the gaps as noise.
  • BM25 typically fails on a shared word with another meaning: a question about when Wat Phra Kaew was built ranked a section about Khao Yai's "เขาแก้ว" second, because both contain "แก้ว".
  • The system refused all 10 out-of-corpus questions instead of using outside knowledge.
  • My first answer-quality run scored 39 of 40 correct, but reading every miss showed the measurement was the weak part. One reference answer was wrong, and the judge accepted 540 km against a reference of 520 km because the article states both. I corrected the reference and made the judge match numbers, years and names exactly.
05

Next steps and limits

  • Re-run the answer-quality numbers with the stricter judge and the corrected reference on all 80 questions. The repository notes this re-run is still to do.
  • The same model family writes the questions, answers them and judges them, so the results show relative differences between retrievers better than absolute quality.
  • 40 articles and 80 questions is a small benchmark, so differences of a few points are noise.
Next / 04Tech stack