Skip to main content
Ollama is the default backend for Mellea. It runs models locally with no API key, making it the fastest way to get started. Prerequisites: Ollama installed and the Ollama server running, pip install mellea.

Install Ollama

Download the installer from ollama.ai or:
Start the server before running any Mellea code:
On macOS, installing via Homebrew or the .dmg starts the server automatically as a background service.

Default setup

start_session() connects to Ollama on localhost:11434 and uses IBM Granite 4 Micro (granite4.1:3b) by default. On first run, Mellea automatically pulls the model if it is not already downloaded:
Note: The first run pulls granite4.1:3b (~2 GB). Subsequent runs start immediately from the local cache.

Switching models

Pass any model name that Ollama supports:
Use model_ids constants for well-known models — they carry the correct Ollama model name automatically:
Pull models before using them (or let Mellea pull on first use):
Run ollama list to see which models are already downloaded locally.

Direct backend construction

For full control, construct OllamaModelBackend directly:

Custom host

Mellea reads the OLLAMA_HOST environment variable or accepts a base_url parameter. Use this to connect to Ollama running on a remote machine or a non-standard port:
base_url takes precedence over OLLAMA_HOST if both are set.

Model options

Pass generation parameters via ModelOption:
Options set at construction time apply to all calls. Options passed to instruct() or chat() apply to that call only and take precedence.

Vision models

Ollama hosts vision-capable models. Use IBM_GRANITE_3_3_VISION_2B or any Ollama vision model via the OpenAI-compatible endpoint:
Backend note: Vision requires a model that supports image inputs. The default granite4.1:3b is text-only. Pull a vision model explicitly before using images: ollama pull ibm/granite3.3-vision:2b.

Ollama’s OpenAI-compatible endpoint

Ollama exposes an OpenAI-compatible API at http://localhost:11434/v1. Use this with the OpenAIBackend to access any Ollama model with OpenAI-style tool calling or vision support:
See Backends and Configuration for the full OpenAIBackend reference.

Troubleshooting

Connection refused on port 11434

The Ollama server is not running. Start it with ollama serve, or on macOS, launch the Ollama app from Applications.

Model not found

The model has not been pulled. Run ollama pull <model-name> before using it, or let Mellea pull it automatically on first use.

Slow first run

Ollama loads the model into memory on the first request. Subsequent requests in the same session are much faster. On machines with less than 8 GB RAM, consider using granite4.1:3b or llama3.2:1b.

Intel Mac torch errors

Some dependencies require a Rosetta-compatible environment on Intel Macs. Create a conda environment and install torchvision before pip install mellea:

See also: Backends and Configuration | Getting Started