Haystack is a Python framework for building pipelines out of components: a prompt builder feeds a generator, the generator calls a model, and the reply comes back as a structured result. Its Ollama integration gives you OllamaChatGenerator, a component that enables chat completion using an LLM running on Ollama. It is a different framework from LangChain and LlamaIndex, with its own package, its own message objects, and its own pipeline wiring, and it talks to the same local server at http://localhost:11434.
Install and start the two pieces
You need a running instance of Ollama and the ollama-haystack package. The Haystack docs give a fast way to run Ollama with Docker:
docker run -d -p 11434:11434 --name ollama ollama/ollama:latest
docker exec ollama ollama pull zephyr
If Ollama is already installed on your system, pull the model directly with ollama pull zephyr instead. Then install the integration package:
pip install ollama-haystack
Call the model on its own
The docs give the standalone example with the zephyr model. OllamaChatGenerator needs a model name and a url to work; by default it uses the qwen3:0.6b model and the http://localhost:11434 URL. Messages are ChatMessage objects, each with a role such as user, assistant, or system:
from haystack_integrations.components.generators.ollama import OllamaChatGenerator
from haystack.dataclasses import ChatMessage
generator = OllamaChatGenerator(
model="zephyr",
url="http://localhost:11434",
generation_kwargs={
"num_predict": 100,
"temperature": 0.9,
},
)
messages = [
ChatMessage.from_system("\nYou are a helpful, respectful and honest assistant"),
ChatMessage.from_user("What's Natural Language Processing?"),
]
print(generator.run(messages=messages))
The run returns a dictionary whose replies key holds a list of the model’s alternative replies, each one a ChatMessage. That is where your answer lives: read response["replies"][0], not the printed dictionary as a whole.
Put it in a pipeline
On its own, the generator answers one list of messages. In a pipeline it sits after a ChatPromptBuilder, which is its most common position. The docs wire it like this: create a Pipeline, add a prompt_builder component and an llm component holding the OllamaChatGenerator, then connect them with pipe.connect("prompt_builder.prompt", "llm.messages"). The prompt builder fills the template variables, for example a location such as Berlin, and the generator answers with the same local model. The generator also supports function calling through a tools parameter, and streaming through a streaming_callback, using the built-in print_streaming_chunk to print tokens as they arrive.
Try it: three checks from install to reply
| Check | What you should see | What it means |
|---|---|---|
| Model pulled | ollama pull zephyr finishes, or docker exec ollama ollama pull zephyr in Docker |
The model is on your machine |
| Package installed | pip install ollama-haystack finishes |
Python can import OllamaChatGenerator |
| Reply | generator.run(messages=messages) returns a replies list with an answer to “What’s Natural Language Processing?” |
The local model answered through Haystack |
Expected result. We checked the Haystack OllamaChatGenerator documentation, which gives the Docker commands, the pip install, the zephyr example, the default model and URL, and the pipeline wiring. We did not install the package, pull a model, or run the script on this machine.
Limits
The model name must match a model Ollama actually has: if you never pulled zephyr, the generator has nothing to call, so pull it first or change the model value to one you did pull. The url must point at your Ollama server; the default is http://localhost:11434, and a Docker Ollama needs the published port instead. Streaming works only with a single response, so if a provider supports multiple candidates, set n=1. The example’s generation_kwargs set num_predict to 100 and temperature to 0.9, which caps the reply length and makes it more varied; change them only if you know what they do. We did not test any of this ourselves.
