benwtrent commented on code in PR #15948: URL: https://github.com/apache/lucene/pull/15948#discussion_r3131734983
########## lucene/core/src/java/org/apache/lucene/search/BayesianScoreEstimator.java: ########## @@ -0,0 +1,228 @@ +/* + * 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.lucene.search; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredFields; +import org.apache.lucene.index.Term; +import org.apache.lucene.util.ArrayUtil; + +/** + * Estimates {@link BayesianScoreQuery} parameters (alpha, beta, base rate) from corpus statistics + * via pseudo-query sampling. + * + * <p>The estimation algorithm: + * + * <ol> + * <li>Sample N documents randomly from the index + * <li>For each document, create a pseudo-query from its first few tokens in the target field + * <li>Run each pseudo-query via BM25 and collect the score distribution + * <li>Estimate: beta = median(scores), alpha = 1 / std(scores) + * <li>Estimate base rate: mean fraction of documents scoring above the 95th percentile + * </ol> + * + * @lucene.experimental + */ +public class BayesianScoreEstimator { Review Comment: So, I see these params are then used within `BayesianScoreQuery` I wonder, could we have a constructor for `BayesianScoreQuery` (and have those internal parameters be nullable), that detects during `rewrite` if the parameters are null, and if they are, we provide the correct estimation? Or we adjust the interface so that `BayesianScoreQuery` accepts an estimator in its constructor OR the parameters, and if its an estimator, it will handle it rewrite? Is the main concern that the estimation should only ever happen once per the life time of the index? Or only periodically vs. on every 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: [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]
