Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Few changes in integration test #1404

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,16 @@ public void testFiltering_whenNonNestedKNNAndNestedFilterAndNonNestedFieldWithNe
private void validateFilterSearch(final String query, final String engine) throws IOException {
String response = EntityUtils.toString(performSearch(INDEX_NAME, query).getEntity());
// Validate number of documents returned as the expected number of documents
Assert.assertEquals("For engine " + engine + " : ", DOCUMENT_IN_RESPONSE, parseHits(response));
Assert.assertEquals("For engine " + engine + ", hits: ", DOCUMENT_IN_RESPONSE, parseHits(response));
Assert.assertEquals("For engine " + engine + ", totalSearchHits: ", k, parseTotalSearchHits(response));
if (KNNEngine.getEngine(engine) == KNNEngine.FAISS) {
// Update the filter threshold to 0 to ensure that we are hitting ANN Search use case for FAISS
updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD, 0));
response = EntityUtils.toString(performSearch(INDEX_NAME, query).getEntity());

// Validate number of documents returned as the expected number of documents
Assert.assertEquals("For engine " + engine + " with ANN search :", DOCUMENT_IN_RESPONSE, parseHits(response));
Assert.assertEquals("For engine " + engine + ", hits with ANN search :", DOCUMENT_IN_RESPONSE, parseHits(response));
Assert.assertEquals("For engine " + engine + ", totalSearchHits with ANN search :", k, parseTotalSearchHits(response));
}
}

Expand Down
35 changes: 17 additions & 18 deletions src/test/java/org/opensearch/knn/index/NestedSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,16 @@ public final void cleanUp() {
public void testNestedSearchWithLucene_whenKIsTwo_thenReturnTwoResults() {
createKnnIndex(2, KNNEngine.LUCENE.getName());

String doc1 = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { 1f, 1f }, new Float[] { 1f, 1f })
.build();
addKnnDoc(INDEX_NAME, "1", doc1);

String doc2 = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { 2f, 2f }, new Float[] { 2f, 2f })
.build();
addKnnDoc(INDEX_NAME, "2", doc2);
int totalDocCount = 15;
for (int i = 0; i < totalDocCount; i++) {
String doc = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { (float) i, (float) i }, new Float[] { (float) i, (float) i })
.build();
addKnnDoc(INDEX_NAME, String.valueOf(i), doc);
}

refreshIndex(INDEX_NAME);
forceMergeKnnIndex(INDEX_NAME);

Float[] queryVector = { 1f, 1f };
Response response = queryNestedField(INDEX_NAME, 2, queryVector);
Expand All @@ -86,17 +85,16 @@ public void testNestedSearchWithLucene_whenKIsTwo_thenReturnTwoResults() {
public void testNestedSearchWithFaiss_whenKIsTwo_thenReturnTwoResults() {
createKnnIndex(2, KNNEngine.FAISS.getName());

String doc1 = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { 1f, 1f }, new Float[] { 1f, 1f })
.build();
addKnnDoc(INDEX_NAME, "1", doc1);

String doc2 = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { 2f, 2f }, new Float[] { 2f, 2f })
.build();
addKnnDoc(INDEX_NAME, "2", doc2);
int totalDocCount = 15;
for (int i = 0; i < totalDocCount; i++) {
String doc = NestedKnnDocBuilder.create(FIELD_NAME_NESTED)
.addVectors(FIELD_NAME_VECTOR, new Float[] { (float) i, (float) i }, new Float[] { (float) i, (float) i })
.build();
addKnnDoc(INDEX_NAME, String.valueOf(i), doc);
}

refreshIndex(INDEX_NAME);
forceMergeKnnIndex(INDEX_NAME);

Float[] queryVector = { 1f, 1f };
Response response = queryNestedField(INDEX_NAME, 2, queryVector);
Expand Down Expand Up @@ -148,6 +146,7 @@ public void testNestedSearchWithFaiss_whenDoingExactSearch_thenReturnCorrectResu
addKnnDoc(INDEX_NAME, String.valueOf(i), doc);
}
refreshIndex(INDEX_NAME);
forceMergeKnnIndex(INDEX_NAME);

// Make it as an exact search by setting the threshold larger than size of filteredIds(6)
updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD, 100));
Expand Down
Loading