Documentation Index
Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
Use this file to discover all available pages before exploring further.
class JinaRerankerToolkit(BaseToolkit):
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
def __init__(
self,
timeout: Optional[float] = None,
model_name: str = 'jinaai/jina-reranker-m0',
device: Optional[str] = None,
use_api: bool = True
):
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 (str): The reranker model name. (default: :obj:
"jinaai/jina-reranker-m0")
- 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
def _sort_documents(self, documents: List[str], scores: List[float]):
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
def _call_jina_api(self, data: Dict[str, Any]):
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
def rerank_text_documents(
self,
query: str,
documents: List[str],
max_length: int = 1024
):
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
def rerank_image_documents(
self,
query: str,
documents: List[str],
max_length: int = 2048
):
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
def image_query_text_documents(
self,
image_query: str,
documents: List[str],
max_length: int = 2048
):
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
def image_query_image_documents(
self,
image_query: str,
documents: List[str],
max_length: int = 2048
):
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.
Returns:
List[FunctionTool]: A list of FunctionTool objects
representing the functions in the toolkit.