benwtrent commented on issue #13626:
URL: https://github.com/apache/lucene/issues/13626#issuecomment-2278487437

   OK, I was able to replicate with the following test:
   ```
    public void testTryToThrowNPE() throws Exception {
       try (var dir = newDirectory()) {
         IndexWriterConfig iwc = new IndexWriterConfig();
         iwc.setMergePolicy(new 
ForceMergePolicy(iwc.getMergePolicy())).setCodec(new Lucene912VectorCodec());
         try (var writer = new IndexWriter(dir, iwc)) {
           for (int i = 0; i < 10; i++) {
             var doc = new Document();
             if (random().nextBoolean()) {
               doc.add(new KnnFloatVectorField("field", new float[] {1, 2, 3}));
             }
             writer.addDocument(doc);
             if (random().nextBoolean()) {
               writer.commit();
             }
           }
           for (int i = 0; i < 10; i++) {
             var doc = new Document();
             if (random().nextBoolean()) {
               // add a vector but a different field
               doc.add(new KnnFloatVectorField("otherVector", new float[] {1, 
2, 3}));
             }
             writer.addDocument(doc);
             if (random().nextBoolean()) {
               writer.commit();
             }
           }
           writer.forceMerge(1);
         }
       }
     }
   ```
   
   The error goes away if you use the perField codec like so:
   
   ```
   public static class Lucene99VectorCodec extends FilterCodec
     {
       public Lucene99VectorCodec() {
         super("Lucene99VectorCodec", new Lucene99Codec());
       }
   
       @Override
       public KnnVectorsFormat knnVectorsFormat() {
         return new PerFieldKnnVectorsFormat() {
           @Override
           public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
             return new Lucene99HnswVectorsFormat(16, 250);
           }
         };
       }
     }
   ```
   
   I am not sure its valid to have more than one kNN field and not use the 
perfield format. The logic seems to make that assumption.
   
   @msokolov ^ What do you think of this bug. I am not sure what our behavior 
should be. We can easily check for a `null` field and return `null`.


-- 
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

Reply via email to