Skip to content

refactor: improve Ollama embedder, normalize model names, add error handling, update tests#4403

Merged
whysosaket merged 2 commits intomainfrom
fix/ollama-deprecated-embeddings-api
Mar 18, 2026
Merged

refactor: improve Ollama embedder, normalize model names, add error handling, update tests#4403
whysosaket merged 2 commits intomainfrom
fix/ollama-deprecated-embeddings-api

Conversation

@kartik-mem0
Copy link
Copy Markdown
Contributor

Description

Migrates both the Python and TypeScript Ollama embedders from the deprecated ollama.embeddings() API to the current ollama.embed() API. The old endpoint (/api/embeddings) uses prompt: and
returns response.embedding, while the new endpoint (/api/embed) uses input: and returns response.embeddings[0]. This breaks for anyone running Ollama server 0.17+.

Also fixes a sneaky bug where ensureModelExists() would trigger a redundant model pull on every startup because "nomic-embed-text" never matched "nomic-embed-text:latest" from ollama list
due to strict string equality.

Fixes #4155

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

Python (4 tests passed):

  • test_embed_text — verifies client.embed() called with model= and input=, returns embeddings[0]
  • test_ensure_model_exists — verifies pull is triggered when model is missing
  • test_ensure_model_exists_normalizes_latest_tag — verifies nomic-embed-text matches nomic-embed-text:latest
  • test_embed_empty_response_raises — verifies ValueError on empty embeddings

TypeScript (7 tests passed):

  • embed() happy path with model and input
  • embed() non-string input coercion
  • embedBatch() multiple inputs
  • ensureModelExists() skips pull when model present
  • ensureModelExists() pulls when model missing
  • ensureModelExists() normalizes :latest tag
  • embed() throws on empty embeddings response

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Maintainer Checklist

@whysosaket whysosaket merged commit 7539463 into main Mar 18, 2026
11 checks passed
@whysosaket whysosaket deleted the fix/ollama-deprecated-embeddings-api branch March 18, 2026 18:04
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama embedder uses deprecated embeddings() API — should use embed() with input: field

2 participants