{"record":{"id":"298a8e30631e26c7","repo":"CherryHQ/cherry-studio","slug":"rerank-response-results-must-reference-a-valid-doc","errorCode":null,"errorMessage":"Rerank response results must reference a valid document index","messagePattern":"Rerank response results must reference a valid document index","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ai-sdk-provider/src/openai-compatible-reranking-model.ts","lineNumber":101,"sourceCode":"}\n\nfunction parseRerankResponse(body: unknown, documentCount: number): RerankRanking {\n  const results = (body as OpenAICompatibleRerankResponse).results\n  if (!Array.isArray(results)) {\n    throw new Error('Rerank response must contain a results array')\n  }\n\n  return results.map((result) => {\n    if (typeof result !== 'object' || result === null) {\n      throw new Error('Rerank response results must be objects')\n    }\n\n    if (typeof result.index !== 'number' || typeof result.relevance_score !== 'number') {\n      throw new Error('Rerank response results must contain numeric index and relevance_score')\n    }\n\n    if (!Number.isInteger(result.index) || result.index < 0 || result.index >= documentCount) {\n      throw new Error('Rerank response results must reference a valid document index')\n    }\n\n    return { index: result.index, relevanceScore: result.relevance_score }\n  })\n}\n\nexport function createOpenAICompatibleRerankingModel(\n  modelId: string,\n  settings: OpenAICompatibleRerankingModelSettings\n): RerankingModelV3 {\n  const baseURL = withoutTrailingSlash(settings.baseURL)\n  if (!baseURL) {\n    throw new Error('OpenAI-compatible reranking model requires baseURL')\n  }\n\n  return new OpenAICompatibleRerankingModel(modelId, {\n    provider: `${settings.name}.rerank`,\n    url: ({ path }) => {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/packages/ai-sdk-provider/src/openai-compatible-reranking-model.ts#L83-L119","documentation":"Re-thrown during Vertex AI model listing when options.throwOnError is set and at least one publisher group failed (returned null). `firstPublisherError` is captured as `unknown` from the per-publisher catch; if it is not an Error instance but is defined (e.g. a thrown string, a fetch rejection wrapping a non-Error), it is stringified and re-wrapped so the original value reaches the caller as a message. This branch only runs when the underlying thrown value was a non-Error.","triggerScenarios":"A per-publisher Vertex request (`publishers/{publisher}/models`) threw something that is not an Error instance — e.g. a raw string, a Response object, or a library that rejects with a plain object — and throwOnError propagated it. The real failure is upstream (auth, network, 403); this error is just the re-wrapping.","commonSituations":"Vertex service account JSON invalid or expired (GCE/gcloud auth); the configured region does not serve a publisher (e.g. Model Garden model unavailable in region); IAM permissions lacking `aiplatform.models.list`; a dependency rejecting with a non-Error value; transient 5xx from the Vertex endpoint.","solutions":["The stringified message is the underlying failure — read it: it usually names the auth or HTTP cause.","Verify the Vertex provider is configured with valid iam-gcp credentials (service account JSON + project + region).","Confirm the service account has the Vertex AI User / Model Garden access IAM role.","Retry once for transient 5xx; if one publisher consistently fails, note that non-throwOnError mode would skip it and list the rest.","Run the listing without throwOnError to see which publishers succeed and which fail individually in the warn logs."],"exampleFix":"// before: caller passes throwOnError and gets an opaque String(...) message\nawait listModels(provider, signal, { throwOnError: true })\n// after: list permissively, then inspect warn logs to find the failing publisher, fix its auth/region, then re-enable strict mode\nconst models = await listModels(provider, signal)  // throwOnError defaults off; failures degrade to 'no models from this publisher'\n// ... fix the failing publisher's config ...\nawait listModels(provider, signal, { throwOnError: true })","handlingStrategy":"validation","validationCode":"// Validate Vertex auth before requesting a strict (throwOnError) listing.\nconst auth = providerService.getAuthConfig(provider.id)\nif (auth?.type !== 'iam-gcp' || !auth.serviceAccountJson) {\n  throw new Error('Vertex provider must use iam-gcp auth with a service account JSON')\n}\nawait listModels(provider, signal, { throwOnError: true })","typeGuard":null,"tryCatchPattern":"try {\n  await listModels(provider, signal, { throwOnError: true })\n} catch (e) {\n  // the message stringifies the original (non-Error) cause; surface it, do not blanket-retry\n  logger.error('Vertex listing failed', { providerId: provider.id, cause: e instanceof Error ? e.message : String(e) })\n  // fall back to non-strict listing to still surface working publishers\n  await listModels(provider, signal)\n}","preventionTips":["Run the first Vertex listing without throwOnError to see which publishers fail and why in the warn logs.","Keep the service account JSON and IAM roles current; rotate and re-test after changes.","Prefer the Error-typed branch by ensuring upstream fetchers reject with Error instances so the cause is preserved."],"tags":["vertex-ai","model-listing","iam-gcp","auth"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}