ProximaScore

更新时间:
复制 MD 格式

ProximaScore calculates the vector similarity score for a named vector index within a custom scorer. Use it inside a Cava scorer class to retrieve the similarity score from a vector index and combine it with other signals — such as text relevance or business rules — into a final ranking score.

Constructor

SignatureDescription
ProximaScore create(OpsScorerInitParams params, CString indexName)Creates a ProximaScore object for the specified vector index.

Functions

SignatureDescription
double evaluate(OpsScoreParams params)Returns the similarity score of the vector index for the current document.

Function details

ProximaScore create(OpsScorerInitParams params, CString indexName)

A factory function that creates a ProximaScore object bound to a specific vector index. Call this method in the init() method of your scorer class, not in score(). The init() method runs once per query; calling create() in score() would re-initialize the object on every document.

Parameters

ParameterTypeDescription
paramsOpsScorerInitParamsInitialization parameters. See OpsScoreParams.
indexNameCStringThe name of the vector index to score against. Must match a vector index name defined in the query.

double evaluate(OpsScoreParams params)

Returns the similarity score of the current document against the vector index bound at initialization. Call this method inside the score() method of your scorer class.

Parameter

ParameterTypeDescription
paramsOpsScoreParamsScore calculation parameters. See OpsScoreParams.

Return value

The similarity score of the specified vector index.

Example

The following example creates a basic scorer that returns the raw vector similarity score. All scoring logic runs inside the init() and score() lifecycle methods.

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.similarity.ProximaScore;

class BasicSimilarityScorer {
    ProximaScore _f1;
    boolean init(OpsScorerInitParams params) {
        _f1 = ProximaScore.create(params, "vector_index");
        return true;
    }

    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        float s1 = _f1.evaluate(params);
        return s1;
    }
};
  • Create the ProximaScore object in init(), not in score(). The init() method runs once per query; score() runs once per document.

  • Pass the index name as a name specified in the query.