-
Notifications
You must be signed in to change notification settings - Fork 19.5k
feat: add rerank top-k configuration and integrate into retrieval pro… #30669
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
Summary of ChangesHello @SCMforever01, 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 enhances the document retrieval system by implementing a 'rerank top-k relaxation' mechanism. The primary goal is to improve the quality of results when a reranking model is used. Instead of directly retrieving the final Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 configurable top_k expansion for the reranking process, which is a valuable feature for improving retrieval quality. The implementation is well-structured, adding new configurations and correctly applying them to expand the number of candidates for reranking. I have a couple of suggestions to enhance code conciseness and maintainability. Overall, this is a good addition.
| enable_rerank = bool( | ||
| reranking_model | ||
| and reranking_model.get("reranking_provider_name") | ||
| and reranking_model.get("reranking_model_name") | ||
| ) |
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.
This check can be written more concisely and scalably using all() with a generator expression. This is especially useful if more keys need to be checked in the future.
| enable_rerank = bool( | |
| reranking_model | |
| and reranking_model.get("reranking_provider_name") | |
| and reranking_model.get("reranking_model_name") | |
| ) | |
| enable_rerank = bool(reranking_model and all( | |
| reranking_model.get(key) for key in [ | |
| "reranking_provider_name", "reranking_model_name" | |
| ] | |
| )) |
| support_expand = retrieval_method in { | ||
| RetrievalMethod.SEMANTIC_SEARCH, | ||
| RetrievalMethod.FULL_TEXT_SEARCH, | ||
| RetrievalMethod.HYBRID_SEARCH, | ||
| } |
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.
To improve consistency and reuse existing logic, you can use the static methods RetrievalMethod.is_support_semantic_search and RetrievalMethod.is_support_fulltext_search to define support_expand. This makes the code more maintainable as the logic for supported methods is centralized in the RetrievalMethod enum, and it's consistent with how these checks are performed elsewhere in this function.
| support_expand = retrieval_method in { | |
| RetrievalMethod.SEMANTIC_SEARCH, | |
| RetrievalMethod.FULL_TEXT_SEARCH, | |
| RetrievalMethod.HYBRID_SEARCH, | |
| } | |
| support_expand = ( | |
| RetrievalMethod.is_support_semantic_search(retrieval_method) | |
| or RetrievalMethod.is_support_fulltext_search(retrieval_method) | |
| ) | |
|
When a user sets top_k = 2, they naturally expect “the two most relevant chunks” to come back. But with rerank enabled, both the initial vector/full-text retrieval and the reranker are capped at 2 candidates. If the first-stage retrieval misses a semantically relevant chunk due to BM25/ts_rank quirks, it |
|
Please link an issue in the description :) |
|
@QuantumGhost @crazywoola @SCMforever01 can I look into the issue too or Contribute as well. |
|
Once @SCMforever01 create an issue, you can leave a message there, I will assign it to you as well. |
…cess
Important
Fixes #<issue number>.Summary
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods