1515 */
1616package com .nvidia .cuvs .lucene ;
1717
18- import static com .nvidia .cuvs .lucene .Lucene99AcceleratedHNSWVectorsFormat .cuVSResourcesOrNull ;
1918import static com .nvidia .cuvs .lucene .TestUtils .generateDataset ;
19+ import static com .nvidia .cuvs .lucene .Utils .cuVSResourcesOrNull ;
2020import static org .apache .lucene .index .VectorSimilarityFunction .EUCLIDEAN ;
2121
2222import java .io .File ;
@@ -75,26 +75,20 @@ public static void beforeClass() throws Exception {
7575
7676 @ Test
7777 public void testCagraToHnswSerializationAndSearch () throws IOException {
78- log .info ("Test Scenario 1 - cuvs supported" );
79- test (
80- false ,
81- new Integer [] {1869 , 1803 , 1302 , 59 , 1497 , 108 , 1411 , 351 , 1982 },
82- indexDirPath .get (0 ));
83-
84- log .info ("Test Scenario 2 - cuvs NOT supported" );
85- test (true , new Integer [] {885 , 612 , 1795 , 1806 , 1665 }, indexDirPath .get (1 ));
78+ log .info ("Test Scenario 1 - cuVS supported" );
79+ test (new Integer [] {1869 , 1803 , 1302 , 59 , 1497 , 108 , 1411 , 351 , 1982 }, indexDirPath .get (0 ));
80+
81+ log .info ("Test Scenario 2 - cuVS NOT supported" );
82+ // Set resources to null to simulate that cuVS is not supported.
83+ Lucene99AcceleratedHNSWVectorsFormat .setResources (null );
84+ test (new Integer [] {885 , 612 , 1795 , 1806 , 1665 }, indexDirPath .get (1 ));
8685 }
8786
88- private void test (boolean disableResources , Integer [] expected , Path indexDirPath )
89- throws IOException {
87+ private void test (Integer [] expected , Path indexDirPath ) throws IOException {
9088
9189 Lucene101AcceleratedHNSWCodec codec =
9290 new Lucene101AcceleratedHNSWCodec (32 , 128 , 64 , 3 , 16 , 100 );
9391
94- if (disableResources ) {
95- Lucene99AcceleratedHNSWVectorsFormat .resources = null ;
96- }
97-
9892 IndexWriterConfig config = new IndexWriterConfig ().setCodec (codec ).setUseCompoundFile (false );
9993 // TODO: handle random related issues.
10094 int numDocs = 2000 ; // random.nextInt(100, 1000);
@@ -103,7 +97,7 @@ private void test(boolean disableResources, Integer[] expected, Path indexDirPat
10397 final int COMMIT_FREQ = 2000 ; // Math.min(numDocs, random.nextInt(100, 1000));
10498 int count = COMMIT_FREQ ;
10599 final String ID_FIELD = "id" ;
106- final String VECTOR_FIELD = "knn1 " ;
100+ final String VECTOR_FIELD = "vector_field " ;
107101 float [][] dataset = generateDataset (random , numDocs , dimension );
108102
109103 // Indexing
@@ -183,7 +177,7 @@ private void test(boolean disableResources, Integer[] expected, Path indexDirPat
183177 @ AfterClass
184178 public static void afterClass () throws Exception {
185179 // Reset resources.
186- Lucene99AcceleratedHNSWVectorsFormat .resources = cuVSResourcesOrNull ();
180+ Lucene99AcceleratedHNSWVectorsFormat .setResources ( cuVSResourcesOrNull () );
187181 // Cleanup.
188182 for (Path p : indexDirPath ) {
189183 File indexDirPathFile = p .toFile ();
0 commit comments