Camel.toolkits.jina reranker toolkit
JinaRerankerToolkit
A class representing a toolkit for reranking documents using Jina Reranker.
This class provides methods for reranking documents (text or images) based on their relevance to a given query using the Jina Reranker model.
init
Initializes a new instance of the JinaRerankerToolkit class.
Parameters:
- timeout (Optional[float]): The timeout value for API requests in seconds. If None, no timeout is applied. (default: :obj:
None
) - model_name (Optional[str]): The reranker model name. If None, will use the default model. (default: :obj:
None
) - device (Optional[str]): Device to load the model on. If None, will use CUDA if available, otherwise CPU. Only effective when use_api=False. (default: :obj:
None
) - use_api (bool): A flag to switch between local model and API. (default: :obj:
True
)
_sort_documents
Sort documents by their scores in descending order.
Parameters:
- documents (List[str]): List of documents to sort.
- scores (List[float]): Corresponding scores for each document.
Returns:
List[Dict[str, object]]: Sorted list of (document, score) pairs.
_call_jina_api
Makes a call to the JINA API for reranking.
Parameters:
- data (Dict[str]): The data to be passed into the api body.
Returns:
List[Dict[str, object]]: A list of dictionary containing the reranked documents and their relevance scores.
rerank_text_documents
Reranks text documents based on their relevance to a text query.
Parameters:
- query (str): The text query for reranking.
- documents (List[str]): List of text documents to be reranked.
- max_length (int): Maximum token length for processing. (default: :obj:
1024
)
Returns:
List[Dict[str, object]]: A list of dictionary containing the reranked documents and their relevance scores.
rerank_image_documents
Reranks image documents based on their relevance to a text query.
Parameters:
- query (str): The text query for reranking.
- documents (List[str]): List of image URLs or paths to be reranked.
- max_length (int): Maximum token length for processing. (default: :obj:
2048
)
Returns:
List[Dict[str, object]]: A list of dictionary containing the reranked image URLs/paths and their relevance scores.
image_query_text_documents
Reranks text documents based on their relevance to an image query.
Parameters:
- image_query (str): The image URL or path used as query.
- documents (List[str]): List of text documents to be reranked.
- max_length (int): Maximum token length for processing. (default: :obj:
2048
)
Returns:
List[Dict[str, object]]: A list of dictionary containing the reranked documents and their relevance scores.
image_query_image_documents
Reranks image documents based on their relevance to an image query.
Parameters:
- image_query (str): The image URL or path used as query.
- documents (List[str]): List of image URLs or paths to be reranked.
- max_length (int): Maximum token length for processing. (default: :obj:
2048
)
Returns:
List[Dict[str, object]]: A list of dictionary containing the reranked image URLs/paths and their relevance scores.
get_tools
Returns:
List[FunctionTool]: A list of FunctionTool objects representing the functions in the toolkit.