Skip to content

fix(py/plugins/ollama): return one embedding per document - #181

Open
pcbeingused33 wants to merge 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/ollama-embedding-document-cardinality
Open

pcbeingused33 wants to merge 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/ollama-embedding-document-cardinality

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

The Ollama embedder sends each text part as a separate input string. Ollama returns one vector per string, so a multipart document shifts the vectors returned by embed_many out of alignment with the input documents.

Join each document's text parts with newlines before sending the batch to Ollama. This keeps one input string per document and preserves document order.

The regression test simulates one vector per string. With two documents containing three text parts in total, it reproduced three vectors before the fix and verifies two ordered vectors after it. All 254 non-integration Ollama tests passed. The local Ollama server was unavailable for a live reproduction.

Disclosure: this change was prepared with AI assistance.

@huangjeff5 huangjeff5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Pushed a small cleanup (31a0e55) to use doc.text so Ollama matches Document.text, OpenAI, and Vertex multimodal (and avoids stray newlines on empty text parts).

@huangjeff5
huangjeff5 enabled auto-merge (squash) November 30, 2026 19:52
@huangjeff5

Copy link
Copy Markdown
Collaborator

@pcbeingused33 — same cla/google username mismatch here (pcbeingused333 -> pcbeingused33). Once your GitHub username is updated at https://cla.developers.google.com/clas and rescanned in the cla/google check details, auto-merge will land this automatically.

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

@googlebot I fixed it.

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

@huangjeff5 the CLA is now linked to this account: the new PRs #271, #272 and #273 pass cla/google. The red check here (and on #180 and #182) is from the 11-30 run. Could you re-run it on these three when you have a moment? If a new push is easier, I can push an empty commit instead. Thanks!

This branch has not been deployed

No deployments
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.

2 participants