# embedding.EmbeddingOllama

Creates an embedding function provider backed by a local Ollama server.

Usage

[Source](https://github.com/posit-dev/raghilda/blob/main/src/raghilda/_embedding_ollama.py#L13-L127)

``` python
embedding.EmbeddingOllama(
    model="embeddinggemma-2:270m-q8_0-text",
    base_url="http://localhost:11434/v1",
    api_key=None,
    batch_size=20,
    prompts=None,
)
```

Implements the EmbeddingProvider interface.

This provider uses Ollama's OpenAI-compatible API with defaults for a local server. Stores created with it can be reconnected without setting `OPENAI_API_KEY`.

Pull an embedding model before using it (e.g., `ollama pull embeddinggemma-2:270m-q8_0-text`). Browse available embedding models at [ollama.com/search](https://ollama.com/search?c=embedding).

Set `prompts=` when creating the provider to configure the model's query and document prefixes. On each [embed()](../reference/embedding.EmbeddingProvider.md#raghilda.embedding.EmbeddingProvider.embed) call, `input_type=` selects which prefix to use for the supplied texts. It defaults to [EmbedInputType.DOCUMENT](../reference/embedding.EmbedInputType.md#raghilda.embedding.EmbedInputType.DOCUMENT). Stores select the input type automatically during ingestion and retrieval.

## Parameters

`model: str = "embeddinggemma-2:270m-q8_0-text"`  
The Ollama embedding model to use. Default is "embeddinggemma-2:270m-q8_0-text", a text-only build. The default is a pinned tag rather than `:latest` because the store saves only the model name, and `:latest` can resolve to different builds over time or across platforms, which would silently degrade retrieval.

`base_url: str = "http://localhost:11434/v1"`  
The base URL for the Ollama server's OpenAI-compatible API. Default is "http://localhost:11434/v1". Change this when Ollama runs on another machine or port.

`api_key: str | None = None`  
The API key sent with each request. Ollama does not check it, so this is only needed when the server sits behind a proxy that requires one. If None, uses `OLLAMA_API_KEY` from the environment, or a placeholder if unset. Keys are not saved with the store. Set `OLLAMA_API_KEY` before reconnecting to a store that uses an authenticated proxy.

`batch_size: int = 20`  
The number of texts to process in each batch when calling the API.

`prompts: dict[EmbedInputType, str] | None = None`  
Optional prefix strings keyed by EmbedInputType. The `input_type` argument to [embed()](../reference/embedding.EmbeddingProvider.md#raghilda.embedding.EmbeddingProvider.embed) selects the prefix to add to each text in that call. Use the query and document prefixes recommended by your model. If no prefix is configured for the selected type, text is sent unchanged. These settings are saved with the store.

## Examples

``` python
from raghilda.embedding import EmbeddingOllama, EmbedInputType

provider = EmbeddingOllama(
    model="embeddinggemma-2:270m-q8_0-text",
    prompts={
        EmbedInputType.QUERY: "task: search result | query: ",
        EmbedInputType.DOCUMENT: "title: none | text: ",
    },
)
document_embeddings = provider.embed(
    ["Authentication requires an API key."],
    input_type=EmbedInputType.DOCUMENT,
)
query_embeddings = provider.embed(
    ["How do I configure authentication?"],
    input_type=EmbedInputType.QUERY,
)
```
