← Ask the Constitution
Under the Hood

How This Works

A complete retrieval pipeline with no servers, no API keys, and no tracking. Your question never leaves your browser. Here is the full engineering story.

§1 The Pipeline

Your Browser — Privacy Boundary

Your question never crosses this line

Step 1 — You ask
What protects free speech?
Can the government take my property?
What abolished untouchability?
Step 2 — Browser converts to 384 numbers (all-MiniLM-L6-v2)
[ 0.23, −0.41, 0.87, 0.12, −0.53, 0.71, 0.09, −0.34 … 376 more ]
[ −0.18, 0.62, −0.33, 0.89, 0.14, −0.47, 0.55, 0.21 … 376 more ]
[ 0.44, 0.31, −0.67, 0.19, 0.82, −0.25, 0.38, −0.11 … 376 more ]
Step 3 — Dot product vs 544 passages (< 1ms)
Article 19
91%
Article 21
44%
Article 25
28%
Article 300A
88%
Article 31A
51%
Article 21
39%
Article 17
95%
Article 15
34%
Article 14
29%
Step 4 — The Constitution answers in its own words
Article 19 · Part III
“All citizens shall have the right to freedom of speech and expression.”
Article 300A · Part XII
“No person shall be deprived of his property save by authority of law.”
Article 17 · Part III
“Untouchability is abolished and its practice in any form is forbidden.”
No outbound API calls
OpenAI API
Vector DB
Your Server

§2 Why 544 Passages, Not 500-Token Windows

The default way to chunk documents for retrieval is mechanical: slice the text into fixed windows of a few hundred tokens, with some overlap so nothing falls between the cracks. It works, and it is also why so many retrieval systems cite "chunk 47" and hand you a passage that starts mid-sentence.

The Constitution of India makes that laziness inexcusable, because it ships with its own structure. The document is organised into Parts, the Parts into Articles, and long Articles into numbered clauses. Every Article opens with a marginal note that names what it does, in the drafters' own words. Those are the chunk boundaries. Each Article is the atomic citable unit, so it becomes one chunk, with its marginal note leading the text. Articles that run past roughly 450 words are split at numbered clause boundaries, and the citation travels with the split: a result can say Article 356 · clauses (1)–(3) instead of a byte offset. The Preamble is its own chunk. Schedules 1 through 5 are included. The result is 544 citation-ready passages, and every one of them is a complete thought with a name a citizen, a journalist, or a High Court already understands.

That is why a result here says Article 21, Part III instead of "chunk 47." A student can quote it. A teacher can assign it. A lawyer would recognise the citation. The retrieval system speaks the same language as the document it searches.

The transferable rule: before reaching for a token splitter, ask what the document's own atomic unit is. Contracts have clauses. API docs have endpoints. Runbooks have steps. Structure-aware chunking costs one afternoon of parsing and pays out every single query.

§3 The Economics of Zero

First, precision: this is not a "local LLM" doing the answering. The core is a local embedding model, all-MiniLM-L6-v2 as quantized ONNX, about 23 MB, loaded by Transformers.js from Hugging Face's CDN and cached in your browser's Cache API after the first visit. Your question is embedded in a web worker, and because the vectors are L2-normalized, cosine similarity is a plain dot product. Retrieval cannot hallucinate. There is an optional in-browser summarizer (LaMini-Flan-T5-77M) that also runs entirely on your device and carries its own disclaimer in the interface, but the quoted passages and explainers never pass through it.

Cost lineTypical hosted RAGThis site
Query embeddingAPI call, metered per token$0, computed in your browser
Vector searchHosted vector DB, monthly fee$0, a dot product over one static JSON file
Answer generationLLM call, cents per query$0, curated explainers written once at build time
Keys & rate limitsKeys to protect, quotas to hitNone exist
Cost if it goes viralScales with every visitorFlat. The origin serves about 2–3 MB of static files (the index plus the HTML). The model comes from Hugging Face's CDN, and repeat visitors cost roughly nothing.

The index itself is built offline by two Node scripts, build-corpus.js and build-embeddings.js, which embed all 544 passages (384 dimensions, mean pooling, L2-normalized, quantized to 5 decimals) into a single static file at data/index.json. The only real cost a visitor pays is the one-time model download on the first search, cached by the browser afterward. That is the honest tradeoff, and for a public tool it is the right one: a site that costs money per query dies the day it goes viral. This one cannot, because its marginal cost per query is zero at ten visitors and zero at ten million.

§4 When to Use This Pattern, and When Not To

Use it for small, public, read-heavy corpora: documentation sites, legal and policy texts, product manuals, FAQ knowledge bases. Anywhere under a few thousand chunks where the content is not secret and the questions repeat.

Do not use it for private data (the whole index ships to every visitor), for large corpora (the index download outgrows its welcome), or when users need generated prose rather than retrieved passages. Engineering maturity is matching the architecture to the problem, not to the hype cycle.

§5 What Is Curated vs. Computed

Honesty about the seams: the AI here does retrieval and question-matching, nothing else. Every one of the 544 passages carries a plain-language explainer written by a person at build time and shipped as static text. On top of that sit 30 curated questions and answers that act as a semantic router: your question is compared against the embedded curated questions, and when the cosine similarity reaches 0.60 or higher, the human-written short answer appears above the retrieved passages. The Constitution's words are quoted exactly from the source text. Each layer is labeled in the interface, so you always know who is talking: 1950, or 2026.

§6 Sources, and Two Honest Caveats

The working text is the official English text of the Constitution of India via the Wikisource 2020 edition, which includes all 104 amendments, downloaded Part by Part. The authoritative reference remains the Government of India's own publication at legislative.gov.in. If they ever disagree, the government text wins.

Caveat one: the printed text is not always the living law. Where the Supreme Court has struck down an amendment but the print retains the words, this site shows the printed text. The famous example is the 99th Amendment's National Judicial Appointments Commission articles, struck down in 2015 yet still present on the page. The passages quote what is printed, and the plain-words explainers flag where the Court has said otherwise.

Caveat two: some of the law is not in the document at all. Judge-made law, like the right to privacy from Puttaswamy or the basic structure doctrine, does not appear in the text you can search here. Where a curated answer rests on judgments rather than the document, the answer says so plainly.

✦ ✦ ✦

Retrieval that citizens can quote, at a cost that virality cannot kill. The architecture is the product decision.

The entire build is open source: github.com/swapniltamse/ask-the-constitution-india