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

未关闭
#2,639 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
search

调研方向

先从 LuceneAcceleratedHNSWScalarQuantizedVectorsFormat 和 LuceneAcceleratedHNSWBinaryQuantizedVectorsFormat 中的 fieldsWriter 开始,然后检查 LuceneProvider 中对应的 fallback 方法。使用 setCuVSResourcesInstance(null) 和提供的 codec 加载示例重现该问题。完成的标准是两个量化 codec 都能通过各自的 CPU fallback 成功建立索引,且不会抛出异常。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Cuda
星标
902
派生
267
平均合并
2 天 21 小时
30 天内合并 PR
57

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/cuvs 的其他 Issue

查看 NVIDIA/cuvs 的全部 Issue

相似的 Issue

更多 Search Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。