[BUG] CPU fallback for the quantized accelerated-HNSW Lucene codecs throws instead of falling back

Aperta
#2,639 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
search

Direzione di ricerca

Inizia con fieldsWriter in LuceneAcceleratedHNSWScalarQuantizedVectorsFormat e LuceneAcceleratedHNSWBinaryQuantizedVectorsFormat, quindi esamina i metodi di fallback corrispondenti in LuceneProvider. Riproduci il problema con setCuVSResourcesInstance(null) e l’esempio fornito di caricamento del codec. Il lavoro è completato quando entrambi i codec quantizzati indicizzano correttamente tramite il loro fallback CPU senza generare eccezioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug Lucene

Describe the bug

The CPU fallback path in LuceneAcceleratedHNSWScalarQuantizedVectorsFormat and LuceneAcceleratedHNSWBinaryQuantizedVectorsFormat is broken. When cuVS resources cannot be created, both log GPU based indexing not supported, falling back to using the ... and then throw instead of falling back.

Steps to reproduce

Try loading the codecs

package com.nvidia.cuvs.repro;

import static com.nvidia.cuvs.lucene.ThreadLocalCuVSResourcesProvider.setCuVSResourcesInstance;
import static org.apache.lucene.index.VectorSimilarityFunction.EUCLIDEAN;

import com.nvidia.cuvs.lucene.AcceleratedHNSWParams;
import com.nvidia.cuvs.lucene.Lucene101AcceleratedHNSWCodec;
import com.nvidia.cuvs.lucene.LuceneAcceleratedHNSWBinaryQuantizedCodec;
import com.nvidia.cuvs.lucene.LuceneAcceleratedHNSWScalarQuantizedCodec;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Random;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.KnnFloatVectorField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

/**
 * Indexes a few vectors with each accelerated HNSW codec while cuVS resources are unavailable.
 *
 * <p>All three codecs are documented to fall back to CPU index construction in this state.
 * Only {@code Lucene101AcceleratedHNSWCodec} does; the two quantized variants throw.
 */
public class FallbackRepro {

  private static final int NUM_DOCS = 16;
  private static final int DIMENSION = 8;

  public static void main(String[] args) throws Exception {
    // Force the !isSupported() branch on this thread, the same way
    // TestCagraToHnswSerializationAndSearchWithFallbackWriter does.
    setCuVSResourcesInstance(null);

    AcceleratedHNSWParams params = new AcceleratedHNSWParams.Builder().build();
    index("Lucene101AcceleratedHNSWCodec", new Lucene101AcceleratedHNSWCodec(params));
    index("LuceneAcceleratedHNSWScalarQuantizedCodec", new LuceneAcceleratedHNSWScalarQuantizedCodec(params));
    index("LuceneAcceleratedHNSWBinaryQuantizedCodec", new LuceneAcceleratedHNSWBinaryQuantizedCodec(params));
  }

  private static void index(String label, Codec codec) {
    Random random = new Random(222);
    IndexWriterConfig config = new IndexWriterConfig().setCodec(codec);
    try {
      Path indexPath = Files.createTempDirectory("cuvs-fallback-repro");
      try (Directory directory = FSDirectory.open(indexPath);
          IndexWriter writer = new IndexWriter(directory, config)) {
        for (int i = 0; i < NUM_DOCS; i++) {
          float[] vector = new float[DIMENSION];
          for (int j = 0; j < DIMENSION; j++) {
            vector[j] = random.nextFloat() * 100;
          }
          Document document = new Document();
          document.add(new KnnFloatVectorField("vector_field", vector, EUCLIDEAN));
          writer.addDocument(document);
        }
      }
      System.out.printf("%-45s OK%n", label);
    } catch (Throwable t) {
      System.out.printf("%-45s %s%n", label, t);
    }
  }
}

output:

WARNING: Java vector incubator module is not readable. For optimal vector performance, pass '--add-modules jdk.incubator.vector' to enable Vector API.
Sep 16, 2026 5:38:43 PM com.nvidia.cuvs.lucene.Lucene99AcceleratedHNSWVectorsFormat fieldsWriter
WARNING: GPU based indexing not supported, falling back to using the Lucene99HnswVectorsWriter
Lucene101AcceleratedHNSWCodec                 OK
Sep 16, 2026 5:38:44 PM com.nvidia.cuvs.lucene.LuceneAcceleratedHNSWScalarQuantizedVectorsFormat fieldsWriter
WARNING: GPU based indexing not supported, falling back to using the Lucene99HnswScalarQuantizedVectorsFormat
Sep 16, 2026 5:38:44 PM com.nvidia.cuvs.lucene.LuceneProvider getLuceneHnswScalarQuantizedVectorsFormatInstance
SEVERE: Unable to initialize LuceneHnswScalarQuantizedVectorsFormat: class org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat cannot be cast to class org.apache.lucene.codecs.hnsw.FlatVectorsFormat (org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat and org.apache.lucene.codecs.hnsw.FlatVectorsFormat are in unnamed module of loader org.codehaus.mojo.exec.URLClassLoaderBuilder$ExecJavaClassLoader @5f7989fa)
LuceneAcceleratedHNSWScalarQuantizedCodec     java.lang.ClassCastException: class org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat cannot be cast to class org.apache.lucene.codecs.hnsw.FlatVectorsFormat (org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat and org.apache.lucene.codecs.hnsw.FlatVectorsFormat are in unnamed module of loader org.codehaus.mojo.exec.URLClassLoaderBuilder$ExecJavaClassLoader @5f7989fa)
Sep 16, 2026 5:38:44 PM com.nvidia.cuvs.lucene.LuceneAcceleratedHNSWBinaryQuantizedVectorsFormat fieldsWriter
WARNING: GPU based indexing not supported, falling back to using the Lucene102HnswBinaryQuantizedVectorsFormat
Sep 16, 2026 5:38:44 PM com.nvidia.cuvs.lucene.LuceneProvider getLuceneHnswBinaryQuantizedVectorsFormatInstance
SEVERE: Unable to initialize LuceneBinaryQuantizedVectorsFormat: Cannot invoke "java.lang.Class.getConstructor(java.lang.Class[])" because "this.hnswBinaryQuantizedVectorsFormat" is null
LuceneAcceleratedHNSWBinaryQuantizedCodec     java.lang.NullPointerException: Cannot invoke "java.lang.Class.getConstructor(java.lang.Class[])" because "this.hnswBinaryQuantizedVectorsFormat" is null

Additional context covers three things:

The NullPointerException is already tracked in #2615 as part of another set of issues.

Lingua principale
Cuda
Stelle
902
Fork
267
Merge medio
2g 21h
PR unite (30g)
57

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/cuvs

Tutte le issue di NVIDIA/cuvs

Issue simili

Altre issue su Search

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.