← all work

project 2 of 4

shikshapatri q&a

a chatbot that answers only from the scriptures, ends every answer with its source, and says "not found" rather than guess.

role
solo developer
year
2026
  • Python
  • FastAPI
  • BGE-M3
  • ChromaDB
  • reranker
  • Claude
  • Google Cloud Vision OCR

the problem

The Shikshapatri is a short scripture of about 212 verses, called shloks. It comes with a long commentary, the Shikshapatri Bhashya. The Vachanamrut is a larger scripture of 273 discourses. People turn to these texts with everyday questions: what to eat, how to behave, what a ritual means.

Finding the answer by hand is slow. The sources I had are scanned Gujarati books, and a question can be asked in Gujarati, Hindi or English.

A normal chatbot is the wrong tool for this. It will answer smoothly from memory, and it can invent a verse number that does not exist. For a religious text, a confident wrong answer is worse than no answer at all.

So the goal was a chatbot that behaves like a careful reader:

  • It answers only from the texts it was given.
  • It replies in the language of the question, in detail, with the reasoning the text gives.
  • It ends every answer with the exact source, such as “Shikshapatri, shlok 31”, and shows the original passage so the reader can check it.
  • It says “this is not directly addressed in the texts I have” when the texts do not cover the question.

the demo

video, no sound · One question, from typing it to the answer being written out. Shown at four times its real speed; the clip stops while the answer is still arriving.
The start screen: choose the scripture and the answer mode, or tap an example question.
An English question, and the start of its answer.
The sources under the English answer. 'Verify in the original texts' is open and names the first passage, with its relevance score.
Part of an answer to a Gujarati question, written in Gujarati, and the start of its list of sources.
The end of the answer to a follow-up, 'Does that also apply to insects?', with its sources.
A question the texts do not cover. No answer is forced.

open shikshapatri q&a →an answer can take a minute or two, so please wait for it

how it works

This is retrieval, not training. No model is ever trained on the scriptures. The texts are prepared once and stored so they can be searched by meaning. Then, for every question, the system finds the most relevant passages and asks Claude to answer from those passages only.

once · when the texts are loadedscanned pagesGujarati books aspage images, plusclean Englishtextread the scansGoogle CloudVision turns eachpage into textsplit by verseone shlok, onecommentary or onepart of adiscourse perpiecetext intonumbersBGE-M3 gives eachpiece afingerprint ofits meaningthe storeChromaDB keepseach piece withits book andverse numberthe index is built. nothing is trained.every time someone asksthe questionin Gujarati,Hindi or English;a follow-up isrewritten tostand alonesearchthe store returnsmany passagesclose in meaningreranka second modelreads eachpassage againstthe questionstrong enough?if the best matchis weak, thereply is "notfound"answer +sourcesClaude writesonly from thepassages, thenlists each oneonce · when the texts are loadedscanned pagesGujarati books as page images, plusclean English textread the scansGoogle Cloud Vision turns each pageinto textsplit by verseone shlok, one commentary or onepart of a discourse per piecetext into numbersBGE-M3 gives each piece afingerprint of its meaningthe storeChromaDB keeps each piece with itsbook and verse numberthe index is built. nothing istrained.every time someone asksthe questionin Gujarati, Hindi or English; afollow-up is rewritten to standalonesearchthe store returns many passagesclose in meaningreranka second model reads each passageagainst the questionstrong enough?if the best match is weak, the replyis "not found"answer + sourcesClaude writes only from thepassages, then lists each one
read the books once, then look things up for every question

In plain words:

  1. The scans are read. Google Cloud Vision turns each page image into text. The results are saved, so no page is read twice.
  2. The text is split by scripture unit. One piece is one shlok, or the commentary on one shlok, or a few paragraphs of one discourse. It is never cut at a fixed number of characters.
  3. Every piece carries its address. That means the book, the shlok number or the discourse name, and the page. A verse and its commentary share a shlok number, so they stay linked.
  4. Each piece gets an embedding. BGE-M3, a multilingual model, turns the text into a list of numbers that stands for its meaning. The same model is used for the questions, so a Hindi question can find a Gujarati passage.
  5. A question arrives. If it is a follow-up such as “and for women?”, a small fast model first rewrites it into one complete question.
  6. Search, then rerank. The store returns a wide set of nearby passages. A reranker then reads each passage together with the question and puts the best ones on top.
  7. A threshold decides. If even the best passage is a weak match, the system stops and says the texts do not address the question.
  8. Claude answers from the passages. It writes in the user’s language and may only cite numbers that belong to a passage it was shown.
  9. The reader can check. The answer ends with its sources, and the original passages are shown beside it. Every question and its sources are also logged, so answers can be reviewed later.

key decisions

RAG, not fine-tuning

The model reads retrieved passages at answer time. It is never trained on the books.

Why: a trained model blends what it has read and can invent a reference. I needed exact references, and only retrieval keeps the text and its address together.

'not found' beats a confident guess

A relevance threshold sits between search and answer. Below it, there is no answer.

Why: in religious content a wrong citation is worse than an honest “not found”. The model is also told never to fill a gap from outside knowledge.

split by verse, never by length

One piece is one logical unit of scripture, and every piece carries its book, number and page.

Why: citation accuracy depends on clean metadata for every piece. If a cut falls in the middle of a verse, the reference is already wrong.

measure it, and keep a record

A test set of questions with their expected verses runs after any change, and every answer is logged with its sources.

Why: accuracy should be measured, not felt. The log makes it possible to audit what the system said and why.

what was hard

Reading scanned Gujarati. The Shikshapatri sources are scans, and the Gujarati Vachanamrut file uses an old font encoding, so its text could not simply be copied out. Both went through OCR. Seven shloks (149 to 151, 154 to 155 and 205 to 206) had trouble in both sources. I marked them as low confidence instead of guessing their numbers.

Keeping a verse and its commentary together. The verse and the commentary live in different books but share shlok numbers. I built the pieces around one reconciled list of shlok numbers, so each commentary is tagged with the verse it explains.

Two scriptures, two ways of citing. The Shikshapatri is cited by shlok number. The Vachanamrut is cited by section and discourse, for example “Vachanamrut, Gadhada Pratham 1”. I made the shlok number optional and gave Vachanamrut pieces their own section, discourse and reference fields, so each answer cites in the style of its book.

Speed on an ordinary computer. With no graphics card, an answer takes about 1 to 1.5 minutes, because the embedding model and the reranker both run on the processor. Shortening the text length used for embeddings made search usable. This only affects how passages are found; the stored and cited text is never shortened. The hosted version was set up to use a reranker in the cloud for the same reason.

Follow-up questions. “What about on fasting days?” means nothing on its own. A small model rewrites a follow-up into a complete question before the search. If that step fails for any reason, the original question is used, so a conversation can never search worse than a single question. The chat history is used only to understand the question. It is never treated as a source.

results

  • 212shloks in the Shikshapatri, each with its commentary
  • 273Vachanamrut discourses, all parsed
  • 3languages: Gujarati, Hindi and English
  • 2,508Vachanamrut pieces: 1,298 English and 1,210 Gujarati
  • 44questions in the evaluation set
  • 7shloks marked low confidence instead of guessed
  • Accuracy so far: in an earlier evaluation, on a smaller test set, the right shlok was among the top results about 89% of the time. The test set has since grown to 44 questions, and I have not yet published a number for it.
  • A known weakness: the single best match is sometimes a neighbouring shlok on the same topic.
  • Speed: an answer can take a minute or two. On a computer without a graphics card it is about 1 to 1.5 minutes.
  • Hosting: it runs as a public web app on Vercel. The link is at the top of this page.

what i learned, and what’s next

What I learned

  • Most of the quality comes from preparing the data. Clean pieces with correct addresses mattered more than any prompt.
  • A refusal is a feature. Deciding when the system should say “not found” was as important as making it answer well.
  • An evaluation set, built early, turns “it feels better” into a number that can be checked after every change.

What’s next

  • Re-run the evaluation on all 44 questions and report the current number.
  • Fix the ranking of neighbouring shloks, so the exact verse comes first more often.
  • Check the seven low-confidence shloks by hand against the printed text.
  • Make it faster, with a graphics card or a hosted reranker.