reranker()
Perform inference with a Reranker model, on a pair of inputs: a query string and a list of document strings. The model will rank the documents based on their relevance to the input query, returning the documents sorted from most to least relevant and a relevance score for each document.
If no model is loaded, the base Reranker model cross-encoder/mmarco-mMiniLMv2-L12-H384-v1 will be used by default. For more information on the base Reranker model, see the model's Hugging Face page.
Arguments
- query str
The input query string to rank the documents against. - documents str | list[str]
A string or list of strings to be ranked based on their relevance to the input query.
Response
A list[tuple], each tuple containing a document string and a float value
representing the model's confidence in its relevance to the input query. The list
is sorted in descending order of relevance, with the most relevant document first.
- Python
from artifex import Artifex
reranker = Artifex().reranker
ranked_documents = reranker(
query="Best programming language for data science",
documents=[
"Java is a versatile language typically used for building large-scale applications.",
"Python is widely used for data science due to its simplicity and extensive libraries.",
"JavaScript is primarily used for web development.",
]
)
print(ranked_documents)
- Response
[('Python is widely used for data science due to its simplicity and extensive libraries.', 3.83454), ('Java is a versatile language typically used for building large-scale applications.', -0.83086), ('JavaScript is primarily used for web development.', -1.37813)]