Run a local AI chatbot
ActivitiesProjects
Get a language model answering test prompts on your own computer while the internet connection is off.
Running a local AI chatbot means downloading a language model onto your own macOS, Windows, or Linux computer and holding a conversation directly on your hardware rather than sending prompts to a remote server. With Ollama, the documented setup flow is to install and open the app, start the background service with `ollama serve` on Linux if it is not already running, pull a model over HTTPS (such as `ollama pull gemma4:e2b`), and send chat requests to the local server. If you prefer working from the command line, Ollama's CLI also provides `ollama run` (for example, `ollama run gemma4` or `ollama run llama3.2`) to launch a model directly. You need an internet connection to fetch a model initially, after which local runs execute on your own machine.
Matching a model to your disk and memory
Download size and working memory are separate constraints, and mixing them up is the easiest way to stall a first attempt. Smaller text-only models are light enough for modest machines: Llama 3.2, an instruction-tuned family built for multilingual dialogue, retrieval, and summarization, lists a 1.3 GB download for its 1B variant (`ollama run llama3.2:1b`) and 2.0 GB for its 3B default (`ollama run llama3.2`). Those figures reflect the model files on disk, not total memory use. A larger example such as Gemma 4 E2B is roughly a 7.2 GB download and calls for 8 GB of available GPU video memory (VRAM) or Mac unified memory. When a machine has less VRAM than a model needs, Ollama can fall back to system RAM, which keeps the chat running but can noticeably slow down replies. Because smaller and larger models also differ in answer quality and capability, a useful first test is to ask a concrete question and then follow up by changing the target length, audience, or format to see how cleanly the model adapts.
Context length, speed, and managing local models
Every chat shares memory with its context window, the maximum number of tokens a model can hold in memory at once. Pasting a long document or carrying on a long back-and-forth uses more of that window, and increasing the context length raises the amount of memory the model needs. You can adjust the limit in the app, set `OLLAMA_CONTEXT_LENGTH` when running the server, or change it during `ollama run` with `/set parameter num_ctx 4096`. To see what an active model is actually allocated on your hardware, run `ollama ps`. Its `PROCESSOR` column reports whether the model is loaded entirely into GPU memory, entirely into system RAM, or split between both, helping you diagnose memory placement.
Keeping track of models also separates memory from disk space: - `ollama ls` lists models downloaded to your machine. - `ollama stop MODEL` unloads a running model from memory while keeping its files on disk. - `ollama rm MODEL` deletes the downloaded model files completely.
Downloaded models live by default in `~/.ollama/models` on macOS, `/usr/share/ollama/.ollama/models` on Linux, and `C:\Users\%username%\.ollama\models` on Windows. Setting `OLLAMA_MODELS` moves them to another folder; on a standard Linux installation, the `ollama` user needs read and write permissions for that directory.
Privacy boundaries and building a simple chat interface
Local execution is distinct from Ollama's cloud models, where inference runs on Ollama's cloud service and prompts and responses are processed to provide that service. For local runs, Ollama states that it does not see your prompts or data, though that guarantee applies to Ollama itself rather than separate apps you connect to it. To keep a setup strictly local, set `OLLAMA_NO_CLOUD=1` or add `disable_ollama_cloud` to `~/.ollama/server.json` and restart Ollama, which disables cloud models and web search at the same time. By default, the local server binds only to `127.0.0.1` on port `11434`; `OLLAMA_HOST` changes the bind address, so exposing the server beyond your own machine depends on the address you configure and calls for deliberate network security controls.
Once your local server is responding, you can build a simple custom interface on top of it by sending `POST /api/chat` requests containing a model name and a `messages` array of role-and-content objects. The server returns an assistant message, and the REST API streams response chunks by default while SDKs leave streaming off by default. Any script that uses streaming needs to accumulate those partial chunks back into the message list so the model retains the conversation history on the next turn.
