Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export type EngineConfig = {
model: string;
apiStyle: string;
apiKey: string | undefined;
// Per-request timeout override (EMBED_TIMEOUT_MS). `undefined` means
// "use embed-client.ts's own default" — must NOT be defaulted here.
timeoutMs: number | undefined;
};
rerank: {
baseUrl: string | undefined;
Expand All @@ -40,5 +43,8 @@ export type EngineConfig = {
// single constant is exactly how a small-model budget got applied to
// the default model's much larger context window.
maxDocChars: number | undefined;
// Per-request timeout override (RERANK_TIMEOUT_MS). `undefined` means
// "use rerank-client.ts's own default" — must NOT be defaulted here.
timeoutMs: number | undefined;
};
};
4 changes: 4 additions & 0 deletions src/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ const wiringConfig: MemoryConfig = {
model: "m",
apiStyle: "openai",
apiKey: undefined,
timeoutMs: undefined,
},
rerank: {
baseUrl: undefined,
model: undefined,
apiKey: undefined,
maxDocChars: undefined,
timeoutMs: undefined,
},
},
};
Expand All @@ -145,6 +147,7 @@ function baseConfig(
model: "m",
apiStyle: "openai",
apiKey: undefined,
timeoutMs: undefined,
},
rerank,
},
Expand All @@ -163,6 +166,7 @@ describe("createMemory — construction validation", () => {
model: "bge-reranker-base",
apiKey: undefined,
maxDocChars: 5_000,
timeoutMs: undefined,
}),
}),
).toThrow(RerankConfigError);
Expand Down
59 changes: 59 additions & 0 deletions src/mount-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import { loadMemoryConfig } from "./mount-config.ts";

const REQUIRED_ENV = {
KNOWLEDGE_DATABASE_URL: "postgres://localhost:5432/test",
EMBED_BASE_URL: "http://embed.example",
EMBED_MODEL: "test-model",
};

const ENV_KEYS = [
...Object.keys(REQUIRED_ENV),
"EMBED_TIMEOUT_MS",
"RERANK_TIMEOUT_MS",
];

let savedEnv: Record<string, string | undefined>;

beforeEach(() => {
savedEnv = {};
for (const key of ENV_KEYS) {
savedEnv[key] = process.env[key];
delete process.env[key];
}
for (const [key, value] of Object.entries(REQUIRED_ENV)) {
process.env[key] = value;
}
});

afterEach(() => {
for (const key of ENV_KEYS) {
if (savedEnv[key] === undefined) delete process.env[key];
else process.env[key] = savedEnv[key];
}
});

describe("loadMemoryConfig — EMBED_TIMEOUT_MS / RERANK_TIMEOUT_MS", () => {
it("leaves embed.timeoutMs and rerank.timeoutMs undefined when unset, so the clients' own defaults apply", () => {
const config = loadMemoryConfig();
expect(config.memory.embed.timeoutMs).toBeUndefined();
expect(config.memory.rerank.timeoutMs).toBeUndefined();
});

it("flows EMBED_TIMEOUT_MS through to embed.timeoutMs", () => {
process.env.EMBED_TIMEOUT_MS = "20000";
const config = loadMemoryConfig();
expect(config.memory.embed.timeoutMs).toBe(20_000);
});

it("flows RERANK_TIMEOUT_MS through to rerank.timeoutMs", () => {
process.env.RERANK_TIMEOUT_MS = "15000";
const config = loadMemoryConfig();
expect(config.memory.rerank.timeoutMs).toBe(15_000);
});

it("rejects a non-positive-integer EMBED_TIMEOUT_MS", () => {
process.env.EMBED_TIMEOUT_MS = "not-a-number";
expect(() => loadMemoryConfig()).toThrow("EMBED_TIMEOUT_MS must be a positive integer");
});
});
2 changes: 2 additions & 0 deletions src/mount-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export function loadMemoryConfig(): MemoryConfig {
model: requireEnv("EMBED_MODEL"),
apiStyle: optionalEnv("EMBED_API_STYLE") ?? "openai",
apiKey: optionalEnv("EMBED_API_KEY"),
timeoutMs: optionalIntEnv("EMBED_TIMEOUT_MS"),
},
rerank: {
baseUrl: optionalEnv("RERANK_BASE_URL"),
model: optionalEnv("RERANK_MODEL"),
apiKey: optionalEnv("RERANK_API_KEY"),
maxDocChars: optionalIntEnv("RERANK_MAX_DOC_CHARS"),
timeoutMs: optionalIntEnv("RERANK_TIMEOUT_MS"),
},
},
};
Expand Down
4 changes: 4 additions & 0 deletions src/services/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ function toEmbedClientConfig(embed: EngineConfig["embed"]): EmbedClientConfig {
modelId: embed.model,
apiStyle: embed.apiStyle as EmbedClientConfig["apiStyle"],
...(embed.apiKey !== undefined ? { apiKey: embed.apiKey } : {}),
...(embed.timeoutMs !== undefined ? { timeoutMs: embed.timeoutMs } : {}),
};
}

Expand All @@ -694,6 +695,9 @@ export function toRerankClientConfig(
...(rerank.maxDocChars !== undefined
? { maxDocChars: rerank.maxDocChars }
: {}),
...(rerank.timeoutMs !== undefined
? { timeoutMs: rerank.timeoutMs }
: {}),
};
}

Expand Down
Loading