mastra-ai/mastra · error
No relevance score found in VoyageAI response
Error message
No relevance score found in VoyageAI response
What it means
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.
Source
Thrown at embedders/voyageai/src/reranker.ts:81
* Get relevance score between a query and a document.
*
* @param query - The search query (text1)
* @param document - The document to score (text2)
* @returns Relevance score between 0 and 1
*/
async getRelevanceScore(query: string, document: string): Promise<number> {
const response = await this.client.rerank({
query,
documents: [document],
model: this.modelId,
topK: 1,
truncation: this.config.truncation ?? true,
});
// Extract relevance score from response
const result = response.data?.[0];
if (!result || result.relevanceScore === undefined) {
throw new Error('No relevance score found in VoyageAI response');
}
return result.relevanceScore;
}
/**
* Rerank multiple documents against a query.
*
* This is more efficient than calling getRelevanceScore multiple times
* as it makes a single API call for all documents.
*
* @param query - The search query
* @param documents - Array of documents to rerank
* @param topK - Optional number of top results to return
* @returns Array of reranked results with scores
*/
async rerankDocuments(
query: string,View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const scores = docs.map(() => reranker.score(query, docs)); // docs = []
// after
if (docs.length === 0) throw new Error('rerank requires at least one document');
const scores = docs.map(() => reranker.score(query, docs)); Defensive patterns
Strategy: try-catch
Validate before calling
if (!documents || documents.length === 0) {
throw new Error('Voyage rerank requires at least one document');
}
const score = await reranker.score(query, documents); Type guard
function hasRelevanceScore(r: unknown): r is { relevanceScore: number } {
return typeof r === 'object' && r !== null && 'relevanceScore' in r && typeof (r as any).relevanceScore === 'number';
} Try / catch
try {
const score = await reranker.score(query, doc);
} catch (err) {
if ((err as Error).message.includes('No relevance score found')) {
console.error('Voyage returned no scored result — check documents input and SDK/API versions');
}
throw err;
} Prevention
- 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.
When it happens
Trigger: Voyage returns data: [] (e.g. empty documents array sent), or the SDK response shape changed so relevanceScore is absent/renamed on the result object.
Common situations: Reranking an empty document list; API/SDK version drift between @voyageai/client and this embedder package; partial or malformed API responses.
Related errors
- VoyageAI API key is required. Set VOYAGE_API_KEY environment
- Unknown content type: ${(content as any).type}
- VoyageAI API key is required. Set VOYAGE_API_KEY environment
- VoyageAI API key is required. Set VOYAGE_API_KEY environment
- VoyageAI API key is required. Set VOYAGE_API_KEY environment
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/3e2a4e49d1861de9.
Report an issue: GitHub.