add-qwen-reranker-support-87a3354f3a3a292b.yaml
1 --- 2 enhancements: 3 - | 4 The parameters ``query_suffix`` and ``document_suffix`` have been added to ``SentenceTransformersSimilarityRanker`` to support the Qwen3 reranker model family. 5 6 Here is an example of how to use these new parameters to use the Qwen3-Reranker-0.6B: 7 8 .. code:: python 9 10 from haystack import Document 11 from haystack.components.rankers.sentence_transformers_similarity import SentenceTransformersSimilarityRanker 12 13 ranker = SentenceTransformersSimilarityRanker( 14 model="tomaarsen/Qwen3-Reranker-0.6B-seq-cls", 15 query_prefix='<|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<Instruct>: Given a web search query, retrieve relevant passages that answer the query\n<Query>: ', 16 query_suffix="\n", 17 document_prefix="<Document>: ", 18 document_suffix="<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n", 19 ) 20 21 result = ranker.run( 22 query="Which planet is known as the Red Planet?", 23 documents=[ 24 Document(content="Venus is often called Earth's twin because of its similar size and proximity."), 25 Document(content="Mars, known for its reddish appearance, is often referred to as the Red Planet."), 26 Document(content="Jupiter, the largest planet in our solar system, has a prominent red spot."), 27 Document(content="Saturn, famous for its rings, is sometimes mistaken for the Red Planet."), 28 ], 29 ) 30 31 print(result) 32 33 NOTE: This only works with the Qwen3 reranker models that use the sequence classification architecture. 34 For example, you can find some on ``tomaarsen``'s Hugging Face profile.