Skip to content

Commit

Permalink
Adds BWC tests for efSearch
Browse files Browse the repository at this point in the history
Signed-off-by: Tejas Shah <[email protected]>
  • Loading branch information
shatejas committed May 21, 2024
1 parent 4423df4 commit e041a98
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/backwards_compatibility_tests_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
java: [ 11, 17 ]
os: [ubuntu-latest]
bwc_version : [ "2.0.1", "2.1.0", "2.2.1", "2.3.0", "2.4.1", "2.5.0", "2.6.0", "2.7.0", "2.8.0", "2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0-SNAPSHOT"]
bwc_version : [ "2.0.1", "2.1.0", "2.2.1", "2.3.0", "2.4.1", "2.5.0", "2.6.0", "2.7.0", "2.8.0", "2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "2.15.0-SNAPSHOT"]
opensearch_version : [ "3.0.0-SNAPSHOT" ]
exclude:
- os: windows-latest
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
java: [ 11, 17 ]
os: [ubuntu-latest]
bwc_version: [ "2.14.0-SNAPSHOT" ]
bwc_version: [ "2.15.0-SNAPSHOT" ]
opensearch_version: [ "3.0.0-SNAPSHOT" ]

name: k-NN Rolling-Upgrade BWC Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.bwc;

import static org.opensearch.knn.common.KNNConstants.FAISS_NAME;

public class QueryANNIT extends AbstractRestartUpgradeTestCase {

private static final String TEST_FIELD = "test-field";
private static final int DIMENSIONS = 5;
private static final int K = 5;
private static final Integer EF_SEARCH = 10;
private static final int NUM_DOCS = 10;
private static final String ALGORITHM = "hnsw";

public void testQueryANN() throws Exception {
if (isRunningAgainstOldCluster()) {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGORITHM, FAISS_NAME));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
} else {
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K, EF_SEARCH);
deleteKNNIndex(testIndex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.bwc;

import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER;
import static org.opensearch.knn.common.KNNConstants.FAISS_NAME;

public class QueryANNIT extends AbstractRollingUpgradeTestCase {
private static final String TEST_FIELD = "test-field";
private static final int DIMENSIONS = 5;
private static final int K = 5;
private static final Integer EF_SEARCH = 10;
private static final int NUM_DOCS = 10;
private static final String ALGORITHM = "hnsw";

public void testQueryANNIT() throws Exception {
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
switch (getClusterType()) {
case OLD:
createKnnIndex(
testIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGORITHM, FAISS_NAME)
);
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
break;
case MIXED:
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K, EF_SEARCH);
break;
case UPGRADED:
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K, EF_SEARCH);
deleteKNNIndex(testIndex);
}
}
}
14 changes: 12 additions & 2 deletions src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,22 @@ public void addKNNDocs(String testIndex, String testField, int dimension, int fi
}
}

// Validate KNN search on a KNN index by generating the query vector from the number of documents in the index
public void validateKNNSearch(String testIndex, String testField, int dimension, int numDocs, int k) throws Exception {
validateKNNSearch(testIndex, testField, dimension, numDocs, k, null);
}

// Validate KNN search on a KNN index by generating the query vector from the number of documents in the index
public void validateKNNSearch(String testIndex, String testField, int dimension, int numDocs, int k, Integer efSearch)
throws Exception {
float[] queryVector = new float[dimension];
Arrays.fill(queryVector, (float) numDocs);

Response searchResponse = searchKNNIndex(testIndex, new KNNQueryBuilder(testField, queryVector, k), k);
Response searchResponse = searchKNNIndex(
testIndex,
KNNQueryBuilder.builder().k(k).efSearch(efSearch).fieldName(testField).vector(queryVector).build(),
k
);

List<KNNResult> results = parseSearchResponse(EntityUtils.toString(searchResponse.getEntity()), testField);

assertEquals(k, results.size());
Expand Down

0 comments on commit e041a98

Please sign in to comment.