
How to turn a single-course offline RAG exam assistant into a universal, subject-agnostic platform—supporting Markdown, PDF, DOCX, and HTML with 1-command subject updates.
In the first article, we built Kubernetes WebAI RAG—a 100% offline, browser-based exam assistant powered by Gemma 4 E2B, EmbeddingGemma, LiteRT-LM, TensorFlow.js, and WebGPU.
That post covered why offline Web AI solves classroom equity and academic integrity, and how the browser runtime works under the hood (OPFS caching, hybrid BM25 + WebGPU vector search, and Windows 11 zero-config packaging).
Now comes the next practical question from educators:
"I don't teach Kubernetes. How do I adapt this for Python, Linux administration, cybersecurity, or my own course notes—and update it easily every semester without rebuilding the entire 2 GB model bundle?"
That is exactly why we evolved the architecture into SourceDesk AI (sourcedesk-ai): a universal offline RAG platform built around replaceable subject packs and shared local models.
{% youtube HaK8iFzB1aM %}
When you strip away the Kubernetes branding, the system splits cleanly into two independent layers:

src/CosineSimilarity.js: Loads any normalized vectors-<hash>.f32 matrix into WebGPU and runs tf.matMul + tf.topk in milliseconds.src/KeywordSearch.js: Runs BM25 + Reciprocal Rank Fusion (RRF) over any keywords-<hash>.json.src/OfflineAnswerGenerator.js: Streams grounded answers from Gemma 4 E2B (~2.01 GB) with atomic OPFS caching.package:common / package:app): Bundles Python 3.14.4 embeddable, EmbeddingGemma 300M, and Gemma 4 E2B once.Everything that changes between courses lives in a self-contained subject pack:
.md), PDF (.pdf), or Word (.docx) course materials.vectors-<hash>.f32 + keywords-<hash>.json + chunk metadata.script-src 'none' CSP.Because the 2+ GB AI models never change between subjects, students who already have the shared runtime cached in their browser's OPFS on localhost:8080 only need to swap in the lightweight subject pack!
In the original Kubernetes prototype, build-kubernetes.mjs was hardcoded to scrape a single /_print/ HTML page and XML sitemap. Real-world courses rarely look like that—educators have Markdown lecture notes, PDF textbooks, DOCX lab manuals, and static doc sites.
In SourceDesk AI, scripts/build-subject.mjs unifies ingestion across formats:
linkedom): Crawls local HTML snapshots or sitemaps, preserving heading structure.markdown-it via scripts/markdown-source.mjs): Converts .md files into clean semantic HTML with heading anchors (<h2 id="...">).pdfjs-dist & mammoth via scripts/document-source.mjs): Extracts structured sections from textbooks, syllabi, and lab sheets into HTML pages.Why convert everything to semantic HTML with heading anchors? Because it powers the side-by-side verification reader! When a student clicks
[1]in an answer, the browser opens the exact local HTML page and scrolls straight to the#heading-anchorinside the sandboxed<iframe>.
Once your course materials are ready, building, verifying, and shipping a new subject pack takes four commands:

Place your course docs (Markdown, PDF, DOCX, or HTML) in examples/<id>/content/ and define examples/<id>/subject.json (plus evaluation.json for retrieval checks). For example, our Linux Command Line pack uses open-source tldr-pages Markdown files.
build:subject)Run the unified subject builder with the path to subject.json to chunk by headings, compute 768-dimensional EmbeddingGemma vectors, and generate the BM25 keyword index:
npm run build:subject -- --subject examples/linux-commands/subject.json
This outputs the content-hashed vectors-<hash>.f32 matrix and keywords-<hash>.json postings into data/linux-commands/.
test:retrieval)Before handing a new subject pack to students, run automated retrieval checks against evaluation.json to verify that your chunking and hybrid search surface the right passages:
npm run test:retrieval -- data/linux-commands examples/linux-commands/evaluation.json
prepare:offline & package:subject)Sanitize the local HTML mirror (stripping <script>, <form>, <iframe>, and enforcing script-src 'none' CSP), activate the pack locally, and package only the subject pack (or one-click Windows .cmd installers) for students:
npm run prepare:offline
npm run activate:subject -- --pack data/linux-commands
npm run package:subject -- data/linux-commands
Students can then install or switch to the Linux Command Line pack with a single click—reusing the shared 2 GB Gemma 4 / EmbeddingGemma runtime:
Separating the shared model runtime from subject packs solves three real-world headaches for IT teams and instructors:
Gemma 4 E2B OPFS cache on localhost:8080.markdown-it rendering, and strict CSP sandboxing.By decoupling the universal WebGPU + Gemma 4 runtime from replaceable subject packs, SourceDesk AI turns an offline Kubernetes exam assistant into a reusable platform for any technical curriculum.
Suggested Tags: WebAI, RAG, Gemma, WebGPU, EdTech
discussI Constantly Try to Survive Reality Maybe that's why I built an entire universe, including a...
aiWhen you build an AI agent, you're actually using two separate things, not one. In this episode of...
agentsHow stateful agent harnesses run, suspend, and wake in under a second on Agent Substrate 1.0, from one VM to millions of actors.
top7Welcome to this week's Top 7, where the DEV editorial team handpicks their favorite posts from the...
discussMeme Monday! Today's cover image comes from the last thread. DEV is an inclusive space! Humor in...
angularI upload images of places, wrestlers, and general objects to the application. When uploading images...
Workflows from the Neura Market marketplace related to this CoPilot resource