From 9fc3327a768026852daf6e22863df44031d3f16c Mon Sep 17 00:00:00 2001 From: ZengGanghui Date: Fri, 27 Mar 2026 06:20:32 +0800 Subject: [PATCH] feat: add configurable rerank timeout (rerankTimeoutMs) The cross-encoder rerank request timeout was hardcoded at 5 seconds, which is too aggressive for self-hosted rerank services that may need 6-7 seconds to respond. This adds a option to RetrievalConfig and raises the default to 10 seconds. - Add field to RetrievalConfig interface - Use instead of hardcoded 5000 - Backwards compatible: existing configs without the field get 10s default --- src/retriever.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/retriever.ts b/src/retriever.ts index 900db75..f7202a4 100644 --- a/src/retriever.ts +++ b/src/retriever.ts @@ -45,6 +45,8 @@ export interface RetrievalConfig { rerankModel?: string; /** Reranker API endpoint (default: https://api.jina.ai/v1/rerank). */ rerankEndpoint?: string; + /** Reranker request timeout in milliseconds (default: 10000). */ + rerankTimeoutMs?: number; /** Reranker provider format. Determines request/response shape and auth header. * - "jina" (default): Authorization: Bearer, string[] documents, results[].relevance_score * - "siliconflow": same format as jina (alias, for clarity) @@ -858,9 +860,10 @@ export class MemoryRetriever { results.length, ); - // Timeout: 5 seconds to prevent stalling retrieval pipeline + // Timeout to prevent stalling retrieval pipeline + const RERANK_TIMEOUT_MS = this.config.rerankTimeoutMs ?? 10_000; const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 5000); + const timeout = setTimeout(() => controller.abort(), RERANK_TIMEOUT_MS); const response = await fetch(endpoint, { method: "POST",