My Chat Widget Downloaded 44 MB Before It Could Answer a Question
SageDesk's LLM mode embedded every visitor question in the browser, which meant a 23 MB model and a 21 MB WebAssembly runtime for someone who might ask one thing. I removed the embedding step, and the fix turned out smaller than the problem.

When a visitor opened the chat on my portfolio and sent a question, their browser fetched two things before anything else happened: a 23 MB embedding model from Hugging Face and a 21 MB WebAssembly runtime from a CDN. That is 44 MB, for a visitor who might ask one question and leave.
I built it that way on purpose. SageDesk is my own open source widget, and I had a reason for every line of that design. But the reason had stopped being true, and I had not noticed until I added up the network tab.
Why the Embedding Was There
SageDesk's LLM mode follows the usual retrieval pattern. The visitor asks a question, the server finds the few knowledge entries most likely to answer it, and a language model writes the reply from those entries. Finding the right entries means comparing the question against every entry by meaning, and that comparison needs the question as a vector.
Making that vector needs an embedding model. I had put it in the browser so the server function could stay tiny, with no native ONNX binaries and no model weights, which suits serverless hosting well. I described that trade in the post about building SageDesk, and at the time it felt like a clean one.
The cost landed on the visitor. It also landed on the site around them. To let the model and runtime load, my Content Security Policy had to allow Hugging Face, a CDN for the WebAssembly runtime, and wasm-unsafe-eval. I had added a workaround that warmed the model when someone hovered the chat button, so the first answer would not feel slow. A workaround for a download that existed to serve a search step.
The Question I Should Have Asked Earlier
Retrieval exists to pick a few entries out of many. So I asked how many many was.
My knowledge file has a few dozen entries. It is about 40 KB, which the library estimates at roughly 7,500 tokens. A current model reads that in one pass without noticing. The language model was already in the loop, already being paid for on every question, and I had built a whole retrieval stage to avoid showing it a document the length of a short report.
For a support or portfolio FAQ, the retrieval stage was solving a problem I did not have.
What the Flow Looks Like Now
SageDesk 3 added a second retrieval strategy, and it is now the default when you give the handler a knowledge file. The widget sends only the question. The server loads knowledge.json, builds one system prompt with the whole knowledge base inside it, and sends the question as the only user message.
const handler = createSageDeskHandler({
knowledgePath: resolve(process.cwd(), 'knowledge.json'),
provider: 'https://openrouter.ai/api/v1/chat/completions',
apiKey: process.env.SAGEDESK_LLM_API_KEY ?? '',
model: 'anthropic/claude-haiku-5.5',
systemPrompt: SYSTEM_PROMPT,
llmTimeoutMs: 30000,
maxQueryLength: 500,
});There is no index to build, no vector in the request, and nothing for the browser to download. The first message goes straight to my API route.
Three Details That Mattered
The model now decides when it does not know. With vector retrieval, a similarity threshold did that job: if no entry scored high enough, the server returned a fallback without calling the model. With the whole knowledge base in the prompt there is no threshold, so the server appends a rule to my prompt. If the knowledge does not contain the answer, the model must reply with exactly [[NO_ANSWER]], and the server turns that into the same fallback response the widget already knew how to show.
My system prompt became a base, not the whole prompt. The library puts my text first, then its own answer rules, then the knowledge inside a <knowledge_base> block. That is a breaking change from the old behaviour, and it is a good reason for the major version, because a custom prompt that replaced everything would have lost the no-answer rule.
Every question now costs a model call. Under the old design a question that matched nothing never reached the model. Now every accepted question does, and each one carries the whole knowledge base. Nothing about that is new in kind, because anyone could already forge a vector and force a call, but the stakes are higher. So the origin check, the per-IP rate limit and the spend cap on the provider key matter more than they did. The library has options for caching identical questions and for provider prompt caching, and I would reach for both before the traffic justified it.
A Surprise With Reasoning Models
Some open-ended questions came back with the fallback message, even though the answer was plainly in the knowledge file.
The cause was the model. Haiku 5.5 thinks by default, and SageDesk fixes the reply at 512 tokens. On a broad question the thinking spent the whole budget and nothing was left for the answer, so the server saw an empty reply and showed the fallback.
A knowledge-base lookup does not need reasoning, so the fix is to switch it off for that one request. The library gives me no way to pass that option, so my route wraps fetch and adds reasoning: { enabled: false } to the single request that goes to OpenRouter. I would rather the library exposed it. I also added a line to the prompt asking for answers under 150 words, so a long answer is not cut off at the cap.
If you move a retrieval setup to whole-knowledge prompts, test with broad questions as well as specific ones. A narrow question works even when the setup is wrong, and the broad ones are where an empty reply or a muddled answer shows up.
What I Deleted
This is the part I enjoyed. The change removed more than it added:
- the warm-up code that preloaded the model when the chat button was hovered
- the Hugging Face and CDN entries in the Content Security Policy, and
wasm-unsafe-eval - the 1.2 MB vector index file
- the build step that loaded a 23 MB model on my own machine every time I changed the content
- the query vector validation in my API route, which also let me shrink the request size limit from about 16 KB to 2 KB
The chat widget itself still loads when the browser is idle, so it stays out of the first load of the page, and it now mounts only on the SageDesk case study, where it runs as a live demo. What it no longer does is pull in a model and a runtime when someone opens it.
When This Is the Wrong Choice
This works because the knowledge base is small and public. It is not a general replacement for retrieval, and the limits are worth stating plainly.
- Size. The whole knowledge base rides along on every request. SageDesk estimates its size, and if it passes a configurable limit it falls back to a keyword pre-filter and logs a warning once. That is a safety net, not a design. A large knowledge base should use vector retrieval, which SageDesk still supports, and so does local mode, which keeps everything in the browser.
- Privacy. Every entry goes to your model provider with every question. Mine is a public FAQ about my work. Yours might not be.
- Quality depends on the file. When the model sees everything, it can blend two entries into one answer. Short, specific, non-overlapping entries matter more than they did when retrieval was choosing for the model.
If your knowledge base is a few dozen entries and you are paying a 44 MB download to avoid reading it, I would try the simpler version first. It is also much easier to explain to the next person who opens the repository.


