msokolov commented on code in PR #14256: URL: https://github.com/apache/lucene/pull/14256#discussion_r1960570796
########## lucene/core/src/java/org/apache/lucene/search/knn/MappedDISI.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.knn; + +import java.io.IOException; +import org.apache.lucene.index.KnnVectorValues; +import org.apache.lucene.search.DocIdSetIterator; + +/** + * A {@link DocIdSetIterator} that maps the doc ids from a {@link TopDocsDISI} to the corresponding + * vector ordinal + * + * @lucene.internal + */ +public sealed class MappedDISI extends DocIdSetIterator { Review Comment: whoa I had to look up what a sealed class is - I guess it is like final but you can allow some classes to inherit? ########## lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphBuilder.java: ########## @@ -229,25 +230,32 @@ public void addGraphNode(int node, UpdateableRandomVectorScorer scorer) throws I // NOTE: the entry node and max level may not be paired, but because we get the level first // we ensure that the entry node we get later will always exist on the curMaxLevel int[] eps = new int[] {hnsw.entryNode()}; + float[] epsScores = new float[] {scorer.score(eps[0])}; // we first do the search from top to bottom // for levels > nodeLevel search with topk = 1 GraphBuilderKnnCollector candidates = entryCandidates; for (int level = curMaxLevel; level > nodeLevel; level--) { candidates.clear(); - graphSearcher.searchLevel(candidates, scorer, level, eps, hnsw, null); + graphSearcher.searchLevel(candidates, scorer, level, eps, epsScores, hnsw, null); + epsScores[0] = candidates.queue.topScore(); eps[0] = candidates.popNode(); } // for levels <= nodeLevel search with topk = beamWidth, and add connections candidates = beamCandidates; NeighborArray[] scratchPerLevel = new NeighborArray[Math.min(nodeLevel, curMaxLevel) - lowestUnsetLevel + 1]; + int epCount = eps.length; for (int i = scratchPerLevel.length - 1; i >= 0; i--) { int level = i + lowestUnsetLevel; candidates.clear(); - graphSearcher.searchLevel(candidates, scorer, level, eps, hnsw, null); - eps = candidates.popUntilNearestKNodes(); + graphSearcher.searchLevel(candidates, scorer, level, eps, epsScores, epCount, hnsw, null); + candidates.popUntilNearestKNodes(); + eps = ArrayUtil.growExact(eps, candidates.size()); + epsScores = ArrayUtil.growExact(epsScores, candidates.size()); + epCount = candidates.size(); + candidates.collectNodesAndScores(eps, epsScores); Review Comment: you are re-using the scores from upper levels when scoring the lower levels? -- 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-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org