← all notes

note 2 of 4

why my chatbot says ‘not found’

retrieval instead of training, the exact shlok under every answer, and a bug that taught me to check what a model sends back.

written
reading time
about 3 minutes

I built a chatbot that answers questions from the Shikshapatri, its commentary and the Vachanamrut. People ask it in Gujarati, Hindi or English. Sometimes it replies: “this is not directly addressed in the texts I have.”

That reply is not a failure. I built it on purpose.

why not train a model on the books

A normal chatbot answers smoothly from memory. It can also invent a verse number that does not exist. For a religious text, a confident wrong answer is worse than no answer at all.

Training a model on the books, which is called fine-tuning, would not fix that. A trained model blends what it has read, and it can still invent a reference.

So I used retrieval, often called RAG. No model is ever trained on the scriptures. The texts are prepared once and stored so they can be searched by meaning. For every question, the system finds the most relevant passages and asks the model to answer from those passages only.

the exact shlok

The texts are split by scripture unit, never by length. One piece is one shlok, or the commentary on one shlok, or a few paragraphs of one discourse. Every piece carries its address: the book, the number and the page.

That is why every answer can end with its source, such as “Shikshapatri, shlok 31”, and show the original passage beside it. The model may only cite numbers that belong to a passage it was shown. The reader does not have to trust the chatbot. They can check.

the threshold

A search always returns something. The closest passage may still have nothing to do with the question.

So a second model reads each passage against the question and scores how well they match. If even the best passage is a weak match, the system stops and says the texts do not address the question. Ask it for the capital of France, and that is the reply.

The line is not perfect yet. In my last test run, one off-topic question in Gujarati got past it. That is on my list.

the bug i fixed

One day the hosted app gave a broken answer. The question was in English. The answer came back in Gujarati, stopped in the middle of a sentence, and was followed by about 1,300 invisible characters, until it reached its length limit.

I checked the stored texts first. Not one of the 3,182 passages held an invisible character, so the faults came from the model’s own output. My code had only asked for the right language. It never checked what came back, and it never looked at why an answer stopped.

On 1 December 2026 I fixed three things.

  • Language. The passages are mostly in Gujarati, and they sometimes pull an answer into Gujarati. The code now reads the script of the question and tells the model which language to use. The first 80 or so letters of an answer are held back and checked. A draft in the wrong language is asked for once more.
  • Invisible characters. They are removed from the passages, the chat history and the answer. A long run of them closes the answer early.
  • Cut-off answers. The code now reads the reason an answer stopped. An unfinished sentence is dropped and a short note is added. Text is released one sentence at a time, so half a sentence is never shown. I also doubled the length limit, because earlier answers had been cut off in the middle of a word.

A small test now replays the incident on my computer, at no cost. Then I asked four real questions: the English one that had failed, one in Gujarati, one in Hindi, and an English follow-up after a Gujarati exchange. Each came back in the language of its question and ended on a complete sentence, with its sources.

The fix did not touch the search, the threshold, the citations or “not found”.

what i took from it

Asking a model to behave is not the same as checking that it did.

And a refusal is a feature. Deciding when the chatbot should say “not found” was as important as making it answer well.

parth, december 2026