Skip to content

Ollama embeddings: dimensions provider option is sent twice, triggering "invalid option" warning #1010

Description

@timmcleod

Summary

When generating embeddings via the Ollama provider with a dimensions provider option, the option is included in the request payload twice, once as a top-level field, and again nested inside the options object. Ollama doesn't recognize dimensions as a valid model option (it expects things like temperature, num_ctx, etc. inside options), so it logs a warning on every request:

level=WARN source=types.go:977 msg="invalid option provided" option=dimensions

The embeddings still come back successfully, but production logs get spammed.

Version

  • prism-php/prism v0.99.22
  • Ollama (any recent version, the warning was added when Ollama tightened its option validation)

Reproduction

use Prism\Prism\Facades\Prism;                            

$response = Prism::embeddings()
    ->using('ollama', 'qwen3-embedding:0.6b')
    ->fromInput('hello world')                                                                                                                                                                                 
    ->withProviderOptions(['dimensions' => 1024])
    ->asEmbeddings();                                                                                                                                                                                          

This call succeeds and returns a 1024-dim embedding, but Ollama's server log shows:

level=WARN source=types.go:977 msg="invalid option provided" option=dimensions

Root cause

In src/Providers/Ollama/Handlers/Embeddings.php (lines 47–56):

$response = $this->client->post(                          
    'api/embed',
    Arr::whereNotNull([                                                                                                                                                                                        
        'model'      => $request->model(),
        'input'      => $request->inputs(),                                                                                                                                                                    
        'dimensions' => $request->providerOptions('dimensions'),
        'keep_alive' => $request->providerOptions('keep_alive'),                                                                                                                                               
        'options'    => $request->providerOptions() ?: null,   // ← includes dimensions + keep_alive again
    ])                                                                                                                                                                                                         
);                                                        

$request->providerOptions() (called with no key) returns the entire providerOptions array, so dimensions and keep_alive end up nested inside options in addition to being passed as top-level fields. Ollama then complains about the nested options.dimensions key.

Suggested fix

Exclude the keys that are already passed at the top level from the nested options payload:

$options = Arr::except($request->providerOptions(), ['dimensions', 'keep_alive']);

$response = $this->client->post(                                                                                                                                                                               
    'api/embed',
    Arr::whereNotNull([                                                                                                                                                                                        
        'model'      => $request->model(),                
        'input'      => $request->inputs(),
        'dimensions' => $request->providerOptions('dimensions'),
        'keep_alive' => $request->providerOptions('keep_alive'),                                                                                                                                               
        'options'    => $options ?: null,
    ])                                                                                                                                                                                                         
);                                                        

Introduced by #913 That PR added the top-level dimensions field but didn't exclude it from the nested options payload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions