---
id: local-model
lang: en
title: "Local models with Ollama: similar interface, different capabilities"
prerequisites: [first-chain, debugging]
created: 2026-10-16
updated: 2026-10-16
source_lectures: [12]
status: documented-from-subtitles
---

# Local models with Ollama: similar interface, different capabilities

## Objective and entry check

Distinguish a fake model, real local inference, and a hosted model service. Understand what changing an integration preserves and what it does not. Prerequisites: chains and response messages.

Before continuing: is a local model the same as `FakeListChatModel`? Does sharing `invoke` guarantee equally good answers?

<details><summary>Entry-check answer</summary>

No. A fake model returns prepared replies; a real local model performs inference. A common calling contract does not guarantee equal quality or capabilities.

</details>

## Why run locally?

Using a model does not always require sending input to a hosted service. With downloadable weights and suitable runtime software, inference can happen on our own machine. This changes control over execution location, network dependency, and per-request service charges. In exchange, we supply memory, loading time, and processing resources.

This explains architectural motivation, not an exact historical invention date. In lecture 012, the instructor substitutes a small Gemma 3 model through Ollama. His observed answer is faster but does not satisfy every instruction. That is an observation about his experiment, not a universal rule about local models.

“Open weights” also does not mean all training code and data are freely available. Usage conditions depend on the model's license.

## Three separate layers

![The application, Ollama service, and model weights have distinct responsibilities](../../assets/012-local-model/layers-en.svg)

- Our application chooses the template, input, chain, and use of the answer.
- Ollama is model-running software/service, not the name of one particular model.
- The selected model has weights and capabilities that must fit the task.

A local inference path does not automatically make the entire application offline. Web search or cloud tracing still uses the network. Absence of an API invoice does not eliminate hardware or energy costs.

## Basic commands and a subtitle correction

The [Ollama quickstart](https://docs.ollama.com/quickstart) distinguishes listing models with `ollama list` and interacting with them through `ollama run`. `ollama pull` downloads weights; `ollama serve` starts the service rather than an interactive conversation with a named model.

For a model already installed:

```powershell
ollama list
ollama run qwen3-local:latest
```

This name is the installed model's tag on the machine used for our experiment. Elsewhere, use a tag from your own `ollama list`. Understanding the lesson does not require downloading this model or the instructor's larger recommendation.

## The usual LangChain integration

`langchain-ollama` supplies `ChatOllama`; its model tag should match an installed model. [Official integration guide](https://docs.langchain.com/oss/python/integrations/chat/ollama)

```python
from langchain_ollama import ChatOllama

model = ChatOllama(model="YOUR_INSTALLED_MODEL_TAG")
chain = prompt | model
result = chain.invoke({"information": information})
```

This fragment uses the preceding lesson's template and input. The integration package was absent from the inspected environment, so we do not report this particular path as tested. In a uv project, `uv add langchain-ollama` changes dependencies; inspect and record the resulting resolution.

## What was actually tested?

[ollama_local.py](../../examples/ollama_local.py) exposes the underlying layers through a small educational bridge: it converts `PromptValue` to a JSON message, sends it only to `127.0.0.1:11434/api/chat`, and wraps the reply in `AIMessage`. It is not `ChatOllama` and does not implement all its features. The request follows the [chat API reference](https://docs.ollama.com/api/chat).

```powershell
python ollama_local.py --model qwen3-local:latest
```

Using the previous lesson's fictional Mina input, the installed model actually ran and produced:

```text
Mina teaches Python and built a robot in 2024.
```

The completion reported `stop`. No weights were downloaded, and cloud tracing was disabled for this experiment. This is one successful smoke test, not a general quality or tool-use evaluation. The script limits generation length and requests `think=False`; support for that setting depends on the model.

## Diagnose the right layer

| Symptom | First inspection |
|---|---|
| Connection fails | Local service and address/port |
| Model is not found | Exact installed model tag |
| Response is slow | Initial loading, model size, and available resources |
| Instructions are not followed | Actual input, model capability, and evaluation criteria |

Similar method names do not equalize context limits, structured output, or tool calling. Test the capabilities needed by an agent separately.

## Independent practice

1. Local inference works, but enabling LangSmith makes input visible in its dashboard. Is that contradictory?
2. Why not always select the smallest model solely for speed?
3. How do `ollama run` and `ollama serve` differ?

<details><summary>Answer 1</summary>

No. Model computation is local, while a separate tracing path can upload data. Inspect the application's complete data flow.

</details>

<details><summary>Answer 2</summary>

Speed is one criterion. Test instruction following, quality, context capacity, and required capabilities against representative tasks too.

</details>

<details><summary>Answer 3</summary>

The former opens interactive execution for a specified model; the latter starts a request-serving process. An already running service does not need a second instance on the same port.

</details>

## Recall and continuation

Without the text, explain the path from application to model weights and name two things a shared interface does not guarantee. Continue to [LangSmith tracing](../013-langsmith/en.md) if these boundaries are clear; otherwise redraw the three layers from memory.

Course source: the complete lecture 012 subtitle file. The diagram, API bridge, and Qwen experiment are supplementary; the instructor's model was not tested at this stage. Sources checked on 2026-10-16. Video not visually reviewed.
