You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2022/02/01 15:21:54 UTC

[lucene] branch main updated: Small fix for assertConsistentGraph (#631)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new c8e1c08  Small fix for assertConsistentGraph (#631)
c8e1c08 is described below

commit c8e1c08cc8bf1d33d9796f9c114cb9852bc37195
Author: Mayya Sharipova <ma...@elastic.co>
AuthorDate: Tue Feb 1 10:21:48 2022 -0500

    Small fix for assertConsistentGraph (#631)
    
    TestKnnGraph.testMultipleVectorFields sometimes breaks with
    the following message:
    
    java.lang.NullPointerException: Cannot invoke
     "org.apache.lucene.codecs.lucene91.Lucene91HnswVectorsReader.getGraphValues(String)"
    because "vectorReader" is null
    
    This happens in assertConsistentGraph.
    
    This patch ensures that for a segment and a field  where there is no
    vectors indexed, we don't run a check on consistent graph.
---
 lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java b/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
index e2366aa..0590024 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
@@ -172,9 +172,11 @@ public class TestKnnGraph extends LuceneTestCase {
     int numDoc = atLeast(100);
     int[] dims = new int[numVectorFields];
     float[][][] values = new float[numVectorFields][][];
+    FieldType[] fieldTypes = new FieldType[numVectorFields];
     for (int field = 0; field < numVectorFields; field++) {
       dims[field] = atLeast(3);
       values[field] = randomVectors(numDoc, dims[field]);
+      fieldTypes[field] = KnnVectorField.createFieldType(dims[field], similarityFunction);
     }
 
     try (Directory dir = newDirectory();
@@ -184,8 +186,7 @@ public class TestKnnGraph extends LuceneTestCase {
         for (int field = 0; field < numVectorFields; field++) {
           float[] vector = values[field][docID];
           if (vector != null) {
-            FieldType fieldType = KnnVectorField.createFieldType(vector.length, similarityFunction);
-            doc.add(new KnnVectorField(KNN_GRAPH_FIELD + field, vector, fieldType));
+            doc.add(new KnnVectorField(KNN_GRAPH_FIELD + field, vector, fieldTypes[field]));
           }
         }
         String idString = Integer.toString(docID);
@@ -428,7 +429,6 @@ public class TestKnnGraph extends LuceneTestCase {
     try (DirectoryReader dr = DirectoryReader.open(iw)) {
       for (LeafReaderContext ctx : dr.leaves()) {
         LeafReader reader = ctx.reader();
-        VectorValues vectorValues = reader.getVectorValues(vectorField);
         PerFieldKnnVectorsFormat.FieldsReader perFieldReader =
             (PerFieldKnnVectorsFormat.FieldsReader) ((CodecReader) reader).getVectorReader();
         if (perFieldReader == null) {
@@ -436,7 +436,11 @@ public class TestKnnGraph extends LuceneTestCase {
         }
         Lucene91HnswVectorsReader vectorReader =
             (Lucene91HnswVectorsReader) perFieldReader.getFieldReader(vectorField);
+        if (vectorReader == null) {
+          continue;
+        }
         KnnGraphValues graphValues = vectorReader.getGraphValues(vectorField);
+        VectorValues vectorValues = reader.getVectorValues(vectorField);
         if (vectorValues == null) {
           assert graphValues == null;
           continue;