Skip to content

Commit

Permalink
(tests): null check for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-4 committed Feb 2, 2025
1 parent 2b70063 commit 698b26a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/test/java/io/anserini/index/IndexHnswDenseVectorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;
import io.anserini.index.generator.InvalidDocumentException;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.lucene.index.IndexReader;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -198,6 +200,43 @@ public void testParquetFloat() throws Exception {
assertEquals(10, results.get("documents"));
}

@Test
public void testNullVector() throws Exception {
// Test for JsonDenseVectorDocumentGenerator
String indexPath = "target/lucene-test-index.hnsw." + System.currentTimeMillis();
String[] indexArgs = new String[] {
"-collection", "JsonDenseVectorCollection",
"-input", "src/test/resources/sample_docs/openai_ada2/json_vector_null",
"-index", indexPath,
"-generator", "JsonDenseVectorDocumentGenerator",
"-threads", "1"
};

try {
IndexHnswDenseVectors.main(indexArgs);
fail("Expected InvalidDocumentException");
} catch (InvalidDocumentException e) {
// expected
}

// Test for JsonInvertedDenseVectorDocumentGenerator
indexPath = "target/lucene-test-index.hnsw." + System.currentTimeMillis();
indexArgs = new String[] {
"-collection", "JsonDenseVectorCollection",
"-input", "src/test/resources/sample_docs/openai_ada2/json_vector_null",
"-index", indexPath,
"-generator", "JsonInvertedDenseVectorDocumentGenerator",
"-threads", "1"
};

try {
IndexHnswDenseVectors.main(indexArgs);
fail("Expected InvalidDocumentException");
} catch (InvalidDocumentException e) {
// expected
}
}

@Test
public void testQuantizedInt8() throws Exception {
String indexPath = "target/lucene-test-index.hnsw." + System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"docid": "1", "contents": "contents 1", "vector": null}

0 comments on commit 698b26a

Please sign in to comment.