You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2026/02/04 17:12:05 UTC

(lucene) branch branch_10x updated (a9d3f4dbd98 -> de0781d5dec)

This is an automated email from the ASF dual-hosted git repository.

shubhamvishu pushed a change to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


    from a9d3f4dbd98 Fix FVH boost issue (#15442) (#15635)
     new 2531e89fa3a Avoid unnecessary getGraph() call (#15560)
     new 94b76ce05b9 Optimize DocIdSetIteratorAcceptDocs#cost (#15592)
     new de0781d5dec Disable bypassing graph creation for HnswGraphTestCase#testReadWrite (#15419)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codecs/lucene99/Lucene99HnswVectorsReader.java     |  8 ++++----
 .../src/java/org/apache/lucene/search/AcceptDocs.java  | 12 +++++++-----
 .../lucene/search/BaseKnnVectorQueryTestCase.java      | 18 +++++++++++++++---
 .../org/apache/lucene/util/hnsw/HnswGraphTestCase.java |  6 ++----
 4 files changed, 28 insertions(+), 16 deletions(-)


(lucene) 01/03: Avoid unnecessary getGraph() call (#15560)

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shubhamvishu pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 2531e89fa3a3c0458f751992fdbb37b4e0a9c5bb
Author: Shubham Chaudhary <sh...@gmail.com>
AuthorDate: Mon Jan 12 14:19:00 2026 -0500

    Avoid unnecessary getGraph() call (#15560)
    
    * Avoid unnecessary getGraph() call which initializes the OffHeapHnswGraph whereas all we need is graph size
---
 .../apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
index 7e84bd9cdcd..6bb0812cb0d 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
@@ -341,15 +341,15 @@ public final class Lucene99HnswVectorsReader extends KnnVectorsReader
     // Take into account if quantized? E.g. some scorer cost?
     // Use approximate cardinality as this is good enough, but ensure we don't exceed the graph
     // size as that is illogical
-    HnswGraph graph = getGraph(fieldEntry);
-    int filteredDocCount = Math.min(acceptDocs.cost(), graph.size());
+    int graphSize = (fieldEntry.vectorIndexLength() == 0) ? 0 : fieldEntry.size();
+    int filteredDocCount = Math.min(acceptDocs.cost(), graphSize);
     Bits accepted = acceptDocs.bits();
     final Bits acceptedOrds = scorer.getAcceptOrds(accepted);
     int numVectors = scorer.maxOrd();
     boolean doHnsw = knnCollector.k() < numVectors;
     // The approximate number of vectors that would be visited if we did not filter
-    int unfilteredVisit = HnswGraphSearcher.expectedVisitedNodes(knnCollector.k(), graph.size());
-    if (unfilteredVisit >= filteredDocCount || graph.size() == 0) {
+    int unfilteredVisit = HnswGraphSearcher.expectedVisitedNodes(knnCollector.k(), graphSize);
+    if (unfilteredVisit >= filteredDocCount || graphSize == 0) {
       doHnsw = false;
     }
     if (doHnsw) {


(lucene) 03/03: Disable bypassing graph creation for HnswGraphTestCase#testReadWrite (#15419)

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shubhamvishu pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit de0781d5dec1fe123a450e2ac14c53344267f8cc
Author: Shubham Chaudhary <36...@users.noreply.github.com>
AuthorDate: Mon Dec 1 08:28:22 2025 -0500

    Disable bypassing graph creation for HnswGraphTestCase#testReadWrite (#15419)
---
 .../src/test/org/apache/lucene/util/hnsw/HnswGraphTestCase.java     | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/HnswGraphTestCase.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/HnswGraphTestCase.java
index 1ed25ecf3b2..2d1ef75c3c8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/hnsw/HnswGraphTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/HnswGraphTestCase.java
@@ -319,7 +319,7 @@ abstract class HnswGraphTestCase<T> extends LuceneTestCase {
       IndexWriterConfig iwc =
           new IndexWriterConfig()
               .setCodec(
-                  TestUtil.alwaysKnnVectorsFormat(new Lucene99HnswVectorsFormat(M, beamWidth)));
+                  TestUtil.alwaysKnnVectorsFormat(new Lucene99HnswVectorsFormat(M, beamWidth, 0)));
       try (IndexWriter iw = new IndexWriter(dir, iwc)) {
         KnnVectorValues.DocIndexIterator it2 = v2.iterator();
         while (it2.nextDoc() != NO_MORE_DOCS) {
@@ -350,9 +350,7 @@ abstract class HnswGraphTestCase<T> extends LuceneTestCase {
                               ((CodecReader) ctx.reader()).getVectorReader())
                           .getFieldReader("field"))
                   .getGraph("field");
-          if (graphValues.size() > 0) {
-            assertGraphEqual(hnsw, graphValues);
-          }
+          assertGraphEqual(hnsw, graphValues);
         }
       }
     }


(lucene) 02/03: Optimize DocIdSetIteratorAcceptDocs#cost (#15592)

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shubhamvishu pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 94b76ce05b9c6889535264495858e0cb609c28fb
Author: Shubham Chaudhary <sh...@gmail.com>
AuthorDate: Thu Jan 22 17:55:55 2026 -0500

    Optimize DocIdSetIteratorAcceptDocs#cost (#15592)
---
 .../src/java/org/apache/lucene/search/AcceptDocs.java  | 12 +++++++-----
 .../lucene/search/BaseKnnVectorQueryTestCase.java      | 18 +++++++++++++++---
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java b/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
index 8771f63438e..d0eb817aefd 100644
--- a/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
+++ b/lucene/core/src/java/org/apache/lucene/search/AcceptDocs.java
@@ -157,7 +157,7 @@ public abstract class AcceptDocs {
 
   /**
    * Impl backed by a {@link DocIdSetIterator}, which lazily creates a {@link BitSet} if {@link
-   * #cost()} or {@link #bits()} are called.
+   * #bits()} is called. Otherwise, returns the cost of underlying iterator.
    */
   private static class DocIdSetIteratorAcceptDocs extends AcceptDocs {
 
@@ -189,8 +189,10 @@ public abstract class AcceptDocs {
 
     @Override
     public int cost() throws IOException {
-      createBitSetAcceptDocsIfNecessary();
-      return cardinality;
+      if (acceptBitSet != null) {
+        return cardinality;
+      }
+      return Math.toIntExact(iterator().cost());
     }
 
     @Override
@@ -198,8 +200,8 @@ public abstract class AcceptDocs {
       if (acceptBitSet != null) {
         return new BitSetIterator(acceptBitSet, cardinality);
       }
-      DocIdSetIterator iterator = Objects.requireNonNull(iteratorSupplier.get());
-      return AcceptDocs.getFilteredDocIdSetIterator(iterator, liveDocs);
+      return AcceptDocs.getFilteredDocIdSetIterator(
+          Objects.requireNonNull(iteratorSupplier.get()), liveDocs);
     }
   }
 
diff --git a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
index 1ec59b849ac..90767a6d9a8 100644
--- a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
@@ -59,7 +59,6 @@ import org.apache.lucene.tests.index.RandomIndexWriter;
 import org.apache.lucene.tests.store.BaseDirectoryWrapper;
 import org.apache.lucene.tests.util.LuceneTestCase;
 import org.apache.lucene.tests.util.TestUtil;
-import org.apache.lucene.util.BitSet;
 import org.apache.lucene.util.BitSetIterator;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.FixedBitSet;
@@ -687,6 +686,19 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
         for (int i = 0; i < dimension; i++) {
           vector[i] = i % 2 == 0 ? 42 : 7;
         }
+        // This is to consistently ensure we take the exactSearch path and make the #cost not random
+        // when we don't cache in PointRangeQuery
+        searcher.setQueryCachingPolicy(
+            new QueryCachingPolicy() {
+
+              @Override
+              public void onUse(Query query) {}
+
+              @Override
+              public boolean shouldCache(Query query) throws IOException {
+                return true;
+              }
+            });
         Query filter4 = IntPoint.newRangeQuery("tag", 250, 256);
         expectThrows(
             UnsupportedOperationException.class,
@@ -1139,8 +1151,8 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
           BitSetIterator bitSetIterator =
               new BitSetIterator(docs, docs.approximateCardinality()) {
                 @Override
-                public BitSet getBitSet() {
-                  throw new UnsupportedOperationException("reusing BitSet is not supported");
+                public long cost() {
+                  throw new UnsupportedOperationException("reusing BitSetIterator cost");
                 }
               };
           final var scorer = new ConstantScoreScorer(score(), scoreMode, bitSetIterator);