Skip to content

Commit 2cdb519

Browse files
committed
fix(knowledge): add retry to Ollama search embedding generation
1 parent 7afb708 commit 2cdb519

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

apps/sim/lib/knowledge/embeddings.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,20 @@ export async function generateSearchEmbedding(
452452
const modelName = embeddingModel.slice(7)
453453
const baseUrl = getOllamaBaseUrl(ollamaBaseUrl)
454454
logger.info(`Using Ollama (${baseUrl}) for search embedding with model ${modelName}`)
455-
const embeddings = await callOllamaEmbeddingAPI([query], modelName, baseUrl)
455+
const embeddings = await retryWithExponentialBackoff(
456+
() => callOllamaEmbeddingAPI([query], modelName, baseUrl),
457+
{
458+
maxRetries: 3,
459+
initialDelayMs: 1000,
460+
maxDelayMs: 10000,
461+
retryCondition: (error: unknown) => {
462+
if (error instanceof EmbeddingAPIError) {
463+
return error.status === 429 || error.status >= 500
464+
}
465+
return isRetryableError(error)
466+
},
467+
}
468+
)
456469
return embeddings[0]
457470
}
458471

0 commit comments

Comments
 (0)