All Products
Search
Document Center

OpenSearch:ProximaScore

Last Updated:Apr 01, 2026

ProximaScore calculates the proximity of documents to a vector index inside a custom Cava scorer. Use it when you need vector similarity as part of your ranking logic.

Constructor

SignatureDescription
ProximaScore create(OpsScorerInitParams params, CString indexName)Creates a ProximaScore object.

Methods

SignatureDescription
double evaluate(OpsScoreParams params)Calculates the proximity of the current document to the vector index.

Constructor details

ProximaScore create(OpsScorerInitParams params, CString indexName)

A factory function that creates a ProximaScore instance bound to a specific vector index.

Parameters

ParameterTypeDescription
paramsOpsScorerInitParamsInitialization parameters passed by the framework. See OpsScorerInitParams.
indexNameCStringName of the vector index to score against. The index must participate in the current search query.

Method details

double evaluate(OpsScoreParams params)

Calculates the proximity of the current document to the vector index specified at construction time.

Parameters

ParameterTypeDescription
paramsOpsScoreParamsScore-calculation parameters passed by the framework. See OpsScoreParams.

Return value

A double representing the proximity of the document to the specified vector index.

Example

The following example defines a custom scorer that uses ProximaScore to rank documents by their vector similarity.

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;
    }
};

What's next