llama-serverruns the GGUF model behind an OpenAI-compatible/v1API; Open WebUI is the chat UI; SearXNG does the web search.- On a 24 GB RTX 4090, Qwen3-32B Q4_K_M at 16K context needs ≈ 23.4 GiB; a q8_0 KV cache cuts it to ≈ 21.5 GiB.
- Always pass
--port 8080: llama-server now listens on127.0.0.1:9931by default. - Enable SearXNG's
jsonformat, give the model 16K+ context, and register the admin account first.
- Check the memory budgetSum weights, KV cache and overhead for your model, quant and context.
- Install llama.cppUse a release archive, brew, winget, or a source build with
-DGGML_CUDA=ON. - Start llama-serverRun Qwen3-32B Q4_K_M via
-hfon port 8080 with a 16K context, q8_0 KV cache and an API key. - Test the APIWait for
/healthto return ok, then send one chat completion with the key. - Configure SearXNGCreate
searxng/settings.ymlwith the json format enabled. - Start the containersFill in the secrets in
docker-compose.ymland rundocker compose up -d. - Create the admin accountRegister the first user on port 3000 and set the connection provider to llama.cpp.
- Turn on web searchEnable Web Search on the model and in a chat; check the sources under the answer.
Why run the model locally
A local stack trades peak model quality for control: prompts, documents and chats stay on your hardware, there is no per-token bill or rate limit, and the model changes only when you change it. The price is upfront — a GPU or a Mac with enough memory.
We use open-weight GGUF models: Qwen3 (14B, 30B-A3B, 32B) and DeepSeek-R1-Distill, which brings R1-style reasoning to 32B and 70B sizes. For frontier-size models, use a cloud API. In Russia the recommended cloud stack is Hermes Agent + DeepSeek API.
Architecture: three services on one machine
llama-server loads the GGUF file into GPU memory and serves an OpenAI-compatible API. Open WebUI keeps users, chats and documents and calls llama-server as an OpenAI endpoint. SearXNG is a metasearch engine on the Docker network: when the model calls its search tool, Open WebUI pulls JSON results from it and feeds the pages into the context.
:8080— llama-server, native on the host for direct GPU access (Docker image:ghcr.io/ggml-org/llama.cpp:server-cuda).:3000— Open WebUI, the only port your LAN needs.searxng:8080— SearXNG, visible only inside the Docker network.
Hardware and VRAM: what fits in 24 GB
GPU memory = weights + KV cache + overhead. Weights scale with parameters × bits per weight (Q4_K_M ≈ 4.85, Q8_0 8.5), the KV cache with context × parallel chats; overhead is ≈ 0.5 GiB runtime plus 0.35–0.55 GiB compute buffers. One chat, 16K context, f16 KV unless noted:
| Model · quant | Weights | KV @ 16K | Total |
|---|---|---|---|
| Qwen3-14B · Q8_0 | 14.6 GiB | 2.5 GiB | ≈ 18.0 GiB · fits |
| Qwen3-30B-A3B · Q4_K_M | 17.2 GiB | 1.5 GiB | ≈ 19.6 GiB · fits |
| Qwen3-32B · Q4_K_M | 18.5 GiB | 4.0 GiB | ≈ 23.4 GiB · too big |
| Qwen3-32B · Q4_K_M, q8_0 KV | 18.5 GiB | 2.1 GiB | ≈ 21.5 GiB · tight |
| R1-Distill-Llama-70B · Q4_K_M | 39.9 GiB | 5.0 GiB | ≈ 45.9 GiB · Mac only |
DeepSeek-R1-Distill-Qwen-32B has the same 256 KiB-per-token KV cache as Qwen3-32B — plan it like those rows. The VRAM calculator uses the same formula; R1-Distill-Llama-70B matches its Llama-3.3-70B row.
Install llama.cpp
Pick one route: the release archives (CUDA builds for Windows and Ubuntu, arm64 for macOS), Homebrew or winget, or a source build with the CUDA Toolkit for the newest commits.
# Package managers
brew install llama.cpp # macOS and Linux (Metal on Mac)
winget install llama.cpp # Windows
# Build from source with CUDA (needs the CUDA Toolkit)
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release -j
# binaries: build/bin/ (Windows: build/bin/Release/)
# Check the install
llama-server --versionRun llama-server with Qwen3-32B
-hf downloads the GGUF from Hugging Face on first start and caches it (LLAMA_CACHE moves the cache). This loads Qwen3-32B Q4_K_M fully on the GPU:
# Windows PowerShell: end lines with ` instead of \ or write one line
llama-server -hf unsloth/Qwen3-32B-GGUF:Q4_K_M \
--host 0.0.0.0 --port 8080 \
-ngl all -c 16384 -np 1 \
-fa on -ctk q8_0 -ctv q8_0 \
--api-key <LLAMA_API_KEY>--host 0.0.0.0 --port 8080— reachable from the Open WebUI container; without--portyou get 9931.-ngl all -c 16384 -np 1— all layers on the GPU, one chat slot with the full 16K window.-fa on -ctk q8_0 -ctv q8_0— Flash Attention plus a q8_0 KV cache: 2.1 GiB instead of 4.0 GiB.--api-key— make one withopenssl rand -hex 32; every endpoint except/healththen needs it.
curl http://127.0.0.1:8080/health
# {"status":"ok"} once loaded; 503 while the model is still loading
curl http://127.0.0.1:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <LLAMA_API_KEY>" \
-d '{"messages":[{"role":"user","content":"Reply with one word: ready?"}]}'Open WebUI and SearXNG in Docker Compose
Put this file in an empty folder. OPENAI_API_KEY is the llama-server key; generate the other two secrets with openssl rand -hex 32. Create the SearXNG settings (next section) before the first start.
services:
open-webui:
image: ghcr.io/open-webui/open-webui:main
ports:
- "3000:8080"
volumes:
- open-webui:/app/backend/data
extra_hosts:
- host.docker.internal:host-gateway
environment:
- OPENAI_API_BASE_URL=http://host.docker.internal:8080/v1
- OPENAI_API_KEY=<LLAMA_API_KEY>
- ENABLE_OLLAMA_API=False
- WEBUI_SECRET_KEY=<WEBUI_SECRET_KEY>
- ENABLE_WEB_SEARCH=True
- WEB_SEARCH_ENGINE=searxng
- SEARXNG_QUERY_URL=http://searxng:8080/search
- WEB_SEARCH_RESULT_COUNT=3
depends_on:
- searxng
restart: unless-stopped
searxng:
image: docker.io/searxng/searxng:latest
volumes:
- ./searxng:/etc/searxng
- searxng-cache:/var/cache/searxng
environment:
- SEARXNG_SECRET=<SEARXNG_SECRET>
restart: unless-stopped
volumes:
open-webui:
searxng-cache:Open http://<host-ip>:3000 and register at once: the first account becomes the admin. The llama-server connection is already in Settings → Connections → OpenAI; under Advanced, set Provider to llama.cpp to see and manage the loaded model.
Traffic from the container arrives over the Docker bridge, not loopback — hence --host 0.0.0.0. Block port 8080 from other machines in your firewall.
Private web search through SearXNG
SearXNG queries public engines on your behalf and merges the results. Open WebUI asks it for JSON, which is off by default — without this file every search gets 403 Forbidden:
use_default_settings: true
server:
# secret_key comes from SEARXNG_SECRET in docker-compose.yml
limiter: false # the limiter needs Valkey; skip it on a private instance
search:
formats:
- html
- jsondocker compose up -d
docker compose exec open-webui curl -s "http://searxng:8080/search?q=llama.cpp&format=json"
# JSON output = OK; 403 Forbidden = json is missing from search.formatsIn Open WebUI, search is a tool the model calls (search_web, fetch_url) in Native function-calling mode. Enable the Web Search capability on the model, then switch it on per chat from the + menu. Only the search query and the page requests leave your machine.
Apple Silicon: Metal and unified memory
On a Mac, brew install llama.cpp gives a Metal build and the same command works: -ngl all puts every layer on the GPU, which shares unified memory with the CPU. macOS caps how much memory the GPU may wire — llama.cpp logs it as recommendedMaxWorkingSetSize — and you can raise the cap:
# 64 GB Mac: let the GPU wire up to 52 GiB, keep 12 GiB for macOS and Docker
sudo sysctl iogpu.wired_limit_mb=53248Per Apple's MLX docs, the value should exceed the model size in megabytes and stay below total memory; it resets on reboot. That fits R1-Distill-Llama-70B Q4_K_M: ≈ 45.9 GiB at 16K, ≈ 43.6 GiB with a q8_0 KV cache.
Tuning and security
- Parallel chats.
-cis the KV budget for all slots: two 16K chats need-np 2 -c 32768and twice the KV memory. - Auto-fit. With the default
-fit on, llama.cpp sizes unset arguments like-ngland-cto free memory. - MoE offload.
--n-cpu-moe Nkeeps the expert weights of the first N layers in system RAM.
- Expose only port 3000 to your LAN; keep 8080 and SearXNG off the internet.
- Set
WEBUI_SECRET_KEYyourself: the auto-generated key lives inside the container, so recreating it logs everyone out.
Common gotchas and fixes
| Symptom | Cause | Fix |
|---|---|---|
| llama-server starts, but nothing answers on port 8080. | Current builds listen on 127.0.0.1:9931 by default. | Pass --port 8080, plus --host 0.0.0.0 for containers. |
| Every web search fails with 403 Forbidden. | SearXNG serves only html unless json is enabled. | Add json to search.formats and restart the searxng container. |
On Linux, Open WebUI cannot reach host.docker.internal. | Docker Engine on Linux lacks that name, and traffic comes over the bridge, not loopback. | Keep extra_hosts: host.docker.internal:host-gateway and run llama-server with --host 0.0.0.0. |
| Web search broke after switching the KV cache to q4_0. | A q4_0 KV cache degrades tool calling, and search is a tool call. | Return to -ctk q8_0 -ctv q8_0; save memory with a shorter context or a smaller quant. |
| With search on, answers ignore most of the page or lose the question. | Results and fetched pages overflow a context below 16K tokens. | Give each chat -c 16384 or more and keep WEB_SEARCH_RESULT_COUNT low. |
| Someone else on the LAN registered first and became the admin. | The first account on a fresh instance gets admin rights. | Register right after the first start, before sharing port 3000, and set WEBUI_SECRET_KEY explicitly. |
A changed env var in docker-compose.yml has no effect. | ConfigVar settings are saved to the database on first start, and the database wins (ENABLE_PERSISTENT_CONFIG=True). | Change it in the admin Settings, or set ENABLE_PERSISTENT_CONFIG=False. |
Frequently asked questions
Which model should I start with on an RTX 4090?
Qwen3-30B-A3B Q4_K_M (≈ 19.6 GiB at 16K), an MoE model with about 3B active parameters per token. For the strongest dense model: Qwen3-32B Q4_K_M with a q8_0 KV cache.
Is the stack fully private?
Prompts, files and chats stay on your machines. Web search sends the query to public engines via SearXNG and fetches the pages the model opens; turn it off for sensitive chats.
Does it work on Windows?
Yes: llama-server runs natively from the CUDA archive or winget, Open WebUI in Docker Desktop, where host.docker.internal works out of the box.
Can I run the full DeepSeek R1 locally?
Not on this hardware — it has 671B parameters. The R1-Distill models (Qwen-32B, Llama-70B) bring its reasoning style to sizes that fit.
The AI brief engineers actually read
The day’s most important AI stories — models, tools, prices and agents — in five minutes. Free, unsubscribe in one click.
