Gemini embeddings return HTTP response objects instead of numeric vectors
Environment
- Zotero GPT: 3.1.8
- Zotero: 9.0.1
- Embedding provider: Gemini / google
- Embedding model: gemini-embedding-2
- API: https://generativelanguage.googleapis.com/v1beta
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.valuesresponse.embeddingresponse.embeddings[0].valuesresponse.embeddings[0].embedding.valuesresponse.embeddings[0].embeddingresponse.data[0].embedding
Then return something like:
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.
Source: MuiseDestiny/zotero-gpt