# ollama_chat

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [connect-full.txt](https://docs.redpanda.com/connect-full.txt)

---
title: ollama_chat
latest-connect-version: 4.117.0
latest-operator-version: v26.2.5
latest-console-tag: v3.14.0
latest-redpanda-tag: v26.2.6
docname: processors/ollama_chat
page-component-name: connect
page-version: master
page-component-version: master
page-component-title: Connect
page-relative-src-path: processors/ollama_chat.adoc
page-edit-url: https://github.com/redpanda-data/rp-connect-docs/edit/main/modules/components/pages/processors/ollama_chat.adoc
description: Generates responses to messages in a chat conversation, using the Ollama API.
page-git-created-date: "2024-08-15"
page-git-modified-date: "2026-10-29"
page-generated-sources:
  - include: connect:components:partial$descriptions/processors/ollama_chat.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$availability/processors/ollama_chat.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$fields/processors/ollama_chat.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
  - include: connect:components:partial$examples/processors/ollama_chat.adoc
    generator: null
    version: null
    source: the component specs in https://github.com/redpanda-data/connect
page-generated-content: partial
---

<!-- Source: https://docs.redpanda.com/connect/components/processors/ollama_chat.md -->

Generates responses to messages in a chat conversation, using the Ollama API.

Introduced in version 4.32.0.

This processor sends prompts to your chosen Ollama large language model (LLM) and generates text from the responses, using the Ollama API. The model can also call external tools that you define in the [`tools`](#tools) field to retrieve more information to answer a prompt.

By default, the processor starts and runs a locally installed Ollama server. Alternatively, to use an already running Ollama server, add your server details to the `server_address` field. You can [download and install Ollama from the Ollama website](https://ollama.com/download).

For more information, see the [Ollama documentation](https://github.com/ollama/ollama/tree/main/docs) and [Examples](#examples).

#### Common

```yml
processor:
  label: ""
  ollama_chat:
    model: "" # No default (required)
    prompt: "" # No default (optional)
    image: "" # No default (optional)
    response_format: text
    max_tokens: 0 # No default (optional)
    temperature: 0 # No default (optional)
    save_prompt_metadata: false
    history: "" # No default (optional)
    tools: []
    runner:
      context_size: 0 # No default (optional)
      batch_size: 0 # No default (optional)
    server_address: "" # No default (optional)
```

#### Advanced

```yml
processor:
  label: ""
  ollama_chat:
    model: "" # No default (required)
    prompt: "" # No default (optional)
    system_prompt: "" # No default (optional)
    image: "" # No default (optional)
    response_format: text
    max_tokens: 0 # No default (optional)
    temperature: 0 # No default (optional)
    num_keep: 0 # No default (optional)
    seed: 0 # No default (optional)
    top_k: 0 # No default (optional)
    top_p: 0 # No default (optional)
    repeat_penalty: 0 # No default (optional)
    presence_penalty: 0 # No default (optional)
    frequency_penalty: 0 # No default (optional)
    stop: [] # No default (optional)
    save_prompt_metadata: false
    history: "" # No default (optional)
    max_tool_calls: 3
    tools: []
    runner:
      context_size: 0 # No default (optional)
      batch_size: 0 # No default (optional)
      gpu_layers: 0 # No default (optional)
      threads: 0 # No default (optional)
      use_mmap: false # No default (optional)
    server_address: "" # No default (optional)
    cache_directory: "" # No default (optional)
    download_url: "" # No default (optional)
```

## [](#fields)Fields

### [](#cache_directory)`cache_directory`

If `server_address` is not set, download the Ollama binary to this directory and use it as a model cache.

Requires version 4.34.0 or later.

**Type**: `string`

```yaml
# Examples:
cache_directory: /opt/cache/connect/ollama
```

### [](#download_url)`download_url`

If `server_address` is not set, download the Ollama binary from this URL. The default value is the official Ollama GitHub release for this platform.

Requires version 4.34.0 or later.

**Type**: `string`

### [](#frequency_penalty)`frequency_penalty`

A number between `-2.0` and `2.0` that the processor sends to the Ollama server as the `frequency_penalty` model option. Positive values penalize each token in proportion to how often it has already appeared in the text, which makes the model less likely to repeat the same line verbatim. A value of `0` is not sent, so the server’s default applies.

Requires version 4.34.0 or later.

**Type**: `float`

### [](#history)`history`

Include historical messages in a chat request. You must use a Bloblang query to create an array of objects in the form of `[{"role": "", "content":""}]` where:

-   `role` is the sender of the original messages, either `system`, `user`, `assistant`, or `tool`.

-   `content` is the text of the original messages.


Requires version 4.51.0 or later.

**Type**: `string`

### [](#image)`image`

An optional image to submit along with the `prompt` value. The result should be a byte array.

Requires version 4.38.0 or later.

**Type**: `string`

```yaml
# Examples:
image: 'root = this.image.decode("base64") # decode base64 encoded image'
```

### [](#max_tokens)`max_tokens`

The maximum number of tokens to predict and output. Limiting the amount of output means that requests are processed faster and have a fixed limit on the cost.

Requires version 4.34.0 or later.

**Type**: `int`

### [](#max_tool_calls)`max_tool_calls`

The maximum number of sequential calls you can make to external tools to retrieve additional information to answer a prompt.

Requires version 4.45.0 or later.

**Type**: `int`

**Default**: `3`

### [](#model)`model`

The name of the Ollama model to use. For a full list of models, see the [Ollama website](https://ollama.com/models).

**Type**: `string`

```yaml
# Examples:
model: llama3.1

# ---

model: gemma2

# ---

model: qwen2

# ---

model: phi3
```

### [](#num_keep)`num_keep`

Specify the number of tokens from the initial prompt to retain when the model resets its internal context. By default, this value is set to `4`. Use `-1` to retain all tokens from the initial prompt.

Requires version 4.34.0 or later.

**Type**: `int`

### [](#presence_penalty)`presence_penalty`

A number between `-2.0` and `2.0` that the processor sends to the Ollama server as the `presence_penalty` model option. Positive values penalize every token that has already appeared in the text, regardless of how often, which makes the model more likely to move on to new topics. A value of `0` is not sent, so the server’s default applies.

Requires version 4.34.0 or later.

**Type**: `float`

### [](#prompt)`prompt`

The user prompt you want to generate a response for. By default, the processor submits the entire payload of each message as a string.

This field supports [interpolation functions](https://docs.redpanda.com/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

### [](#repeat_penalty)`repeat_penalty`

Sets how strongly to penalize repetitions. A higher value, for example 1.5, will penalize repetitions more strongly. A lower value, for example 0.9, will be more lenient.

Requires version 4.34.0 or later.

**Type**: `float`

### [](#response_format)`response_format`

The format of the response the Ollama model generates. If specifying JSON output, then the `prompt` should specify that the output should be in JSON as well.

Requires version 4.34.0 or later.

**Type**: `string`

**Default**: `text`

**Options**: `text`, `json`

### [](#runner)`runner`

Options for the model runner that are used when the model is first loaded into memory.

Requires version 4.34.0 or later.

**Type**: `object`

### [](#runner-batch_size)`runner.batch_size`

The maximum number of requests to process in parallel.

**Type**: `int`

### [](#runner-context_size)`runner.context_size`

Sets the size of the context window used to generate the next token. Using a larger context window uses more memory and takes longer to process.

**Type**: `int`

### [](#runner-gpu_layers)`runner.gpu_layers`

Sets the number of layers to offload to the GPU for computation. This generally results in increased performance. By default, the runtime decides the number of layers dynamically.

**Type**: `int`

### [](#runner-threads)`runner.threads`

Sets the number of threads to use during response generation. For optimal performance, set this value to the number of physical CPU cores your system has. By default, the runtime decides the optimal number of threads.

**Type**: `int`

### [](#runner-use_mmap)`runner.use_mmap`

Map the model into memory. Set to `true` to load only the necessary parts of the model into memory. This setting is only supported on Unix systems.

**Type**: `bool`

### [](#save_prompt_metadata)`save_prompt_metadata`

Set to `true` to save the prompt value to a metadata field (`@prompt`) on the corresponding output message. If you use the `system_prompt` field, its value is also saved to an `@system_prompt` metadata field on each output message.

Requires version 4.42.0 or later.

**Type**: `bool`

**Default**: `false`

### [](#seed)`seed`

Sets the random number seed to use for generation. Setting this to a specific number will make the model generate the same text for the same prompt.

Requires version 4.34.0 or later.

**Type**: `int`

```yaml
# Examples:
seed: 42
```

### [](#server_address)`server_address`

The address of the Ollama server to use. Leave this field blank and the processor starts and runs a local Ollama server, or specify the address of your own local or remote server.

**Type**: `string`

```yaml
# Examples:
server_address: http://127.0.0.1:11434
```

### [](#stop)`stop[]`

Sets the stop sequences to use. When this pattern is encountered, the LLM stops generating text and returns the final response.

Requires version 4.34.0 or later.

**Type**: `array<string>`

### [](#system_prompt)`system_prompt`

The system prompt to submit along with the user prompt.

This field supports [interpolation functions](https://docs.redpanda.com/connect/configuration/interpolation/#bloblang-queries).

**Type**: `string`

### [](#temperature)`temperature`

The temperature of the model. Increasing the temperature makes the model answer more creatively.

Requires version 4.34.0 or later.

**Type**: `int`

### [](#tools)`tools[]`

The external tools the LLM can invoke, such as functions, APIs, or web browsing. You can build subpipelines of processors that include definitions of these tools, and the specified LLM can choose when to invoke them to help answer a prompt.

Requires version 4.45.0 or later.

**Type**: `array<object>`

**Default**: `[]`

### [](#tools-description)`tools[].description`

A description of this tool. The LLM uses it to decide whether to invoke the tool.

**Type**: `string`

### [](#tools-name)`tools[].name`

The name of this tool.

**Type**: `string`

### [](#tools-parameters)`tools[].parameters`

The parameters the LLM needs to provide to invoke this tool.

**Type**: `object`

### [](#tools-parameters-properties)`tools[].parameters.properties`

The parameters the LLM can provide when it invokes this tool, keyed by parameter name.

**Type**: `object`

### [](#tools-parameters-properties-description)`tools[].parameters.properties.description`

A description of this parameter.

**Type**: `string`

### [](#tools-parameters-properties-enum)`tools[].parameters.properties.enum[]`

The values this parameter is limited to. Leave empty to accept any value.

**Type**: `array<string>`

**Default**: `[]`

### [](#tools-parameters-properties-type)`tools[].parameters.properties.type`

The type of this parameter.

**Type**: `string`

### [](#tools-parameters-required)`tools[].parameters.required[]`

The names of the parameters the LLM must provide when it invokes this tool.

**Type**: `array<string>`

**Default**: `[]`

### [](#tools-processors)`tools[].processors[]`

The processors to run when the LLM invokes this tool. They receive a message whose payload is the tool call arguments as a JSON object, and their output is returned to the LLM as the tool result.

**Type**: `array<processor>`

### [](#top_k)`top_k`

Reduces the probability of generating nonsense. A higher value, for example `100`, will give more diverse answers. A lower value, for example `10`, will be more conservative.

Requires version 4.34.0 or later.

**Type**: `int`

### [](#top_p)`top_p`

Works together with `top-k`. A higher value, for example 0.95, will lead to more diverse text. A lower value, for example 0.5, will generate more focused and conservative text.

Requires version 4.34.0 or later.

**Type**: `float`

## [](#examples)Examples

### [](#use-llava-to-analyze-an-image)Use Llava to analyze an image

This example fetches image URLs from stdin and has a multimodal LLM describe the image.

```yaml
input:
  stdin:
    scanner:
      lines: {}
pipeline:
  processors:
    - http:
        verb: GET
        url: "${!content().string()}"
    - ollama_chat:
        model: llava
        prompt: "Describe the following image"
        image: "root = content()"
output:
  stdout:
    codec: lines
```

### [](#use-subpipelines-as-tool-calls)Use subpipelines as tool calls

This example allows llama3.2 to execute a subpipeline as a tool call to get more data.

```yaml
input:
  generate:
    count: 1
    mapping: |
      root = "What is the weather like in Chicago?"
pipeline:
  processors:
    - ollama_chat:
        model: llama3.2
        prompt: "${!content().string()}"
        tools:
          - name: GetWeather
            description: "Retrieve the weather for a specific city"
            parameters:
              required: ["city"]
              properties:
                city:
                  type: string
                  description: the city to lookup the weather for
            processors:
              - http:
                  verb: GET
                  url: 'https://wttr.in/${!this.city}?T'
                  headers:
                    # Spoof curl user-ageent to get a plaintext text
                    User-Agent: curl/8.11.1
output:
  stdout: {}
```