Skip to content

Commit db0ac3c

Browse files
committed
fix: bound semantic evaluator requests
1 parent 2114781 commit db0ac3c

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

integrations/search-nlp/eval/measure-residency.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
33
import { mkdir, rename, writeFile } from "node:fs/promises";
44
import { dirname } from "node:path";
55
import { promisify } from "node:util";
6+
import { fetchJson } from "@openmapx/core";
67
import { isPrivateEndpoint } from "../provider-config.js";
78
import { SEMANTIC_DIMENSIONS, SEMANTIC_MODEL } from "../semantic-taxonomy-types.js";
89

@@ -11,6 +12,7 @@ export const MAX_CONTAINER_LIMIT_BYTES = 8 * 1024 ** 3;
1112
export const MINIMUM_HEADROOM_BYTES = 1024 ** 3;
1213
const MINIMUM_ROUNDS = 5;
1314
const EVIDENCE_MAX_AGE_MS = 24 * 60 * 60 * 1_000;
15+
const OLLAMA_REQUEST_TIMEOUT_MS = 2 * 60_000;
1416
const EMBEDDING_PROMPT = "Instruct: classify a generic map request\nQuery: a quiet place to read";
1517
const PARSER_PROMPT = "Return a short JSON object for a generic map search for a library.";
1618

@@ -186,10 +188,22 @@ export function parseDockerStatsMemory(input: string): number {
186188
return bytes;
187189
}
188190

189-
async function jsonRequest(endpoint: string, path: string, init?: RequestInit): Promise<unknown> {
190-
const response = await fetch(`${endpoint}${path}`, init);
191-
if (!response.ok) throw new Error(`Ollama request failed with HTTP ${response.status}`);
192-
return response.json() as Promise<unknown>;
191+
interface OllamaJsonRequestInit {
192+
method: string;
193+
headers: Record<string, string>;
194+
body: string;
195+
}
196+
197+
async function jsonRequest(
198+
endpoint: string,
199+
path: string,
200+
init?: OllamaJsonRequestInit,
201+
): Promise<unknown> {
202+
return fetchJson<unknown>(`${endpoint}${path}`, {
203+
label: "Ollama",
204+
timeoutMs: OLLAMA_REQUEST_TIMEOUT_MS,
205+
...(init ? { headers: init.headers, init: { method: init.method, body: init.body } } : {}),
206+
});
193207
}
194208

195209
function residentModels(

integrations/search-nlp/eval/run.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
22
import { dirname } from "node:path";
33
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
4+
import { fetchJson } from "@openmapx/core";
45
import { createPassthroughCache } from "@openmapx/integration-framework/testing";
56
import { buildSemanticCategoryCatalog } from "@openmapx/presets";
67
import { createOllamaEmbeddingClient } from "../ollama-embeddings.js";
@@ -327,9 +328,10 @@ export function measureSemanticBypassLatency(
327328
}
328329

329330
async function installedModels(endpoint: string): Promise<Map<string, string>> {
330-
const response = await fetch(`${endpoint}/api/tags`);
331-
if (!response.ok) throw new Error(`Ollama tags HTTP ${response.status}`);
332-
const value = (await response.json()) as { models?: Array<{ name?: string; digest?: string }> };
331+
const value = await fetchJson<{ models?: Array<{ name?: string; digest?: string }> }>(
332+
`${endpoint}/api/tags`,
333+
{ label: "Ollama tags" },
334+
);
333335
if (!Array.isArray(value.models)) throw new Error("Ollama tags response is malformed");
334336
return new Map(
335337
value.models.flatMap((model) =>

0 commit comments

Comments
 (0)