Maybe not a helpful response but I want to say anyway that you should consider "Collapse & Expand" before result grouping. It's generally more efficient, code details are better encapsulated (which I care about, as a maintainer). However, result grouping works on distributed search (shards) when a group may span shards.
If you find a perf bug; PR welcome! On Sat, Apr 5, 2025 at 6:49 AM Yue Yu <yue...@bloomreach.com> wrote: > Hi All, > > When running vector search with grouping in multi-shard setting, the > KnnFloatVectorQuery is executed (2+rows) times. > > I've observed that Qtime grows linearly when I increase "rows" number > > The culprit is this function call in > > https://github.com/apache/solr/blob/main/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java#L202 > > if (needScores) { > for (GroupDocs<?> group : topGroups.groups) { > TopFieldCollector.populateScores(group.scoreDocs, searcher, query); > } > } > > Where > > https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java#L403 > does > > final Weight weight = searcher.createWeight(searcher.rewrite(query), > ScoreMode.COMPLETE, 1); > > Here, if the query is KnnFloatVectorQuery, *searcher.rewrite(query) *will > execute the same vector search for each topGroups.groups > > a simple fix could be moving *searcher.rewrite(query) *out of the > topGroups.groups loop. Thoughts? > > Best, > > Yue >