Support SweRank code re-ranking#338
Open
aaryanshroff wants to merge 19 commits intocastorini:mainfrom
Open
Conversation
Add get_content() to Candidate dataclass to centralize the doc key
lookup logic (text/segment/contents/content/body/passage). Update
_convert_doc_to_prompt_content and _create_prompt_code to use it,
fixing a bug where the CODE path used doc.get("content") missing
the "contents" key.
Removes get_content() from Candidate and reverts _convert_doc_to_prompt_content
back to taking doc: Dict directly. Fixes the only real bug: the final else
branch now uses doc.get("passage", "") instead of doc["passage"] to avoid
KeyError on malformed docs.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
aaryanshroff
commented
Feb 19, 2026
| TEMPLATES = files("rank_llm.rerank.prompt_templates") | ||
|
|
||
|
|
||
| class RerankType(Enum): |
Contributor
Author
There was a problem hiding this comment.
SweRank uses a different prompt truncation/creation algorithm than RankLLM. This enum lets us choose which one to use based on the task.
aaryanshroff
commented
Feb 19, 2026
| @@ -0,0 +1,11 @@ | |||
| method: "singleturn_listwise" | |||
aaryanshroff
commented
Feb 19, 2026
| token_str = " > ".join([f"[{i+1}]" for i in range(current_window_size)]) | ||
|
|
||
| _output_token_estimate = len(self._tokenizer.encode(token_str)) - 1 | ||
| _output_token_estimate = len(self._tokenizer.encode(token_str)) + 2 |
Contributor
Author
There was a problem hiding this comment.
SweRank output was getting interrupted, leading to nonsense results
aaryanshroff
commented
Feb 19, 2026
| else: | ||
| return re.sub(r"\[(\d+)\]", r"(\1)", s) | ||
|
|
||
| def _create_prompt_code( |
Contributor
Author
There was a problem hiding this comment.
aaryanshroff
commented
Feb 19, 2026
| return messages, self.get_num_tokens(messages) | ||
| return prompt, self.get_num_tokens(prompt) | ||
|
|
||
| def _create_prompt_text( |
Contributor
Author
There was a problem hiding this comment.
Old / RankLLM-style truncation algorithm
Member
|
@claude review |
|
I'll analyze this and get back to you. |
Member
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
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.

Pull Request Checklist
Reference Issue
Please provide the reference to issue this PR is addressing (# followed by the issue number). If there is no associated issue, write "N/A".
ref:
Checklist Items
Before submitting your pull request, please review these items:
PR Type
What kind of change does this PR introduce?