{"record":{"id":"871cf429eae76bd9","repo":"mastra-ai/mastra","slug":"no-relevance-score-found-on-cohere-response","errorCode":null,"errorMessage":"No relevance score found on Cohere response","messagePattern":"No relevance score found on Cohere response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/rerank/relevance/cohere/index.ts","lineNumber":55,"sourceCode":"        Authorization: `Bearer ${this.apiKey}`,\n      },\n      body: JSON.stringify({\n        query,\n        documents: [text],\n        model: this.model,\n        top_n: 1,\n      }),\n    });\n\n    if (!response.ok) {\n      throw new Error(`Cohere API error: ${response.status} ${await response.text()}`);\n    }\n\n    const data = (await response.json()) as CohereRerankingResponse;\n    const relevanceScore = data.results[0]?.relevance_score;\n\n    if (typeof relevanceScore !== 'number' || !Number.isFinite(relevanceScore)) {\n      throw new Error('No relevance score found on Cohere response');\n    }\n\n    return relevanceScore;\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":61,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/rerank/relevance/cohere/index.ts#L37-L61","documentation":"The Cohere API returned 200 but the parsed response contained no finite numeric relevance_score at results[0]. This is a defensive check against malformed or empty rerank responses (e.g. empty results array, unexpected schema from a changed API version).","triggerScenarios":"Cohere returns results: [] (e.g. documents array empty or all filtered out by top_n), or the response schema no longer matches CohereRerankingResponse.","commonSituations":"Passing empty/whitespace text documents; using a deprecated rerank model whose response shape changed; proxy/gateway returning a success with an unexpected body.","solutions":["Ensure the query and document text passed to getRelevanceScore are non-empty","Pin/upgrade to a supported rerank model (e.g. rerank-v3.5) and matching @mastra/rag version","Log the raw response to inspect why results[0].relevance_score is missing"],"exampleFix":"// before\nconst score = await reranker.getRelevanceScore(query, ''); // empty doc -> likely no result\n// after\nif (!text.trim()) return 0;\nconst score = await reranker.getRelevanceScore(query, text);","handlingStrategy":"fallback","validationCode":"if (!queryText.trim() || !documents.every(d => d.text?.trim())) throw new Error('Empty rerank input');","typeGuard":null,"tryCatchPattern":"try { score = await reranker.getRelevanceScore(q, t); } catch (e) { if (e.message.includes('No relevance score')) score = 0; else throw e; }","preventionTips":["Filter out empty/whitespace documents before reranking","Pin the @mastra/rag version to a Cohere API version you've tested","Log raw responses when scores go missing to detect schema drift early"],"tags":["api-error","cohere","rerank","response-parsing"],"backgroundTag":"unexpected-api-response","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}