CoREB-Reranker is a code reranker fine-tuned from
Qwen3-Reranker-4B via LoRA on a mixed reranker corpus. It is the
only reranker we evaluate that achieves consistent gains across all three code search tasks (text-to-code, code-to-text, and code-to-code).
CoREB-Reranker follows the same usage pattern as Qwen3-Reranker. The instruction is task-specific — use the appropriate one for your retrieval task:
1from enum import Enum
2from transformers import AutoModelForCausalLM, AutoTokenizer
3import torch
4
5class Task(Enum):
6 TEXT_TO_CODE = "Given a natural language programming task, retrieve code that correctly solves or implements the task."
7 CODE_TO_CODE = "Given a code snippet, retrieve code that is semantically equivalent or solves the same task."
8 CODE_TO_TEXT = "Given a code snippet, retrieve the natural language description or problem statement that best matches the code."
9
10model_id = "hq-bench/coreb-code-reranker"
11tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
12model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, trust_remote_code=True)
13model.eval()
14
15PREFIX = '<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be "yes" or "no".<|im_end|>\n<|im_start|>user\n'
16SUFFIX = "<|im_end|>\n<|im_start|>assistant\n"
17yes_id = tokenizer.convert_tokens_to_ids("yes")
18no_id = tokenizer.convert_tokens_to_ids("no")
19
20def score(query: str, document: str, task: Task) -> float:
21 prompt = f"{PREFIX}<Instruct>: {task.value}\n<Query>: {query}\n<Document>: {document}{SUFFIX}"
22 inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=4096)
23 with torch.no_grad():
24 logits = model(**inputs).logits[0, -1, :]
25 return (logits[yes_id] - logits[no_id]).item()
26
27# Text-to-Code: natural language query -> code
28print(score(
29 query="binary search implementation",
30 document="def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n ...",
31 task=Task.TEXT_TO_CODE,
32))
33
34# Code-to-Code: code -> semantically equivalent code
35print(score(
36 query="def binary_search(arr, target): ...",
37 document="int binarySearch(int[] arr, int target) { ... }",
38 task=Task.CODE_TO_CODE,
39))
40
41# Code-to-Text: code -> problem description
42print(score(
43 query="def binary_search(arr, target): ...",
44 document="Find the index of a target value in a sorted array using binary search.",
45 task=Task.CODE_TO_TEXT,
46))
For batch reranking with the CoREB evaluation pipeline, see the
CoREB repository.
1@article{xue2026coreb,
2 title={Beyond Retrieval: A Multitask Benchmark and Reranker for Code Search},
3 author={Xue, Siqiao and Liao, Zihan and Qin, Jin and Zhang, Ziyin and Mu, Yixiang and Zhou, Fan and Yu, Hang},
4 journal={arXiv preprint arXiv:2605.04615},
5 year={2026},
6 url={https://arxiv.org/abs/2605.04615}
7}