Rerank¶
- class ibm_watsonx_ai.foundation_models.rerank.Rerank(model_id, params=None, credentials=None, project_id=None, space_id=None, verify=None, api_client=None)[source]¶
Bases:
WMLResource
Rerank texts based on some queries.
- Parameters:
model_id (str) – type of model to use
params (dict, RerankParameters, optional) – parameters to use during request generation
credentials (Credentials or dict, optional) – credentials for the Watson Machine Learning instance
project_id (str, optional) – ID of the Watson Studio project
space_id (str, optional) – ID of the Watson Studio space
verify (bool or str, optional) –
You can pass one of the following as verify:
the path to a CA_BUNDLE file
the path of directory with certificates of trusted CAs
True - default path to truststore will be taken
False - no verification will be made
api_client (APIClient, optional) – initialized APIClient object with a set project ID or space ID. If passed,
credentials
andproject_id
/space_id
are not required.
Example:
from ibm_watsonx_ai import Credentials from ibm_watsonx_ai.foundation_models import Rerank generate_params = { "truncate_input_tokens": 10 } wx_ranker = Rerank( model_id="<RERANK MODEL>", params=generate_params, credentials=Credentials( api_key = "***", url = "https://us-south.ml.cloud.ibm.com"), project_id=project_id )
- generate(query, inputs, params=None)[source]¶
Calling this method generates the following auditing event.
- Parameters:
query (str) – The rank query.
inputs (list[str], list[dict['text', str]]) – The rank input strings.
params (dict, RerankParameters, optional)
Example:
query = "As a Youth, I craved excitement while in adulthood I followed Enthusiastic Pursuit." inputs = [ "In my younger years, I often reveled in the excitement of spontaneous adventures and embraced the thrill of the unknown, whereas in my grownup life, I have come to appreciate the comforting stability of a well-established routine.", "As a young man, I frequently sought out exhilarating experiences, craving the adrenaline rush of lifes novelties, while as a responsible adult, I have come to understand the profound value of accumulated wisdom and life experience." ] response = wx_ranker.generate(query=query, inputs=inputs) # Print all response print(response)