Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions java/cuvs-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>9.12.0</version>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
9 changes: 9 additions & 0 deletions java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ private void initializeMethodHandles() throws IOException {
* index
*/
private IndexReference build() throws Throwable {
if (dataset == null || dataset.length == 0 || dataset[0].length == 0) {
throw new IllegalArgumentException("Dataset cannot be null or empty");
}
long rows = dataset.length;
long cols = dataset[0].length;
MemoryLayout layout = resources.linker.canonicalLayouts().get("int");
Expand All @@ -138,6 +141,9 @@ private IndexReference build() throws Throwable {
* @return an instance of {@link CagraSearchResults} containing the results
*/
public CagraSearchResults search(CagraQuery query) throws Throwable {
if (query.getQueryVectors() == null) {
throw new IllegalArgumentException("Query vectors cannot be null");
}
long numQueries = query.getQueryVectors().length;
long numBlocks = query.getTopK() * numQueries;
int vectorDimension = numQueries > 0 ? query.getQueryVectors()[0].length : 0;
Expand Down Expand Up @@ -168,6 +174,9 @@ public CagraSearchResults search(CagraQuery query) throws Throwable {
* bytes into
*/
public void serialize(OutputStream outputStream) throws Throwable {
if (outputStream == null) {
throw new IllegalArgumentException("Output stream cannot be null");
}
serialize(outputStream, File.createTempFile(UUID.randomUUID().toString(), ".cag"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.nvidia.cuvs;

import static org.junit.jupiter.api.Assertions.assertEquals;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -28,7 +29,7 @@
import java.util.Map;
import java.util.UUID;

import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -100,14 +101,14 @@ public void testIndexingAndSearchingFlow() throws Throwable {

// Check results
log.info(results.getResults().toString());
assertEquals(expectedResults, results.getResults(), "Results different than expected");
assertEquals("Results different than expected", expectedResults, results.getResults());

// Search from deserialized index
results = loadedIndex.search(cuvsQuery);

// Check results
log.info(results.getResults().toString());
assertEquals(expectedResults, results.getResults(), "Results different than expected");
assertEquals("Results different than expected", expectedResults, results.getResults());

// Cleanup
if (indexFile.exists()) {
Expand Down
Loading
Loading