Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/ollama/llms.txt
Use this file to discover all available pages before exploring further.
OllamaEmbeddingModel implements EmbeddingModelInterface and sends requests to Ollama’s native /api/embed endpoint — not the OpenAI-compatible path. It supports both single and batch inputs, optional dimension control, and provider-specific pass-through options such as truncate and keep_alive.
Namespace
This class is not instantiated directly. Use
Ollama::model() to obtain a model instance and the Generate facade to dispatch requests.URL
Requests are sent to:nativeBaseUrl defaults to http://localhost:11434 and is distinct from the OpenAI-compatible baseUrl (http://localhost:11434/v1) used by text and image models. It can be configured independently:
nativeBaseUrl is not set explicitly, it is derived automatically by stripping the /v1 suffix from baseUrl.
Method
generate(EmbeddingRequest $request): EmbeddingResponse
Builds a request body and POSTs it to /api/embed, then validates and parses the response into an EmbeddingResponse.
Request body
The following fields are sent to Ollama:The model identifier string passed at construction — for example
'nomic-embed-text'.Array of input strings to embed, sourced from
$request->inputs. Ollama processes all inputs in a single batch call.Optional number of dimensions to truncate the output vectors to. Sourced from
$request->dimensions. Omitted from the request body if not set.Provider options merging
Any provider options passed via->providerOptions('ollama', [...]) are merged into the request body using array_replace_recursive, allowing you to set Ollama-specific fields:
| Option | Type | Description |
|---|---|---|
truncate | bool | Whether to truncate inputs to the model’s context window. Defaults to true in Ollama. |
keep_alive | string | Duration to keep the model loaded in memory, e.g. '10m' or '1h'. |
raw key inside provider options is also merged as a final passthrough, applied after all other fields. Use it to forward any undocumented or future Ollama fields without interference from the SDK’s merge logic.
Response Fields
One
EmbeddingData object per input string, in the same order as the input array.The embedding vector for the nth input. The number of dimensions matches the model’s native output size, or the requested
dimensions value if truncation was applied.Total number of tokens processed across all inputs, sourced from
prompt_eval_count in the Ollama response. Returns 0 if Ollama does not include token counts.The model string echoed back by Ollama in the response. Falls back to the requested model ID if the field is absent.
Total time taken for the request in nanoseconds, as reported by Ollama.
Time spent loading the model into memory in nanoseconds. Only present when Ollama includes this field.
Error Conditions
generate() raises an InvalidResponseException in two cases:
Unexpected embedding count — if the number of embedding vectors in the Ollama response does not match the number of input strings:
inputIndex of the offending vector to aid debugging.
