Skip to content

Commit 349c7aa

Browse files
committed
expose knn format and update test
1 parent e62112e commit 349c7aa

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

lucene/sandbox/src/java/module-info.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040

4141
provides org.apache.lucene.codecs.PostingsFormat with
4242
org.apache.lucene.sandbox.codecs.idversion.IDVersionPostingsFormat;
43-
provides org.apache.lucene.codecs.KnnVectorsFormat with
43+
provides org.apache.lucene.codecs.KnnVectorsFormat with
4444
org.apache.lucene.sandbox.vectorsearch.CuVSVectorsFormat;
45-
// provides org.apache.lucene.codecs.Codec with
46-
// org.apache.lucene.sandbox.vectorsearch.CuVSCodec;
4745
provides com.nvidia.cuvs.spi.CuVSServiceProvider with
4846
org.apache.lucene.sandbox.vectorsearch.FilterCuVSServiceProvider;
4947
}

lucene/sandbox/src/java/org/apache/lucene/sandbox/vectorsearch/CagraFieldVectorsWriter.java

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.lucene.sandbox.vectorsearch;
1818

1919
import java.io.IOException;
20-
import java.nio.charset.Charset;
2120
import java.nio.charset.StandardCharsets;
2221
import java.util.concurrent.ConcurrentHashMap;
2322
import org.apache.lucene.codecs.KnnFieldVectorsWriter;

lucene/sandbox/src/java/org/apache/lucene/sandbox/vectorsearch/CuVSVectorsFormat.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class CuVSVectorsFormat extends KnnVectorsFormat {
3131
public static final String VECTOR_DATA_EXTENSION = "cag";
3232
public static final String META_EXTENSION = "cagmf";
3333
public static final int VERSION_CURRENT = 0;
34+
public static final int DEFAULT_WRITER_THREADS = 1;
35+
public static final int DEFAULT_INTERMEDIATE_GRAPH_DEGREE = 128;
36+
public static final int DEFAULT_GRAPH_DEGREE = 64;
37+
3438
public final int maxDimensions = 4096;
3539
public final int cuvsWriterThreads;
3640
public final int intGraphDegree;
@@ -39,15 +43,11 @@ public class CuVSVectorsFormat extends KnnVectorsFormat {
3943
public static CuVSResources resources;
4044

4145
public CuVSVectorsFormat() {
42-
super("CuVSVectorsFormat");
43-
this.cuvsWriterThreads = 1;
44-
this.intGraphDegree = 128;
45-
this.graphDegree = 64;
46-
try {
47-
resources = CuVSResources.create();
48-
} catch (Throwable e) {
49-
throw new RuntimeException(e);
50-
}
46+
this(
47+
DEFAULT_WRITER_THREADS,
48+
DEFAULT_INTERMEDIATE_GRAPH_DEGREE,
49+
DEFAULT_GRAPH_DEGREE,
50+
MergeStrategy.NON_TRIVIAL_MERGE);
5151
}
5252

5353
public CuVSVectorsFormat(

lucene/sandbox/src/java/org/apache/lucene/sandbox/vectorsearch/CuVSVectorsReader.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ private Map<String, List<CuVSIndex>> loadCuVSIndex(ZipInputStream zis, boolean i
145145
}
146146
case "vec":
147147
{
148-
vectors.put(
149-
segmentField, SerializationUtils.deserialize(baos.toByteArray()));
148+
vectors.put(segmentField, SerializationUtils.deserialize(baos.toByteArray()));
150149
break;
151150
}
152151
case "map":

lucene/sandbox/src/resources/META-INF/services/org.apache.lucene.codecs.Codec

-16
This file was deleted.

lucene/sandbox/src/test/org/apache/lucene/sandbox/vectorsearch/TestCuVS.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class TestCuVS extends LuceneTestCase {
6666
public static void beforeClass() throws Exception {
6767
directory = newDirectory();
6868

69-
Codec codec = new CuVSCodec();
69+
Codec codec = TestUtil.alwaysKnnVectorsFormat(new CuVSVectorsFormat());
7070

7171
RandomIndexWriter writer =
7272
new RandomIndexWriter(
@@ -105,8 +105,8 @@ public static void beforeClass() throws Exception {
105105

106106
@AfterClass
107107
public static void afterClass() throws Exception {
108-
reader.close();
109-
directory.close();
108+
if (reader != null) reader.close();
109+
if (directory != null) directory.close();
110110
searcher = null;
111111
reader = null;
112112
directory = null;

0 commit comments

Comments
 (0)