Skip to content

Python: fix(ollama): preserve zero embedding keep_alive - #8928

Merged
Evan Mattson (moonbox3) merged 1 commit into
microsoft:mainfrom
rksharma-owg:codex/fix-ollama-embedding-keep-alive
Oct 1, 2026
Merged

Evan Mattson (moonbox3) merged 1 commit into
microsoft:mainfrom
rksharma-owg:codex/fix-ollama-embedding-keep-alive

Conversation

@rksharma-owg

Copy link
Copy Markdown
Contributor

Motivation & Context

Ollama embedding requests silently omit numeric keep_alive=0, preventing callers from requesting a zero keep-alive duration. A truthiness check treats the valid zero as an absent option.

Description & Review Guide

  • What are the major changes? Check keep_alive against None, matching the adjacent truncate handling. Add request-level tests through the real Ollama SDK for numeric zero, positive/negative durations, duration strings, and omission.
  • What is the impact of these changes? Explicit zero reaches /api/embed; existing nonzero values and omitted options retain their behavior. No API or dependency changes.
  • What do you want reviewers to focus on? Numeric zero and omission behavior at the HTTP boundary. The two zero cases fail before the fix; all seven parameterized cases pass afterward. The Windows/Linux Python 3.10–3.14 unit matrix, package coverage gate, all four code-quality jobs, and five live Ollama integration tests pass (test matrix and integration run, code quality run). Real-server probes confirm unloading for both 0 and 0.0. Existing skips and expected failures remain counted; package builds retain main's license-classifier deprecation warning.

Related Issue

Fixes #8927

Contribution Checklist

  • The code builds clean without any errors or warnings — wheel/sdist builds succeed; uv_build emits the existing license-classifier deprecation warning on main as well.
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix correctly handles zero without changing omission behavior and includes comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Ollama embedding requests so explicit numeric keep_alive=0 values reach the SDK and HTTP endpoint.

Changes:

  • Replaces the truthiness check with an explicit None check.
  • Adds HTTP-boundary coverage for zero, nonzero, string, and omitted values.
File Description
python/​packages/​ollama/​agent_framework_ollama/​_embedding_client.py Preserves zero-valued keep_alive options.
python/​packages/​ollama/​tests/​ollama/​test_ollama_embedding_client.py Verifies serialized request behavior through the Ollama SDK.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Oct 1, 2026
Merged via the queue into microsoft:main with commit e15c6dc Oct 1, 2026
49 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — e499fef2 Deployed Oct 1, 2026 by rksharma-owg via team_check #5723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: OllamaEmbeddingClient drops numeric zero keep_alive

3 participants