Conversation
tandede
marked this pull request as ready for review
August 19, 2026 11:05
tandede
force-pushed
the
codex/fix-bge-reranker-top-k
branch
from
August 21, 2026 11:21
1bfb746 to
cc2e669
Compare
Author
|
Hi maintainers, just following up on this PR in case it was missed. It is ready for review, and I’d be happy to address any feedback or make further adjustments. Thank you! |
This branch has not been deployed
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.
Summary
kcontract after sorting BGE reranker scoresbatch_sizeandmax_lengthWhy
BgeReranker.rerank()acceptedk(default: 5) but returned the complete ranked list. This affects the README's RAG flow directly: it retrieves 10 candidates and calls the reranker with its default limit, so all 10 documents previously continued into generation instead of the best five.The inference path also tokenized every candidate in one call and unconditionally converted the model to FP16. Large retrieval sets could therefore cause avoidable memory spikes, while CPU execution used a precision mode that is not broadly supported. This is especially relevant because the README documents a local Python installation rather than a CUDA-only deployment.
This change makes resource use bounded and explicit:
zip()truncationWhen
is_sorted=False, the existing score-only behavior is preserved: every document is returned in input order.Compatibility
The original positional arguments (
model_name_or_path,api_key, andurl) keep their order. New options are appended with conservative defaults (batch_size=32,max_length=512, automatic device selection).Validation
pip check— no broken requirementspython -m pytest -q tests/units/test_reranker.py— 18 passedflake8 tests/units/test_reranker.py— passedcross-encoder/ms-marco-TinyBERT-L2-v2— correct top-1 result withbatch_size=1RewriterAppbecauseHyDE_rewriteris undefinedThe tests cover exact top-k ordering, score-only behavior, empty input, batch boundaries, token length forwarding, configuration validation, CUDA/MPS/CPU precision behavior, MPS auto-selection, and model-output shape mismatches without downloading a model during CI.