You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/06/17 15:01:22 UTC

[GitHub] [solr] alessandrobenedetti commented on a diff in pull request #904: SOLR-16246: Introduced pre-filtering in KnnQParser

alessandrobenedetti commented on code in PR #904:
URL: https://github.com/apache/solr/pull/904#discussion_r900200280


##########
solr/core/src/java/org/apache/solr/search/neural/KnnQParser.java:
##########
@@ -72,7 +81,49 @@ public Query parse() {
 
     DenseVectorField denseVectorType = (DenseVectorField) fieldType;
     float[] parsedVectorToSearch = parseVector(vectorToSearch, denseVectorType.getDimension());
-    return denseVectorType.getKnnVectorQuery(schemaField.getName(), parsedVectorToSearch, topK);
+
+    return getFilterQuery()

Review Comment:
   the if condition is not necessary, as the Lucene method accepts the null filter query



##########
solr/core/src/java/org/apache/solr/search/neural/KnnQParser.java:
##########
@@ -72,7 +81,49 @@ public Query parse() {
 
     DenseVectorField denseVectorType = (DenseVectorField) fieldType;
     float[] parsedVectorToSearch = parseVector(vectorToSearch, denseVectorType.getDimension());
-    return denseVectorType.getKnnVectorQuery(schemaField.getName(), parsedVectorToSearch, topK);
+
+    return getFilterQuery()
+        .map(
+            filterQuery ->
+                denseVectorType.getKnnVectorQuery(
+                    schemaField.getName(), parsedVectorToSearch, topK, filterQuery))
+        .orElse(
+            denseVectorType.getKnnVectorQuery(schemaField.getName(), parsedVectorToSearch, topK));
+  }
+
+  private Optional<? extends Query> getFilterQuery() throws SolrException {

Review Comment:
   don't think we need an Optional here, let's discuss



##########
solr/core/src/java/org/apache/solr/schema/DenseVectorField.java:
##########
@@ -276,6 +276,11 @@ public Query getKnnVectorQuery(String fieldName, float[] vectorToSearch, int top
     return new KnnVectorQuery(fieldName, vectorToSearch, topK);
   }
 
+  public Query getKnnVectorQuery(

Review Comment:
   It's not necessary to keep the original one, KnnVectorQuery accepts 'null' for empty filter query



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org