Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ public static void main(String[] args) throws Throwable {
// Create the index with the dataset
CagraIndex index =
CagraIndex.newBuilder(resources)
.withDataset(vectors)
.fromDataset(vectors)
.withIndexParams(indexParams)
.build();

// Saving the index on to the disk.
String indexFileName = UUID.randomUUID().toString() + ".cag";
index.serialize(new FileOutputStream(indexFileName));
try (FileOutputStream outputStream = new FileOutputStream(indexFileName)) {
index.serialize(outputStream);
}

// Loading a CAGRA index from disk.
// Loading a CAGRA index from disk. Loading reads the stream but leaves closing it to us.
File indexFile = new File(indexFileName);
InputStream inputStream = new FileInputStream(indexFile);
CagraIndex loadedIndex = CagraIndex.newBuilder(resources).from(inputStream).build();
CagraIndex loadedIndex;
try (InputStream inputStream = new FileInputStream(indexFile)) {
loadedIndex = CagraIndex.newBuilder(resources).fromSerialized(inputStream).build();
}

// Configure search parameters
CagraSearchParams searchParams = new CagraSearchParams.Builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void main(String[] args) throws Throwable {
// Create the index with the dataset
CagraIndex index =
CagraIndex.newBuilder(resources)
.withDataset(vectors)
.fromDataset(vectors)
.withIndexParams(indexParams)
.build();

Expand Down
Loading
Loading