Skip to content

Commit a01e47e

Browse files
committed
feat: make rerank timeout configurable via rerankTimeoutMs (closes #346)
1 parent 7fe2ae0 commit a01e47e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/retriever.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface RetrievalConfig {
5858
| "pinecone"
5959
| "dashscope"
6060
| "tei";
61+
/** Rerank API timeout in milliseconds (default: 5000). Increase for local/CPU-based rerank servers. */
62+
rerankTimeoutMs?: number;
6163
/**
6264
* Length normalization: penalize long entries that dominate via sheer keyword
6365
* density. Formula: score *= 1 / (1 + log2(charLen / anchor)).
@@ -127,6 +129,7 @@ export const DEFAULT_RETRIEVAL_CONFIG: RetrievalConfig = {
127129
filterNoise: true,
128130
rerankModel: "jina-reranker-v3",
129131
rerankEndpoint: "https://api.jina.ai/v1/rerank",
132+
rerankTimeoutMs: 5000,
130133
lengthNormAnchor: 500,
131134
hardMinScore: 0.35,
132135
timeDecayHalfLifeDays: 60,
@@ -858,9 +861,9 @@ export class MemoryRetriever {
858861
results.length,
859862
);
860863

861-
// Timeout: 5 seconds to prevent stalling retrieval pipeline
864+
// Timeout: configurable via rerankTimeoutMs (default: 5000ms)
862865
const controller = new AbortController();
863-
const timeout = setTimeout(() => controller.abort(), 5000);
866+
const timeout = setTimeout(() => controller.abort(), this.config.rerankTimeoutMs ?? 5000);
864867

865868
const response = await fetch(endpoint, {
866869
method: "POST",
@@ -928,7 +931,7 @@ export class MemoryRetriever {
928931
}
929932
} catch (error) {
930933
if (error instanceof Error && error.name === "AbortError") {
931-
console.warn("Rerank API timed out (5s), falling back to cosine");
934+
console.warn(`Rerank API timed out (${this.config.rerankTimeoutMs ?? 5000}ms), falling back to cosine`);
932935
} else {
933936
console.warn("Rerank API failed, falling back to cosine:", error);
934937
}

0 commit comments

Comments
 (0)