Skip to content

Commit

Permalink
java fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanrb123 committed Oct 17, 2023
1 parent fe4d30a commit 506556b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 11 additions & 5 deletions java/src/main/java/com/spotify/voyager/jni/StringIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public static StringIndex load(
}

/**
* Load a previously constructed index from the provided file location. The space type, dimensions, and storage data type are read from the file metadata.
* Load a previously constructed index from the provided file location. The space type,
* dimensions, and storage data type are read from the file metadata.
*
* @param indexFilename Filename of the underlying HNSW index
* @param nameListFilename Filename of the JSON encoded names list
Expand All @@ -186,15 +187,18 @@ public static StringIndex load(final String indexFilename, final String nameList
}

/**
* Load a previously constructed index from the provided input stream. The space type, dimensions, and storage data type are read from the file metadata.
* Load a previously constructed index from the provided input stream. The space type, dimensions,
* and storage data type are read from the file metadata.
*
* @param indexInputStream input stream pointing to the underlying HNSW index
* @param nameListInputStream input stream pointing to the JSON encoded names list
* @return reference to the loaded StringIndex
*/
public static StringIndex load(final InputStream indexInputStream, final InputStream nameListInputStream) {
public static StringIndex load(
final InputStream indexInputStream, final InputStream nameListInputStream) {
Index index = Index.load(new BufferedInputStream(indexInputStream, DEFAULT_BUFFER_SIZE));
List<String> names = TinyJson.readStringList(new BufferedInputStream(nameListInputStream, DEFAULT_BUFFER_SIZE));
List<String> names =
TinyJson.readStringList(new BufferedInputStream(nameListInputStream, DEFAULT_BUFFER_SIZE));
return new StringIndex(index, names);
}

Expand All @@ -208,7 +212,9 @@ public void saveIndex(final String outputDirectory) throws IOException {
saveIndex(outputDirectory, INDEX_FILE_NAME, NAMES_LIST_FILE_NAME);
}

public void saveIndex(final String outputDirectory, final String indexFilename, final String nameListFilename) throws IOException {
public void saveIndex(
final String outputDirectory, final String indexFilename, final String nameListFilename)
throws IOException {
Path indexPath = Paths.get(outputDirectory, indexFilename);
Path namesPath = Paths.get(outputDirectory, nameListFilename);
try {
Expand Down
7 changes: 2 additions & 5 deletions java/src/test/java/com/spotify/voyager/jni/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.junit.Test;
import org.junit.experimental.theories.suppliers.TestedOn;

public class IndexTest {
static final Map<Index.StorageDataType, Float> PRECISION_PER_DATA_TYPE = new HashMap<>();
Expand Down Expand Up @@ -100,6 +98,7 @@ public void testInnerProductE4M3() throws Exception {
runTestWith(InnerProduct, 2000, StorageDataType.E4M3, false);
runTestWith(InnerProduct, 2000, StorageDataType.E4M3, true);
}

/**
* One large test method with variable parameters, to replicate the parametrized tests we get "for
* free" in Python with PyTest.
Expand Down Expand Up @@ -223,9 +222,7 @@ private void runTestWith(
assertTrue(outputStream.size() > 0);

// Recreate the index from the outputStream alone and ensure queries still work:
try (Index reloadedIndex =
Index.load(
new ByteArrayInputStream(outputStream.toByteArray()))) {
try (Index reloadedIndex = Index.load(new ByteArrayInputStream(outputStream.toByteArray()))) {
final Index.QueryResults[] reloadedResults = reloadedIndex.query(inputData, 1, -1);
for (int i = 0; i < numElements; i++) {
Index.QueryResults neighbor = reloadedResults[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class StringIndexTest {
private static final String EXPECTED_NAME_FILE_NAME = "names.json";
private static final String EXPECTED_INDEX_V2_FILE_NAME = "index-v2.hnsw";
private static final String EXPECTED_NAME_V2_FILE_NAME = "names-v2.json";

@Test
public void itFindsNeighbors() throws Exception {
List<Vector> testVectors = TestUtils.getTestVectors();
Expand Down

0 comments on commit 506556b

Please sign in to comment.