Add batch query encoding to AutoQueryEncoder - #2625
Open
yashs33244 wants to merge 1 commit into
Open
Conversation
AutoQueryEncoder encoded one query at a time, so FaissSearcher.batch_search looped and encoded queries individually. Add an encode_batch method (the hook batch_search already checks for) that encodes a list of queries in a single forward pass. Mean pooling masks padding so each row matches the per-query result; cls pooling is padding-invariant. Adds a test covering both.
yashs33244
marked this pull request as ready for review
July 31, 2026 08:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2270.
AutoQueryEncoder.encodeonly took a single query, soFaissSearcher.batch_searchencoded queries one at a time in a Python loop even though it already checks for anencode_batchmethod. This adds that method toAutoQueryEncoder, so a whole query set is encoded in one forward pass.Mean pooling masks padding tokens so each row matches the per-query result; cls pooling is padding-invariant. Added a test asserting
encode_batch(queries)[i]equalsencode(queries[i])for both poolings, with variable-length queries so padding is exercised.Opening as a draft. One scope question for maintainers: should this also extend to the other query encoders (TCT, DPR, etc.), or is
AutoQueryEncoderthe right first step?