{"record":{"id":"4ef1527ff9b393c1","repo":"abhigyanpatwari/GitNexus","slug":"embedding-endpoint-returned-empty-response-safe","errorCode":null,"errorMessage":"Embedding endpoint returned empty response (${safeUrl(url)})","messagePattern":"Embedding endpoint returned empty response \\((.+?)\\)","errorType":"exception","errorClass":"HttpEmbeddingError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/embeddings/http-client.ts","lineNumber":663,"sourceCode":"  const url = `${config.baseUrl}/embeddings`;\n  const items = await httpEmbedBatch(\n    url,\n    [text],\n    config.model,\n    config.apiKey,\n    0,\n    config.requestDimensions,\n    requestOptions,\n    config.maxAttempts,\n    config.retryCapMs,\n    config.minIntervalMs,\n    config.timeoutMs,\n  );\n  // Defensive backstop like the `httpEmbed` one above: an empty `data` array is\n  // now a cardinality mismatch (0 vectors for 1 text) rejected and retried\n  // inside `httpEmbedBatch`, so this branch is unreachable in practice.\n  if (!items.length) {\n    throw new HttpEmbeddingError(`Embedding endpoint returned empty response (${safeUrl(url)})`);\n  }\n\n  const embedding = items[0].embedding;\n  // Same dimension checks as httpEmbed — catch mismatches before they\n  // reach the Kuzu FLOAT[N] cast in search queries.\n  const expected = config.dimensions ?? DEFAULT_DIMS;\n  if (embedding.length !== expected) {\n    const hint = config.dimensions\n      ? 'Update GITNEXUS_EMBEDDING_DIMS to match your model output.'\n      : `Set GITNEXUS_EMBEDDING_DIMS=${embedding.length} to match your model output.`;\n    throw new HttpEmbeddingError(\n      `Embedding dimension mismatch: endpoint returned ${embedding.length}d vector, ` +\n        `but expected ${expected}d. ${hint}`,\n    );\n  }\n  return embedding;\n};\n","sourceCodeStart":645,"sourceCodeEnd":681,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/embeddings/http-client.ts#L645-L681","documentation":"An HttpEmbeddingError thrown in httpEmbedQuery as a defensive backstop when httpEmbedBatch returns an empty array for a single-text query. The inline comment marks it unreachable: an empty `data` array is now a cardinality mismatch (0 vectors for 1 text) rejected and retried inside httpEmbedBatch (error 125), so this branch is a guard against a future regression. If it fires, the in-loop cardinality check was bypassed.","triggerScenarios":"Only if httpEmbedBatch returns [] for a single-text batch without having thrown the in-loop count mismatch — something the current implementation cannot do. Would indicate a regression in httpEmbedBatch or a version skew.","commonSituations":"Should never occur in normal operation. If seen: a modified httpEmbedBatch that returns [] without validating, or a refactor that removed the in-loop check.","solutions":["Treat as an internal invariant violation: this branch is documented as unreachable.","Reinstall/align gitnexus versions to ensure httpEmbedBatch's in-loop cardinality check is present.","Report the occurrence with the safe URL from the message.","Retry after a clean rebuild; fall back to a known-good release if it recurs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { isHttpEmbeddingError } from 'gitnexus';\nconst isDefensiveEmpty = (e: unknown): boolean =>\n  isHttpEmbeddingError(e) &&\n  e instanceof Error &&\n  e.message.startsWith('Embedding endpoint returned empty response');","tryCatchPattern":"// Unreachable by design (httpEmbedBatch enforces cardinality in-loop).\ntry {\n  await httpEmbedQuery(text);\n} catch (e) {\n  if (isDefensiveEmpty(e)) {\n    // rule out a live endpoint fault (error 125/127) first; if healthy, report a bug\n  }\n  throw e;\n}","preventionTips":["Keep gitnexus builds coherent (reinstall together).","Treat any hit as an invariant violation and report it."],"tags":["invariant","defensive","embeddings","internal"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}