{"record":{"id":"3e2a4e49d1861de9","repo":"mastra-ai/mastra","slug":"no-relevance-score-found-in-voyageai-response","errorCode":null,"errorMessage":"No relevance score found in VoyageAI response","messagePattern":"No relevance score found in VoyageAI response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embedders/voyageai/src/reranker.ts","lineNumber":81,"sourceCode":"   * Get relevance score between a query and a document.\n   *\n   * @param query - The search query (text1)\n   * @param document - The document to score (text2)\n   * @returns Relevance score between 0 and 1\n   */\n  async getRelevanceScore(query: string, document: string): Promise<number> {\n    const response = await this.client.rerank({\n      query,\n      documents: [document],\n      model: this.modelId,\n      topK: 1,\n      truncation: this.config.truncation ?? true,\n    });\n\n    // Extract relevance score from response\n    const result = response.data?.[0];\n    if (!result || result.relevanceScore === undefined) {\n      throw new Error('No relevance score found in VoyageAI response');\n    }\n\n    return result.relevanceScore;\n  }\n\n  /**\n   * Rerank multiple documents against a query.\n   *\n   * This is more efficient than calling getRelevanceScore multiple times\n   * as it makes a single API call for all documents.\n   *\n   * @param query - The search query\n   * @param documents - Array of documents to rerank\n   * @param topK - Optional number of top results to return\n   * @returns Array of reranked results with scores\n   */\n  async rerankDocuments(\n    query: string,","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/embedders/voyageai/src/reranker.ts#L63-L99","documentation":"After calling the Voyage rerank API, the reranker extracts response.data?.[0].relevanceScore. If the response has no data items or the first item lacks a relevanceScore, it throws because a reranker without scores is unusable — usually indicating an unexpected or empty API response.","triggerScenarios":"Voyage returns data: [] (e.g. empty documents array sent), or the SDK response shape changed so relevanceScore is absent/renamed on the result object.","commonSituations":"Reranking an empty document list; API/SDK version drift between @voyageai/client and this embedder package; partial or malformed API responses.","solutions":["Ensure you pass at least one document to rerank.","Check the embedded Voyage API response for an error or empty result.","Upgrade/downgrade the Voyage SDK so the response shape includes relevanceScore.","Add a guard on response.data?.length before interpreting results."],"exampleFix":"// before\nconst scores = docs.map(() => reranker.score(query, docs)); // docs = []\n// after\nif (docs.length === 0) throw new Error('rerank requires at least one document');\nconst scores = docs.map(() => reranker.score(query, docs));","handlingStrategy":"try-catch","validationCode":"if (!documents || documents.length === 0) {\n  throw new Error('Voyage rerank requires at least one document');\n}\nconst score = await reranker.score(query, documents);","typeGuard":"function hasRelevanceScore(r: unknown): r is { relevanceScore: number } {\n  return typeof r === 'object' && r !== null && 'relevanceScore' in r && typeof (r as any).relevanceScore === 'number';\n}","tryCatchPattern":"try {\n  const score = await reranker.score(query, doc);\n} catch (err) {\n  if ((err as Error).message.includes('No relevance score found')) {\n    console.error('Voyage returned no scored result — check documents input and SDK/API versions');\n  }\n  throw err;\n}","preventionTips":["Never rerank an empty documents list.","Keep the Voyage SDK and this package versions aligned.","Log the raw response when the score is missing to spot API changes.","Guard response.data?.[0] yourself when calling lower-level APIs."],"tags":["voyageai","reranker","api-response","version-mismatch"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}