Bug Description (Detailed Analysis)
After PR #621 fixed Ollama 0.20.5+ single embedding, batch embedding now fails because /api/embeddings only accepts a single string prompt field, not an array.
Error
Error: Failed to generate batch embeddings from Ollama: Ollama embedding failed: 400 Bad Request ??{"error":"json: cannot unmarshal array into Go struct field EmbeddingRequest.prompt of type string"}
Root Cause Analysis
PR #621 Background
PR #621 (fixing Issue #620) discovered that Ollama 0.20.5+ returns empty arrays when using /v1/embeddings endpoint. The fix switched to using Ollama's native /api/embeddings endpoint with the prompt field instead:
// PR #621 fix in embedWithNativeFetch()
const ollamaPayload = {
model: payload.model,
prompt: payload.input, // <-- This works for single string
};
The Regression
The problem is that payload.input is not always a string. When embedMany() builds a batch payload, it passes an array:
// In embedMany()
const response = await this.embedWithRetry(
this.buildPayload(validTexts, task), // <-- validTexts is string[]
signal,
);
// In buildPayload()
const payload = {
model: this.model,
input, // <-- When input is string[], this becomes input: ["a", "b", "c"]
};
So when embedWithNativeFetch() receives the payload and sets prompt: payload.input, it sends an array where Ollama expects a string:
// What Ollama receives:
{
"model": "jina-v5-retrieval-test",
"prompt": ["a", "b", "c"] // <-- Array, but Ollama expects string!
}
// Ollama error:
"json: cannot unmarshal array into Go struct field EmbeddingRequest.prompt of type string"
Why Single Works But Batch Fails
| Scenario |
payload.input type |
Works? |
embedPassage("hello") |
string |
✅ |
embedQuery("hello") |
string |
✅ |
embedBatchPassage(["a","b"]) |
string[] |
❌ |
Suggested Fix
This is a routing fix based on verified behavior, not a universal solution.
Limitation: This assumes /v1/embeddings batch mode is valid for the target Ollama/model combination, which was verified in local testing with jina-v5-retrieval-test.
Testing
Local testing confirms both single and batch work correctly:
| Test |
Endpoint |
Input |
Result |
| Single |
/api/embeddings |
prompt: string |
✅ SUCCESS (1024 dims) |
| Batch 3 items |
/v1/embeddings |
input: string[] |
✅ SUCCESS (3 embeddings) |
| Batch 1 item |
/v1/embeddings |
input: string[] |
✅ SUCCESS |
Model: jina-v5-retrieval-test
Related
Bug Description (Detailed Analysis)
After PR #621 fixed Ollama 0.20.5+ single embedding, batch embedding now fails because
/api/embeddingsonly accepts a single stringpromptfield, not an array.Error
Root Cause Analysis
PR #621 Background
PR #621 (fixing Issue #620) discovered that Ollama 0.20.5+ returns empty arrays when using
/v1/embeddingsendpoint. The fix switched to using Ollama's native/api/embeddingsendpoint with thepromptfield instead:The Regression
The problem is that
payload.inputis not always a string. WhenembedMany()builds a batch payload, it passes an array:So when
embedWithNativeFetch()receives the payload and setsprompt: payload.input, it sends an array where Ollama expects a string:Why Single Works But Batch Fails
embedPassage("hello")stringembedQuery("hello")stringembedBatchPassage(["a","b"])string[]Suggested Fix
This is a routing fix based on verified behavior, not a universal solution.
/api/embeddings+prompt(PR fix(embedder): use /api/embeddings + prompt for Ollama 0.20.5+ #621 unchanged)/v1/embeddings+input[]Limitation: This assumes
/v1/embeddingsbatch mode is valid for the target Ollama/model combination, which was verified in local testing withjina-v5-retrieval-test.Testing
Local testing confirms both single and batch work correctly:
/api/embeddingsprompt: string/v1/embeddingsinput: string[]/v1/embeddingsinput: string[]Model:
jina-v5-retrieval-testRelated