Skip to content

Commit

Permalink
Fix KNN SpaceType.getVectorSimilarityFunction renamed issue (#834) (#836
Browse files Browse the repository at this point in the history
)

* Fix KNN SpaceType.getVectorSimilarityFunction renamed issue.

Signed-off-by: Liyun Xiu <[email protected]>

* Fix NPE for a test

Signed-off-by: Liyun Xiu <[email protected]>

---------

Signed-off-by: Liyun Xiu <[email protected]>
(cherry picked from commit 08d82b1)

Co-authored-by: Liyun Xiu <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and chishui committed Jul 19, 2024
1 parent 0200245 commit a581311
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.VectorDataType;
import org.opensearch.knn.index.mapper.KNNVectorFieldMapper;
import org.opensearch.knn.index.query.KNNQueryBuilder;

Expand Down Expand Up @@ -119,6 +120,7 @@ public void testRewrite_whenRewriteQuery_thenSuccessful() {
when(mockKNNVectorField.getDimension()).thenReturn(4);
when(mockQueryShardContext.fieldMapper(eq(VECTOR_FIELD_NAME))).thenReturn(mockKNNVectorField);
when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
when(mockKNNVectorField.getVectorDataType()).thenReturn(VectorDataType.FLOAT);
KNNQueryBuilder knnQueryBuilder = new KNNQueryBuilder(VECTOR_FIELD_NAME, VECTOR_QUERY, K);
Query knnQuery = knnQueryBuilder.toQuery(mockQueryShardContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ protected float computeExpectedScore(
final String queryText
) {
float[] queryVector = runInference(modelId, queryText);
return spaceType.getVectorSimilarityFunction().compare(queryVector, indexVector);
return spaceType.getKnnVectorSimilarityFunction().compare(queryVector, indexVector);
}

protected Map<String, Object> getTaskQueryResponse(final String taskId) throws Exception {
Expand Down

0 comments on commit a581311

Please sign in to comment.