Skip to content

fix(retrievers): handle Voyage AI rerank API response format change#6493

Open
corporatepoetry wants to merge 1 commit into
FlowiseAI:mainfrom
corporatepoetry:bugfix/voyage-rerank-api-schema
Open

fix(retrievers): handle Voyage AI rerank API response format change#6493
corporatepoetry wants to merge 1 commit into
FlowiseAI:mainfrom
corporatepoetry:bugfix/voyage-rerank-api-schema

Conversation

@corporatepoetry

Copy link
Copy Markdown

The Voyage AI rerank API may return results under data.data instead of data.results. Fall back to data.results for backward compatibility.

Fixes #6492

The Voyage AI rerank API may return results under `data.data` instead
of `data.results`. Fall back to `data.results` for backward compatibility.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Voyage AI reranking logic to support API responses that return results under either the 'data' or 'results' field. Feedback suggests adding optional chaining and verifying that the extracted results are an array, throwing an error if the format is invalid to ensure fail-fast behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +41 to +43
const results = returnedDocs.data.data ?? returnedDocs.data.results
const finalResults: Document<Record<string, any>>[] = []
returnedDocs.data.results.forEach((result: any) => {
results.forEach((result: any) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the API response structure is unexpected or empty, returnedDocs.data might be nullish, or results might not be an array. When handling potentially invalid data from external sources (like an API response), we should prefer throwing an error for invalid input types rather than silently returning a default or empty value to promote fail-fast behavior.

Suggested change
const results = returnedDocs.data.data ?? returnedDocs.data.results
const finalResults: Document<Record<string, any>>[] = []
returnedDocs.data.results.forEach((result: any) => {
results.forEach((result: any) => {
const results = returnedDocs.data?.data ?? returnedDocs.data?.results
if (!Array.isArray(results)) {
throw new Error("Invalid response format from Voyage AI API: results is not an array")
}
const finalResults: Document<Record<string, any>>[] = []
results.forEach((result: any) => {
References
  1. When handling potentially invalid data from external sources (like an API response), prefer throwing an error for invalid input types rather than silently returning a default or empty value. This promotes fail-fast behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Voyage AI Rerank Retriever can't process API responses

1 participant