-
Notifications
You must be signed in to change notification settings - Fork 140
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
Adds ef_search support for Lucene kNN queries #1748
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
package org.opensearch.knn.index.query; | ||
|
||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.KnnByteVectorQuery; | ||
import org.apache.lucene.search.KnnFloatVectorQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.TermQuery; | ||
|
@@ -85,6 +86,98 @@ public void testCreateLuceneDefaultQuery() { | |
} | ||
} | ||
|
||
public void testLuceneFloatVectorQuery() { | ||
Query actualQuery1 = KNNQueryFactory.create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a function to create the query as it is duplicated multiple times There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has a different request everytime. The create request itself is using a builder so wrapping it up with a function is moot |
||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.vector(testQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.methodParameters(methodParameters) | ||
.vectorDataType(VectorDataType.FLOAT) | ||
.build() | ||
); | ||
|
||
// efsearch > k | ||
Query expectedQuery1 = new KnnFloatVectorQuery(testFieldName, testQueryVector, 100, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
|
||
// efsearch < k | ||
actualQuery1 = KNNQueryFactory.create( | ||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.vector(testQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.methodParameters(Map.of("ef_search", 1)) | ||
.vectorDataType(VectorDataType.FLOAT) | ||
.build() | ||
); | ||
expectedQuery1 = new KnnFloatVectorQuery(testFieldName, testQueryVector, testK, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
|
||
actualQuery1 = KNNQueryFactory.create( | ||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.vector(testQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.vectorDataType(VectorDataType.FLOAT) | ||
.build() | ||
); | ||
expectedQuery1 = new KnnFloatVectorQuery(testFieldName, testQueryVector, testK, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
} | ||
|
||
public void testLuceneByteVectorQuery() { | ||
Query actualQuery1 = KNNQueryFactory.create( | ||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.byteVector(testByteQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.methodParameters(methodParameters) | ||
.vectorDataType(VectorDataType.BYTE) | ||
.build() | ||
); | ||
|
||
// efsearch > k | ||
Query expectedQuery1 = new KnnByteVectorQuery(testFieldName, testByteQueryVector, 100, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
|
||
// efsearch < k | ||
actualQuery1 = KNNQueryFactory.create( | ||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.byteVector(testByteQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.methodParameters(Map.of("ef_search", 1)) | ||
.vectorDataType(VectorDataType.BYTE) | ||
.build() | ||
); | ||
expectedQuery1 = new KnnByteVectorQuery(testFieldName, testByteQueryVector, testK, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
|
||
actualQuery1 = KNNQueryFactory.create( | ||
BaseQueryFactory.CreateQueryRequest.builder() | ||
.knnEngine(KNNEngine.LUCENE) | ||
.byteVector(testByteQueryVector) | ||
.k(testK) | ||
.indexName(testIndexName) | ||
.fieldName(testFieldName) | ||
.vectorDataType(VectorDataType.BYTE) | ||
.build() | ||
); | ||
expectedQuery1 = new KnnByteVectorQuery(testFieldName, testByteQueryVector, testK, null); | ||
assertEquals(expectedQuery1, actualQuery1); | ||
} | ||
|
||
public void testCreateLuceneQueryWithFilter() { | ||
List<KNNEngine> luceneDefaultQueryEngineList = Arrays.stream(KNNEngine.values()) | ||
.filter(knnEngine -> !KNNEngine.getEnginesThatCreateCustomSegmentFiles().contains(knnEngine)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a leftover from this PR https://github.com/opensearch-project/k-NN/pull/1742/files. The import is not needed. Sorry for the confusion