Skip to content

Add batch query encoding to AutoQueryEncoder - #2625

Open
yashs33244 wants to merge 1 commit into
castorini:masterfrom
yashs33244:feat/batch-query-encoding
Open

Add batch query encoding to AutoQueryEncoder#2625
yashs33244 wants to merge 1 commit into
castorini:masterfrom
yashs33244:feat/batch-query-encoding

Conversation

@yashs33244

Copy link
Copy Markdown
Contributor

Closes #2270.

AutoQueryEncoder.encode only took a single query, so FaissSearcher.batch_search encoded queries one at a time in a Python loop even though it already checks for an encode_batch method. This adds that method to AutoQueryEncoder, 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] equals encode(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 AutoQueryEncoder the right first step?

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
yashs33244 marked this pull request as ready for review July 31, 2026 08:52
Copilot AI review requested due to automatic review settings July 31, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

[Feature Request] Batch Encoding of Queries

2 participants