Jackie-Jiang commented on code in PR #19894:
URL: https://github.com/apache/pinot/pull/19894#discussion_r4622842126
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/vector/LuceneHnswRuntimeControlUtils.java:
##########
@@ -111,65 +174,48 @@ private static final class
RuntimeControlledKnnCollectorManager implements KnnCo
}
@Override
- public KnnCollector newCollector(int visitLimit, LeafReaderContext
context) {
- int effectiveVisitLimit = _efSearch > 0 ? Math.min(visitLimit,
_efSearch) : visitLimit;
- if (_useBoundedQueue) {
- AbstractKnnCollector leafCollector = new TopKnnCollector(_k,
effectiveVisitLimit);
- KnnCollector collector = _globalScoreQueue != null
- ? new MultiLeafKnnCollector(_k, _globalScoreQueue, leafCollector)
- : leafCollector;
- return _useRelativeDistance ? collector : new
RelativeDistanceDisabledKnnCollector(collector);
- }
- return new UnboundedKnnCollector(_k, effectiveVisitLimit,
_useRelativeDistance);
- }
- }
-
- private static final class RelativeDistanceDisabledKnnCollector implements
KnnCollector {
- private final KnnCollector _delegate;
-
- RelativeDistanceDisabledKnnCollector(KnnCollector delegate) {
- _delegate = delegate;
- }
-
- @Override
- public boolean earlyTerminated() {
- return _delegate.earlyTerminated();
- }
-
- @Override
- public void incVisitedCount(int count) {
- _delegate.incVisitedCount(count);
+ public KnnCollector newCollector(int visitLimit, KnnSearchStrategy
searchStrategy, LeafReaderContext context) {
+ // A reentrant pass is seeded with the first pass's candidates. Retain
that leaf quota when it exceeds k.
+ int leafK = searchStrategy instanceof KnnSearchStrategy.Seeded seeded
+ ? Math.max(_k, seeded.numberOfEntryPoints()) : _k;
+ return newCollector(visitLimit, searchStrategy, leafK);
}
@Override
- public long visitedCount() {
- return _delegate.visitedCount();
+ public KnnCollector newOptimisticCollector(int visitLimit,
KnnSearchStrategy searchStrategy,
+ LeafReaderContext context, int leafK) {
+ return newCollector(visitLimit, searchStrategy, leafK);
}
@Override
- public long visitLimit() {
- return _delegate.visitLimit();
+ public boolean isOptimistic() {
+ // Lucene checks its leaf quota before accepting filtered ANN results. A
seeded second pass can
+ // score all entry points before checking its visit limit, so keep it
disabled for explicit budgets.
+ return _hasFilter && _efSearch <= 0;
Review Comment:
[P2] Preserve the per-leaf quota with explicit visit budgets
The [earlier quota
finding](https://github.com/apache/pinot/pull/19894#discussion_r4622048804) is
fixed when `efSearch` is unset, but remains for positive budgets. Returning
`false` here disables quota-aware collectors while Lucene 10.6 still applies
its unconditional `perLeafTopK` acceptance check.
For example, use the new test's two 1,024-document leaves, broad filter and
`k=10`, but set `efSearch=10000`. Collectors still return at most 10 hits while
Lucene requires 30 per leaf. Even ANN that completes within its budget
therefore falls back to exact scanning. Lucene 9.12 accepted completed ANN
results without this quota check.
Please preserve an adequate first-pass leaf quota while suppressing
budget-unsafe seeded passes. Extend the regression with a positive budget large
enough for ANN to complete and assert zero exact scorers; its current
`efSearch=1` case only covers exhausted searches. See [Lucene's result
acceptance
check](https://github.com/apache/lucene/blob/releases/lucene/10.6.0/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java#L268-L297).
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/LuceneRegexpAutomaton.java:
##########
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.utils;
+
+import org.apache.lucene.util.automaton.Automaton;
+import org.apache.lucene.util.automaton.Operations;
+import org.apache.lucene.util.automaton.RegExp;
+
+
+/// Bounds Lucene regular expression construction and compiles deterministic
automata for the FST matchers.
+/// All compilation state is local to the caller.
+public final class LuceneRegexpAutomaton {
+ private static final int MAX_CONSTRUCTION_WORK =
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT;
+
+ private LuceneRegexpAutomaton() {
+ }
+
+ @SuppressWarnings("deprecation") // Preserve the complement syntax supported
by existing FST queries.
+ public static Automaton compile(String expression) {
+ RegExp regex = new RegExp(expression, RegExp.ALL |
RegExp.DEPRECATED_COMPLEMENT);
+ validateConstructionBudget(regex);
+ return Operations.determinize(regex.toAutomaton(),
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
+ }
+
+ /// Checks a pattern using Lucene text query syntax before building its
automaton.
+ public static void validateConstructionBudget(String expression) {
+ validateConstructionBudget(new RegExp(expression, RegExp.ALL));
+ }
+
+ private static void validateConstructionBudget(RegExp regex) {
+ // Lucene expands counted repetitions before determinizing. Estimate that
work on the parsed tree first.
+ estimate(regex);
+ }
+
+ private static ConstructionCost estimate(RegExp regex) {
+ return switch (regex.kind) {
+ case REGEXP_REPEAT_MIN, REGEXP_REPEAT_MINMAX ->
estimateRepetition(regex);
+ case REGEXP_CONCATENATION, REGEXP_UNION, REGEXP_INTERSECTION -> {
+ ConstructionCost left = estimate(regex.exp1);
+ ConstructionCost right = estimate(regex.exp2);
+ long work = regex.kind == RegExp.Kind.REGEXP_INTERSECTION
+ ? left.work() * right.work() : left.work() + right.work();
+ boolean acceptsEmpty = regex.kind == RegExp.Kind.REGEXP_UNION
+ ? left.acceptsEmpty() || right.acceptsEmpty()
+ : left.acceptsEmpty() && right.acceptsEmpty();
+ yield new ConstructionCost(work, acceptsEmpty);
+ }
+ case REGEXP_OPTIONAL, REGEXP_REPEAT -> new
ConstructionCost(estimate(regex.exp1).work() + 1, true);
Review Comment:
[P2] Include star transition growth in the construction budget
The complement fix addresses the reported case, but this existing estimate
has a separate expansion gap. Construct the expression as `"(" +
String.join("|", Collections.nCopies(3333, "aa?")) + ")*"`. Each alternative
costs 3 and the star adds 1, so the estimated cost is exactly 10,000 and
validation passes.
Each alternative retains an accepting state with an outgoing transition,
which Lucene's terminal-accept-state merging does not collapse. Lucene 10.6
`Operations.repeat` copies all 3,333 initial transitions onto each of those
3,333 accepting states, creating over 11 million transitions before final
determinization. Lucene 9.12 minimized the union before repetition. This
affects FST/IFST and built-in text regex validation.
Please account for the accepting-state × initial-transition expansion, or
bound construction directly, and add a regression for this case. Verified from
[Lucene 10.6 star
construction](https://github.com/apache/lucene/blob/releases/lucene/10.6.0/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java#L213-L276)
and [Lucene 9.12 union
minimization](https://github.com/apache/lucene/blob/releases/lucene/9.12.0/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java#L652-L660).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]