-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass filterbitset as null and add integ tests.
Signed-off-by: Wei Wang <[email protected]>
- Loading branch information
1 parent
105c39a
commit c599062
Showing
4 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/org/opensearch/knn/integ/FilteredSearchANNSearchIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.integ; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.hc.core5.http.io.entity.EntityUtils; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.knn.KNNJsonQueryBuilder; | ||
import org.opensearch.knn.KNNRestTestCase; | ||
import org.opensearch.knn.index.KNNSettings; | ||
import java.util.List; | ||
|
||
import static org.opensearch.knn.common.KNNConstants.FAISS_NAME; | ||
import static org.opensearch.knn.common.KNNConstants.METHOD_HNSW; | ||
|
||
@Log4j2 | ||
public class FilteredSearchANNSearchIT extends KNNRestTestCase { | ||
@SneakyThrows | ||
public void testFilteredSearchWithFaissHnsw_whenFiltersMatchAllDocs_thenReturnCorrectResults() { | ||
String filterFieldName = "color"; | ||
final int expectResultSize = randomIntBetween(1, 3); | ||
final String filterValue = "red"; | ||
createKnnIndex(INDEX_NAME, getKNNDefaultIndexSettings(), createKnnIndexMapping(FIELD_NAME, 3, METHOD_HNSW, FAISS_NAME)); | ||
|
||
// ingest 4 vector docs into the index with the same field {"color": "red"} | ||
for (int i = 0; i < 4; i++) { | ||
addKnnDocWithAttributes(String.valueOf(i), new float[] { i, i, i }, ImmutableMap.of(filterFieldName, filterValue)); | ||
} | ||
|
||
refreshIndex(INDEX_NAME); | ||
forceMergeKnnIndex(INDEX_NAME); | ||
|
||
updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD, 0)); | ||
|
||
Float[] queryVector = { 3f, 3f, 3f }; | ||
// All docs in one segment will match the filters value | ||
String query = KNNJsonQueryBuilder.builder() | ||
.fieldName(FIELD_NAME) | ||
.vector(queryVector) | ||
.k(expectResultSize) | ||
.filterFieldName(filterFieldName) | ||
.filterValue(filterValue) | ||
.build() | ||
.getQueryString(); | ||
Response response = searchKNNIndex(INDEX_NAME, query, expectResultSize); | ||
String entity = EntityUtils.toString(response.getEntity()); | ||
List<String> docIds = parseIds(entity); | ||
assertEquals(expectResultSize, docIds.size()); | ||
assertEquals(expectResultSize, parseTotalSearchHits(entity)); | ||
} | ||
} |