Building a Local LLM Stack with Ollama and Open-Source Models 5 min read
AI Engineering

Building a Local LLM Stack with Ollama and Open-Source Models

Step-by-step guide to running LLaMA 3, Mistral, and other open-source LLMs locally with Ollama — zero API costs, full privacy, and production-ready setup.

Apurv Chudasama
Apurv Chudasama March 04, 2026 · 5 min read
Building a Local LLM Stack with Ollama and Open-Source Models

The moment I ran my first LLM locally and saw the response stream in my terminal — no API key, no rate limit, no cloud dependency — something clicked. This is what AI engineering without guardrails looks like. Total control. Total privacy. Zero marginal cost.

Running local LLMs with Ollama has gone from a niche experiment to a legitimate production strategy. Here's how to set up a proper local LLM stack in 2026.

Why Run LLMs Locally?

Before diving into setup, it's worth being clear-eyed about when local models make sense:

Go local when:

  • Privacy is non-negotiable (healthcare, legal, financial data)
  • You need zero-latency for high-volume, low-complexity tasks
  • You want to experiment without burning API credits
  • You're deploying to edge environments or air-gapped networks
  • You want to fine-tune on proprietary data without sending it to third parties

Stick with APIs when:

  • You need frontier-level reasoning (complex coding, nuanced writing)
  • Your hardware can't support the required model size
  • You need guaranteed uptime and SLAs

Setting Up Ollama

Ollama is the easiest way to run open-source LLMs locally. It handles model download, quantization, and a clean API interface.

Installation

# macOS or Linux
curl -fsSL https://ollama.com/install.sh | sh

# Windows — download the installer from ollama.com

Ollama runs as a local server on port 11434. Once installed:

# Pull and run LLaMA 3.1 8B
ollama run llama3.1

# Pull Mistral 7B
ollama run mistral

# Pull Code-specialized model
ollama run codellama:13b

# See all available models
ollama list

Model Selection Guide

Choosing the right model for your hardware:

Model RAM Required Best For
Qwen2.5 0.5B 2GB Embedded, edge
Llama 3.2 3B 4GB Basic Q&A, classification
Mistral 7B 8GB General purpose
Llama 3.1 8B 10GB Strong reasoning
Codellama 13B 16GB Code generation
Llama 3.1 70B 48GB+ Near-frontier quality

For most developers with a MacBook Pro M-series or a mid-range GPU, the 7B–8B range hits the sweet spot.

Building an API-Compatible Interface

Ollama exposes a REST API that mirrors OpenAI's format. This is huge — it means you can swap API calls in existing code with minimal changes:

from openai import OpenAI

# Point to your local Ollama instance
client = OpenAI(
    base_url="http://localhost:11434/v1",
    api_key="ollama"  # Placeholder — Ollama doesn't require auth
)

response = client.chat.completions.create(
    model="llama3.1",
    messages=[
        {"role": "system", "content": "You are a helpful AI assistant."},
        {"role": "user", "content": "Explain transformer attention in simple terms."}
    ]
)
print(response.choices[0].message.content)

This compatibility means you can build applications that work with both local Ollama and OpenAI-compatible APIs — just change the base_url.

Adding a UI with Open WebUI

Ollama's CLI is great for testing, but for a full chat interface:

docker run -d -p 3000:8080 \
  --add-host=host.docker.internal:host-gateway \
  -v open-webui:/app/backend/data \
  --name open-webui \
  ghcr.io/open-webui/open-webui:main

Open WebUI gives you a ChatGPT-like interface connected to your local Ollama instance. It supports:

  • Multi-model switching
  • RAG with document upload
  • Conversation history
  • System prompt customization

Integrating with LangChain and LlamaIndex

Both major AI frameworks have native Ollama support:

from langchain_ollama import ChatOllama

llm = ChatOllama(model="llama3.1", temperature=0)
result = llm.invoke("What are transformers in machine learning?")

This means you can drop a local model into any existing RAG pipeline, agent framework, or chain — a massive productivity win.

Performance Tuning

Getting the most out of local models:

  • Use GPU acceleration — Ollama auto-detects CUDA (NVIDIA) and Metal (Apple Silicon). Ensure your GPU drivers are current.
  • Adjust context windowOLLAMA_NUM_CTX=8192 increases context at the cost of VRAM
  • Quantization tradeoffs — Q4_K_M is the sweet spot for quality vs size. Q2 models save RAM but noticeably degrade quality.
  • Concurrent requests — set OLLAMA_NUM_PARALLEL for handling multiple simultaneous requests

Production Deployment

For deploying Ollama in a team or production environment:

# Run Ollama as a service accessible on your network
OLLAMA_HOST=0.0.0.0 ollama serve

Combine with Nginx for HTTPS, and you have a private, self-hosted LLM API that your entire team can use — at zero marginal cost per query.

The Local LLM Workflow I Use

My current setup for AI engineering work:

  • Ollama running Llama 3.1 8B for general tasks and LangChain development
  • Codellama 13B for code generation and review
  • Open WebUI for quick Q&A without writing code
  • API compatibility layer so I can switch between local and OpenAI with one config change

The local LLM revolution isn't coming. It's here. The quality gap with frontier models still exists for the hardest tasks — but for 80% of typical AI engineering workflows, open-source models running locally are more than good enough.


Sources

Apurv Chudasama
Written by Apurv Chudasama

AI Engineer and Data Scientist focused on applied machine learning, deep learning, and production AI systems.