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
| Signature | Description |
|---|---|
ProximaScore create(OpsScorerInitParams params, CString indexName) | Creates a ProximaScore object. |
Methods
| Signature | Description |
|---|---|
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
| Parameter | Type | Description |
|---|---|---|
params | OpsScorerInitParams | Initialization parameters passed by the framework. See OpsScorerInitParams. |
indexName | CString | Name 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
| Parameter | Type | Description |
|---|---|---|
params | OpsScoreParams | Score-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
OpsScorerInitParams - initialization parameter reference
OpsScoreParams - score-calculation parameter reference