refactor: improve Ollama embedder, normalize model names, add error handling, update tests#4403
Merged
whysosaket merged 2 commits intomainfrom Mar 18, 2026
Merged
Conversation
…andling, update tests
18 tasks
whysosaket
approved these changes
Mar 18, 2026
jamebobob
pushed a commit
to jamebobob/mem0-vigil-recall
that referenced
this pull request
Mar 29, 2026
…andling, update tests (mem0ai#4403)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Migrates both the Python and TypeScript Ollama embedders from the deprecated
ollama.embeddings()API to the currentollama.embed()API. The old endpoint (/api/embeddings) usesprompt:andreturns
response.embedding, while the new endpoint (/api/embed) usesinput:and returnsresponse.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"fromollama listdue to strict string equality.
Fixes #4155
Type of change
How Has This Been Tested?
Python (4 tests passed):
test_embed_text— verifiesclient.embed()called withmodel=andinput=, returnsembeddings[0]test_ensure_model_exists— verifies pull is triggered when model is missingtest_ensure_model_exists_normalizes_latest_tag— verifiesnomic-embed-textmatchesnomic-embed-text:latesttest_embed_empty_response_raises— verifies ValueError on empty embeddingsTypeScript (7 tests passed):
embed()happy path with model and inputembed()non-string input coercionembedBatch()multiple inputsensureModelExists()skips pull when model presentensureModelExists()pulls when model missingensureModelExists()normalizes:latesttagembed()throws on empty embeddings responseChecklist:
Maintainer Checklist