Gemini embeddings return HTTP response objects instead of numeric vectors

Author: mrpl327Created May 26, 2026Updated Jun 8, 2026

Environment

Problem

When using custom Gemini embeddings in AskPDF / related text search, similarity search fails with an error similar to:

cosine-similarity()::invalid input argument. First argument must be an array.
Value: [object XMLHttpRequest]

Cause

The Gemini/google embedding provider appears to return the raw Zotero.HTTP.request(...) results from Promise.all(...) instead of extracting numeric embedding vectors.

In the bundled 3.1.8 script, the google provider sends requests to Gemini :embedContent, but then returns the HTTP response objects directly. As a result, cosine similarity receives XMLHttpRequest/HTTP response objects instead of number[] vectors.

Expected behavior

The Gemini embedding provider should return number[][], one numeric vector per input text, compatible with OpenAI-compatible embedding providers and cosine similarity.

Suggested fix

Parse the JSON response and extract a numeric vector before returning. Gemini/OpenAI-compatible response shapes may include:

  • response.embedding.values
  • response.embedding
  • response.embeddings[0].values
  • response.embeddings[0].embedding.values
  • response.embeddings[0].embedding
  • response.data[0].embedding

Then return something like:

javascript
return responses.map(extractVector);

instead of returning the raw HTTP responses.

For gemini-embedding-2, it may also be safer not to send the old taskType field unless the API explicitly supports it for that model.

Notes

OpenAI-compatible embeddings such as Qwen/Qwen3-Embedding-8B work through the data[].embedding format. The issue seems specific to the Gemini/google embedding branch.