-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
feat: add Rerankers from Azure #5576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add Azure Foundry Reranker integration
feat: Add Azure Foundry Reranker integration
…3-icon-service-AI-Studio.svg
Summary of ChangesHello @Psylockz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates Azure AI Foundry's reranking functionality into Flowise by adding a new AzureRerankRetriever node. This allows users to enhance the relevance of retrieved documents by applying advanced semantic reranking, ensuring that the most pertinent information is prioritized and returned with a clear relevance score. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
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 introduces a new Azure Rerank Retriever node. The implementation is largely correct, but I've identified several areas for improvement to enhance robustness, code consistency, and type safety. My feedback for AzureRerank.ts focuses on improving property naming, strengthening type-safety, and replacing silent error handling with explicit error throwing to prevent unexpected behavior. For AzureRerankRetriever.ts, I've suggested adding credential validation to avoid potential runtime errors and correcting an inconsistent variable name to align with the project's coding style.
packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts
Show resolved
Hide resolved
packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts
Show resolved
Hide resolved
packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerank.ts
Outdated
Show resolved
Hide resolved
packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts
Outdated
Show resolved
Hide resolved
|
@HenryHengZJ I would really appreciate a review :) |
|
/gemini review |
There was a problem hiding this comment.
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 introduces a new AzureRerankRetriever node, which is a great addition. The implementation is solid and follows the existing patterns in the codebase. I've provided a few suggestions to improve code conciseness, enhance error handling for better debugging, and ensure consistency in naming conventions. Overall, this is a well-executed feature.
| } catch (error) { | ||
| throw new Error(`Azure Rerank API call failed: ${error.message}`) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling for the API call can be improved to provide more context upon failure. When an axios error occurs, the response body often contains valuable information. Including this in the thrown error message will make debugging significantly easier.
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
throw new Error(`Azure Rerank API call failed with status ${error.response.status}: ${JSON.stringify(error.response.data)}`);
}
throw new Error(`Azure Rerank API call failed: ${error.message}`);
}| const finalResults: Document<Record<string, any>>[] = [] | ||
| returnedDocs.data.results.forEach((result: any) => { | ||
| const doc = documents[result.index] | ||
| doc.metadata.relevance_score = result.relevance_score | ||
| finalResults.push(doc) | ||
| }) | ||
| return finalResults.splice(0, this.k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for processing reranked documents can be simplified. Using map is more concise and idiomatic in TypeScript than using forEach with an external array. Additionally, since the API is called with top_n: this.k, the response should already contain the top k documents, making the call to splice() redundant.
return returnedDocs.data.results.map((result: { index: number; relevance_score: number }) => {
const doc = documents[result.index];
doc.metadata.relevance_score = result.relevance_score;
return doc;
});
packages/components/nodes/retrievers/AzureRerankRetriever/AzureRerankRetriever.ts
Show resolved
Hide resolved
| let finaltext = '' | ||
|
|
||
| const docs = await retriever.getRelevantDocuments(query ? query : input) | ||
|
|
||
| for (const doc of docs) finaltext += `${doc.pageContent}\n` | ||
|
|
||
| return handleEscapeCharacters(finaltext, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop for concatenating document content can be written more concisely using map and join. This improves readability and is a more functional approach.
const docs = await retriever.getRelevantDocuments(query ? query : input);
const finaltext = docs.map((doc) => doc.pageContent).join('\n');
return handleEscapeCharacters(finaltext, false);
This change adds an Azure Rerank Retriever node to Flowise, allowing reranking via the Azure Foundry endpoint.
Features
AzureRerankRetrievernode under Retrieversrelevance_scorein metadataImplementation details
packages/components/nodes/retrievers/AzureRerankRetriever/Usage
Users can now add the Azure Rerank Retriever node to their flows and rerank documents through secure Azure Foundry infrastructure.
Closes #5555
Screenshots:


