⚡ Bolt: O(n) hash map lookup for reranking scores#384
Conversation
…ted generator Pre-computes a dictionary mapping `idx` to `j + 1` from `mapped_scores` to avoid searching the entire list for every score. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuidePrecomputes a rank lookup map from result indices to their rank in the sorted scores to reduce batch_rank computation from O(n^2) to O(n) in default_reranking_output_transformer. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
🤖 Hi @bashandbone, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @bashandbone, but I was unable to process your request. Please see the logs for more details. |
💡 What: Pre-compute an$O(n)$ hash map ($O(n)$ search for every result inside the generator.$O(n^2)$ algorithmic complexity where $n$ is the number of results, causing unnecessary overhead for large result sets.$O(n^2)$ to $O(n)$ using $O(1)$ dictionary lookups, significantly improving performance when reranking a large number of chunks.
rank_map) of indices to ranks for mapped scores outside the loop, rather than using an🎯 Why: The previous code used
next((j + 1 for j, (idx, _) in enumerate(mapped_scores) if idx == i), -1)inside a generator comprehension iterating overresults. This resulted in an📊 Impact: Reduces the time complexity of the
batch_rankassignment from🔬 Measurement: Benchmark
default_reranking_output_transformerwith large collections of results/chunks to verify the reduction in processing time.PR created automatically by Jules for task 60115920967308526 started by @bashandbone
Summary by Sourcery
Enhancements: