Use the text_relevance_llm function to rank search results using a ranking model.
Prerequisites
The Industry Algorithm Edition must be connected to AI Search Open Platform.
AI Search Open Platform provides the ranking model. To use this model in the Industry Algorithm Edition, you must first access the model.
Log on to AI Search Open Platform and go to the model list page. In the access information area, click one-click access to enable the intelligent dialogue service based on Retrieval-Augmented Generation (RAG). The available models are displayed at the bottom of the page. These include large language models (LLMs) such as ops-qwen-turbo (fine-tuned on qwen-turbo to enhance RAG capabilities), qwen-turbo, qwen-plus, and qwen-max.
Function reference
Create TextRelevanceLLM
-
Syntax: TextRelevanceLLM create(OpsScorerInitParams params, CString serviceId, CString fields)
-
Parameters:
-
params: The scoring initialization parameters. For more information, see OpsScorerInitParams.
-
serviceId: The ID of the reranking service or model.
-
fields: The attribute fields. Separate multiple fields with a hash symbol (
#).
-
Calculate score
-
Syntax: double evaluate(OpsScoreParams params)
-
params: The input parameters for scoring. For more information, see OpsScoreParams.
-
Return value: The text relevance score, returned as a floating-point number in the range [0, 1].
Sample code
package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsDoc;
import com.aliyun.opensearch.cava.features.algo.TextRelevanceLLM;
class IntelligenceAlgorithmScorer {
TextRelevanceLLM _textRelevanceLLM;
boolean init(OpsScorerInitParams params) {
_textRelevanceLLM = TextRelevanceLLM.create(params, "ops-text-reranker-001", "detail_attr");
return true;
}
double score(OpsScoreParams params) {
OpsDoc doc = params.getDoc();
double score = _textRelevanceLLM.evaluate(params);
doc.trace("TextRelevanceLLM Score: ", score);
return score;
}
};