exploration · ongoing
How I Raised Offline Textbook Search Accuracy from 73% to 87%
Letting a classroom AI answer from NCERT textbooks with no internet. The biggest gains came from checking the PDFs and searching only the student's own class and subject, not from a bigger model.
- Retrieval research lead
- Jul 2026
- exploration
- ongoing
Key results
- 73% →87%Questions where the right textbook passage came first, once search was limited to the student's class and subject
- 32,338Textbook passages made searchable, NCERT Classes 1–12 in English
- ~7–8 msTypical search time on the panel, with no internet
Overview
Teachmint’s classroom panels needed an AI assistant that could answer from the NCERT textbooks a class actually uses, with no network. That means retrieval-augmented generation running on the panel: find the right passage locally, then let a small on-device model answer from it.
In July 2026 I led the research that made the retrieval side real. That covered an ingestion pipeline from the textbook PDFs to per-class vector databases, an embedding-model evaluation on the panel itself, and a vector store the Android side could actually open.
The problem
Retrieval quality depends on three things before any model runs:
- What’s in the corpus. NCERT spans 12 classes, several subjects per class and multiple language editions, in PDFs with very uneven text layers.
- How it’s chunked. Textbooks have sections, tables, equations and exercises. Naive splitting breaks all of them.
- Where it’s searched. The panel has to embed queries and search vectors locally, in a store its Android stack can read.
Constraints
- RK3576 panels: CPU embeddings only, with no GPU delegate for the larger embedding model.
- The vector store had to work from an Android app without loading native SQLite extensions at runtime.
- Every result had to be measurable against a gold set, on the device, not just on a laptop.
My approach
NCERT PDFs ──► survey + catalog ──► fetch ──► extract
(quarantine gates, layout model)
│
▼
per-class+subject DBs ◄── embed ◄── section-aware chunks
(sqlite-vec, bge-small) ("Book — Chapter — Section")
│
▼
panel: int8 ONNX query embedding ──► sqlite-vec KNN ──► passages
- An offline ingestion pipeline in Python surveys the library, fetches chapter PDFs, extracts text, chunks it by section, embeds it with the exact int8 model bytes the panel uses, and writes SQLite databases. A fingerprint of a fixed sentence’s embedding is stored in each database, so drift between desktop and device is detectable.
- Quarantine before chunking. Extraction has three gates: font, empty text and non-Latin-script ratio. Chapters that would produce garbage never reach the index.
- sqlite-vec on the device, through JNI. The panel searches the same databases the pipeline writes.
Important decisions
Pick the embedder on the panel
Four embedding models, exported to int8 ONNX, matched desktop sentence-transformers at cosine 0.96–0.99. They were then compared on the panel against 20 NCERT gold questions:
| Model | hit@1 | Cost on the panel |
|---|---|---|
| MiniLM | 1.00 | ~71 ms per chunk |
| E5-small | 0.95 | |
| EmbeddingGemma | 0.95 | ~9.4 s per chunk, CPU only |
| bge-small | 0.90 |
Twenty questions is a small set, and later, larger gold sets reordered the top: on a Class 10 run, bge-small and E5 reached hit@3 1.00 where MiniLM reached 0.93. bge-small became the shipping choice. EmbeddingGemma was ruled out on cost alone.
Ship sqlite-vec by static linking
The vendor SDK’s own vector store couldn’t read standard sqlite-vec vec0 tables, and the SQLite
bindings available on Android expose no way to load an extension at runtime. So I compiled SQLite
3.46.1 and sqlite-vec 0.1.9 together into one JNI library, registering the extension before any
database opens. On the panel it reproduced the desktop pipeline’s results exactly, with a query p50 of
about 7–8 ms over the pilot corpus and almost no JVM heap, because vectors stay on disk.
sqlite-vec is exact brute-force search with SIMD, not an approximate index. The win is flat memory, not sublinear latency. An ANN index is the next step if latency becomes the limit.
One database per class and subject
The key retrieval finding wasn’t about models. With all classes in one combined index, Class 10 gold questions reached hit@1 0.73 and hit@3 0.93, because similar topics from other grades crowded the results. With a database per class and subject, the same questions reached hit@1 0.87, hit@3 1.00 and MRR 0.93. So the design scopes retrieval to the student’s own class and subject.
What went wrong
The corpus was the source of most surprises:
- Hindi PDFs extract as gibberish. Many NCERT Hindi books use legacy glyph-coded fonts, so their text layer comes out as Latin mojibake. They’re quarantined until an OCR or font-mapping stage exists.
- A textbook was a draft. One set of Social Science chapter PDFs in our storage turned out to be pre-publication drafts. One said a role was “appointed by the Crown of the UK” where the official book says “by the Monarch (Head of State) on the advice of the Prime Minister”. All nine files were replaced with the official chapters, and the pipeline now tracks source hashes.
- Question banks pollute retrieval. Excluding exemplar and worksheet books lifted on-target answers to real past exam questions from 44 to 58, a 32% improvement.
- Layout matters. Moving extraction to a layout model removed 268 stray page numbers and 906 of 907 repeated reprint footers, and made 186 table chunks retrievable.
Debugging & Investigation
Two things kept the research honest:
- Evaluation on the panel. A device-side eval runs the gold set against the actual databases and embedder on the panel, writing results to files. One panel suppresses app logs entirely.
- Caveats written next to results. A chunking sweep favoured larger chunks (recursive 400/60 at token-recall@5 0.903, against 0.861 for the 280/40 baseline). But token recall structurally rewards big chunks, and the gold set was generated by a 1B model. That result is recorded as a hint, not a verdict, pending a precision-aware evaluation.
Result
- An ingestion pipeline covering NCERT Classes I–XII in English medium, with 32,338 chunks in the bge-small index and a database per class and subject.
- On-device retrieval through a statically linked sqlite-vec, reproducing desktop results exactly.
- Scoped retrieval that lifted hit@1 from 0.73 to 0.87 on the Class 10 gold set.
Still open: Hindi corpora, a better extractor for mathematics (a layout model turned sin²A into
“sin 2 A”), and keyword search alongside vectors. That last one is harder than it sounds, because the
panel’s ROM ships SQLite without FTS5.
What I learned
- Retrieval quality starts with the corpus. Fonts, drafts and question banks mattered more than the embedding model.
- Scope the index to the user. Grade-mixing cost more accuracy than any model swap.
- Measure models on the target device. One “equal quality” model was 130× slower there.
- Make desktop and device provably identical. Same model bytes, same tokenizer, a stored fingerprint.
- Write the caveat next to the number. A metric that favours big chunks will tell you to use big chunks.