Justin Coyne created SOLR-18688:
-----------------------------------

             Summary: Combined Query (RRF) throws 
ArrayIndexOutOfBoundsException computing facet.query counts when a query is 
knn-based
                 Key: SOLR-18688
                 URL: https://issues.apache.org/jira/browse/SOLR-18688
             Project: Solr
          Issue Type: Bug
         Environment: * Solr 10.1, SolrCloud, one collection with 1 shard and 1 
replica
* Java 21 (OpenJDK 21.0.12), Linux amd64
* About 2.6M nested child documents, each with a 768-dimension DenseVectorField 
(HNSW, cosine), under about 65k parent documents. The index has 14–16 segments.
            Reporter: Justin Coyne


A combined query (CombinedQueryComponent, \{{combiner.algorithm=rrf}}) fails 
with HTTP 500 when the request has \{{facet.query}} and one of the combined 
queries is a \{{knn}} query, or contains one. The same request succeeds when 
any of these is true:
* \{{facet.query}} is removed. \{{facet.field}} facets work fine in the same 
request.
* the vector query is an exact \{{vectorSimilarity}} query with no knn inside 
it.
* it is sent to /select as a single query (no combiner) with the same 
\{{facet.query}}.

It depends on the query text: some queries fail every time and others never do, 
against the same index.


h3. Request (shape)


{code:json}
POST /solr/<collection>/<combined-query handler>
{
  "params": {
    "rows": 20,
    "facet": true,
    "facet.field": ["format_hsim"],
    "facet.query": ["child_count_i:1", "child_count_i:[2 TO *]"],
    "combiner": true,
    "combiner.query": ["lexical", "vector"],
    "combiner.algorithm": "rrf",
    "vector_parents": "doc_type_ssi:parent",
    "vector_candidates": "\{!knn f=vector topK=1000 
childrenOf=$vector_parents}[...768 floats...]"
  },
  "queries": {
    "lexical": \{ "edismax": { "query": "coasts", "qf": "all_search_tesi" } },
    "vector": {
      "parent": {
        "which": "doc_type_ssi:parent",
        "score": "max",
        "query": "\{!vectorSimilarity f=vector minReturn=0.8 
preFilter=$vector_candidates}[...768 floats...]"
      }
    }
  }
}
{code}



h3. Error

{code}
org.apache.solr.client.solrj.RemoteSolrException: Error from server at 
http://<host>:8080/solr/<core>/<handler>:
java.lang.ArrayIndexOutOfBoundsException: Index 41797 out of bounds for length 
41797
    at 
org.apache.solr.client.solrj.impl.HttpSolrClient.processErrorsAndResponse(HttpSolrClient.java:271)
{code}



The failing index equals the array length, so this looks like a doc ID one past 
a segment's maxDoc. My guess is that a knn query's matching docs, which come 
from the rewritten query's global doc IDs, are mapped to the wrong leaf when 
the facet.query DocSet intersection is computed for the combined result.

h3. Variants tried (all for the same failing query text)
|| vector query in the combined request || facet.query || result ||
| vectorSimilarity minReturn=0.8 (exact, no knn) | yes | OK |
| parent(vectorSimilarity, preFilter = knn childrenOf, topK=1000) | yes | *500* 
|
| parent(knn childrenOf, topK=1000) directly | yes | *500* |
| parent(vectorSimilarity, preFilter = plain knn topK=5000) | yes | *500* |
| same as row 2, knn inline in preFilter instead of $param | yes | *500* |
| same as row 2 | no (facet.field only) | OK |
| same as row 2, facet.method=enum | yes | *500* |
| same as row 2, sort=score desc / no sort | yes | *500* |
| same as row 2, rows=0 | yes | *500* |
| same as row 2 on /select (no combiner) | yes | OK |

h3. Workaround
Leave \{{facet.query}} out of the combined request, and compute the facet.query 
counts with a separate rows=0 /select request whose query is \{{bool should 
[lexical, vector]}} (the same documents the combined result facets over).

h3. Related
* SOLR-18550 / SOLR-18541: numFound of combined queries. We also see numFound 
equal to the first query's hits rather than the size of the fused set.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to