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

  1. Ensure you pass at least one document to rerank.
  2. Check the embedded Voyage API response for an error or empty result.
  3. Upgrade/downgrade the Voyage SDK so the response shape includes relevanceScore.
  4. 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

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/3e2a4e49d1861de9. Report an issue: GitHub.