DEV Community

Lukas Kopischke
Lukas Kopischke

Posted on Edited on Originally published at lukiluki.me Fully Autonomous

Offline AI in Web Apps – Embeddings, Chatbots and Local Models

Originally published with interactive examples at lukiluki.me.

You are on a train without a connection and want to find related articles in a digital garden like lukiluki or ask questions about saved content. Does the AI need to reach a server, or can the web app do the computation itself?

Yes: web apps can calculate embeddings, perform semantic search and, with a suitable language model, run chatbots offline. Text classification, speech recognition and certain image tasks are possible too. The models run on your device. This requires an app that starts offline, plus locally available models, runtime files and content. Whether it works well depends on model quality, browser support, memory and computing power.

Merksatz (Key takeaway):
Offline AI needs three things at once: an app that can start, a model that can run locally and locally available data.
An installable app icon or a saved chat history is not enough.

How does a web app compute without an AI server?

With local inference (An already trained model processes new inputs on your device; it is not retrained in the process.), the browser runs a pretrained model. Instead of sending a question to a cloud API, the interface passes it to a local model library. No API key is needed for the model computation. Downloading the app and model files usually requires a connection first; the prepared features can then work offline.

Two common building blocks are Transformers.js for text, image and audio tasks, and WebLLM for local language models with a chat interface. They cannot load just any model: its architecture, file format and required operations must be supported by the library.

WebAssembly (An executable binary format for browsers; AI runtimes can use it to perform calculations on the CPU, abbreviated WASM.) provides a CPU execution path. WebGPU (A browser interface that lets suitable programs use the graphics processor for general computation as well as graphics.) can use the GPU. Transformers.js supports both paths; WebLLM requires WebGPU. The presence of a browser API does not prove that a particular model runs on the device. You need to load the model and actually process an input.

The interface stays more responsive when intensive computation runs in a separate Web Worker, outside the main thread. A Service Worker has a different primary purpose: it can serve saved app files during an offline start. WebLLM documents workers and model caches; MDN explains offline startup with Service Workers.

Which AI features can work offline?

The table describes technical possibilities with suitable models, rather than measured speeds or promises for every phone. Every row requires all necessary files to be available locally.

Feature Works offline? Example in a web app Main limitation
Embeddings Yes Turn articles or personal notes into numerical vectors Check language coverage and suitability of the embedding model
Semantic search Yes “Long loading time” finds an article about performance The query also needs a compatible vector
Chatbot Yes, with a local language model Answer questions or write a draft The model must fit in memory; quality and speed vary
Document chat Yes, if the entire pipeline is local Answer with references to saved articles Documents, search and the answer model must work without cloud services
Classification Yes Sort notes by topic The model must represent the intended categories meaningfully
Summarization and translation With a suitable model Shorten or translate saved text Input length, language and quality depend on the model
Speech to text With a suitable audio model Transcribe a local recording Audio length, memory and compute time limit usage
Text to speech With a suitable speech model Read an article aloud The voice and required files must be available locally
Image analysis With a suitable image model Classify images or detect objects Support applies to specific tasks and model architectures

The Transformers.js task overview covers feature extraction, classification, generation, audio and image tasks. For chat, WebLLM documents model initialization and streamed responses.

How do local embeddings and search work?

Embeddings are numerical vectors produced from text by a model. For a digital garden, you first calculate vectors for article sections and store them locally alongside the text, title and link. A new search query goes through the same embedding process. The app then compares its vector with the saved vectors and displays matching passages.

The crucial distinction: comparing vectors does not run the model again. A small collection can be searched directly in the browser; a cloud vector database is not essential. For larger collections, memory requirements and an appropriate search index become more important.

For public articles, you can generate document vectors during the website build. The browser then only needs to embed the query. Private notes, meanwhile, can be processed entirely on the device. In both cases, document and query vectors must come from the same compatible model space: the same model version, compatible preprocessing, dimensions and any query or document prefixes required by the model. Matching vector lengths alone are insufficient.

An article index generated by a cloud model therefore cannot simply be reused with an arbitrary small local model. When you change models, document vectors need to be regenerated accordingly. For German articles, also test German queries and paraphrases; a model optimized for English is not a reliable default. Embeddings – finding related content explains how vectors and similarity work together.

What else does an offline chatbot need?

A chatbot needs a generative language model that produces its response piece by piece. An embedding model alone cannot do this. A locally running chat also does not automatically know your articles or current information from the internet.

RAG (Retrieval-Augmented Generation: A search retrieves relevant passages that a language model receives as context for its response.) suits a chat about garden content: the app first finds suitable saved passages and passes them, along with the question, to the local language model. The answer should reference the passages it used. If there is no supporting source, the interface should make that clear. Even with relevant passages, answers can still be wrong.

The running example would be: “How do I make my site faster?” is embedded locally, retrieves saved performance sections and is passed with those sections to the answer model. Search, context and response stay on the device. Current web research or an external tool still requires a connection.

Beyond model files, chat needs additional working memory for computation and conversation context. A smaller download therefore does not mean the same amount of memory is used at runtime. Quantization (Model weights are stored using fewer bits; this can reduce file size and memory needs, but can also affect quality and hardware compatibility.) can help, but does not replace device testing. Keep conversation length and retrieved passages within the chosen model's context window.

For a digital garden, local search is therefore a useful first step: it returns results that can be checked directly. An additional chat model is worthwhile when written answers offer a clear benefit and work well enough on the target devices. Intuitive Search shows how to make search results understandable to people.

How do you make an app truly usable offline?

Prepare the app on a secure origin, usually HTTPS in production and localhost during local development. Choose a supported model with an appropriate license and test it on your target devices. A manifest and installation as a PWA (Progressive Web App: A web app that may support installation among other features; offline capability must be implemented separately.) do not replace this preparation.

  1. Save the app and content. Make the entry page, required scripts, styles, fonts and selected articles available offline. Check direct visits and navigation between saved pages too. An already open tab is not sufficient evidence.
  2. Prepare the complete model package. This includes weights, tokenizer, configuration and required runtime files. Transformers.js can fetch models and WASM files from external hosts by default; local paths and remote loading can be configured. A file at your own URL only becomes available offline once it has actually been saved.
  3. Version local data. Store text and vectors in IndexedDB, for example, a browser database for structured data. Use the model library's cache or the Cache API for suitable files. Version the model and index together so an update does not mix incompatible vectors.
  4. Check storage and readiness. Display download progress, missing files and storage errors clearly. Report “ready offline” only after the full package has loaded and a test run has succeeded. Reset the status if data is deleted or incomplete.
  5. Plan for failure. If the model cannot run, saved articles and a simple text search should remain usable. Offer a cloud alternative only as an explicit choice when inputs would leave the device.

Browser storage is limited. Users or storage pressure can remove data; private browsing has additional restrictions. The Storage API can estimate usage and request persistent storage, but the browser decides whether to grant it. Personal data still needs an export option. MDN describes storage quotas and eviction rules.

Local computation does not automatically mean privacy
Local inference needs no upload of your input. Analytics, error reports, synchronization or a cloud fallback can still transmit data. Check the entire data flow and make such transfers visible.

How do you verify the result without internet access?

Test the prepared features in a production build. Record the browser, device, model version and quantization with your results. Measure loading times and response behavior on the actual target devices; WebGPU support alone cannot establish reliable performance.

  • [ ] Start cold: After full preparation, close the app, block network access and open it again. The entry page, saved articles and navigation must work.
  • [ ] Process new inputs: Submit a previously unused query and, if applicable, a new chat question. New results must be generated; a saved history does not prove offline inference.
  • [ ] Check sources: Test a German paraphrase about a saved topic and a question outside the collection. Results must be understandable; unsupported chat answers must not appear as established facts.
  • [ ] Check failures: Test missing model files, deleted caches and an unsuitable device. Expect clear messages and readable content rather than an endless loading indicator.
  • [ ] Check network traffic and usability: Inspect network traffic while connected too; local processing must not send inputs. Search and chat must remain usable on small screens and by keyboard, including while the model computes.

Sources and next steps

These sources describe supported methods and prerequisites; they do not replace testing your model on your target devices.

Explore how embeddings work before building a search index, use Intuitive Search to design understandable search results, and read our field report on Browser-LLMs in PWAs to understand the storage and quality trade-offs of local chat models.


Read the original guide & explore the interactive playground on *lukiluki.me*.

Top comments (0)