CagraIndex

View as Markdown

Java package: com.nvidia.cuvs

1public interface CagraIndex extends AutoCloseable

CagraIndex encapsulates a CAGRA index, along with methods to interact with it.

CAGRA is a graph-based nearest neighbors algorithm that was built from the ground up for GPU acceleration. CAGRA demonstrates state-of-the art index build and query performance for both small and large-batch sized search. Know more about this algorithm here

Public Members

close

1@Override void close() throws Exception

Invokes the native destroy_cagra_index to de-allocate the CAGRA index

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:29

1SearchResults search(CagraQuery query) throws Throwable

Invokes the native search_cagra_index via the Panama API for searching a CAGRA index.

Parameters

NameDescription
queryan instance of CagraQuery holding the query vectors and other parameters

Returns

an instance of SearchResults containing the results

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:40

getGraph

1CuVSDeviceMatrix getGraph()

Returns the CAGRA graph

Returns

a CuVSDeviceMatrix encapsulating the native int (uint32_t) array used to represent the cagra graph

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:47

serialize

1void serialize(OutputStream outputStream) throws Throwable

A method to persist a CAGRA index using an instance of OutputStream for writing index bytes.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes into

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:56

serialize

1void serialize(OutputStream outputStream, int bufferLength) throws Throwable

A method to persist a CAGRA index using an instance of OutputStream for writing index bytes.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes into
bufferLengththe length of buffer to use for writing bytes. Default value is 1024

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:67

serialize

1default void serialize(OutputStream outputStream, Path tempFile) throws Throwable

A method to persist a CAGRA index using an instance of OutputStream for writing index bytes.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes into
tempFilean intermediate Path where CAGRA index is written temporarily

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:78

serialize

1void serialize(OutputStream outputStream, Path tempFile, int bufferLength) throws Throwable

A method to persist a CAGRA index using an instance of OutputStream and path to the intermediate temporary file.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes to
tempFilean intermediate Path where CAGRA index is written temporarily
bufferLengththe length of buffer to use for writing bytes. Default value is 1024

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:93

serializeToHNSW

1void serializeToHNSW(OutputStream outputStream) throws Throwable

A method to create and persist HNSW index from CAGRA index using an instance of OutputStream and path to the intermediate temporary file.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes to

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:102

serializeToHNSW

1void serializeToHNSW(OutputStream outputStream, int bufferLength) throws Throwable

A method to create and persist HNSW index from CAGRA index using an instance of OutputStream and path to the intermediate temporary file.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes to
bufferLengththe length of buffer to use for writing bytes. Default value is 1024

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:113

serializeToHNSW

1default void serializeToHNSW(OutputStream outputStream, Path tempFile) throws Throwable

A method to create and persist HNSW index from CAGRA index using an instance of OutputStream and path to the intermediate temporary file.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes to
tempFilean intermediate Path where CAGRA index is written temporarily

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:124

serializeToHNSW

1void serializeToHNSW(OutputStream outputStream, Path tempFile, int bufferLength) throws Throwable

A method to create and persist HNSW index from CAGRA index using an instance of OutputStream and path to the intermediate temporary file.

Parameters

NameDescription
outputStreaman instance of OutputStream to write the index bytes to
tempFilean intermediate Path where CAGRA index is written temporarily
bufferLengththe length of buffer to use for writing bytes. Default value is 1024

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:139

getCuVSResources

1CuVSResources getCuVSResources()

Gets an instance of CuVSResources

Returns

an instance of CuVSResources

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:146

newBuilder

1static Builder newBuilder(CuVSResources cuvsResources)

Creates a new Builder with an instance of CuVSResources.

Parameters

NameDescription
cuvsResourcesan instance of CuVSResources

Throws

TypeDescription
UnsupportedOperationExceptionif the provider does not cuvs

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:154

merge

1static CagraIndex merge(CagraIndex[] indexes) throws Throwable

Merges multiple CAGRA indexes into a single index using default merge parameters.

Parameters

NameDescription
indexesArray of CAGRA indexes to merge

Returns

A new merged CAGRA index

Throws

TypeDescription
Throwableif an error occurs during the merge operation

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:166

merge

1static CagraIndex merge(CagraIndex[] indexes, CagraIndexParams mergeParams) throws Throwable

Merges multiple CAGRA indexes into a single index with the specified merge parameters.

Parameters

NameDescription
indexesArray of CAGRA indexes to merge
mergeParamsParameters to control the merge operation, or null to use defaults

Returns

A new merged CAGRA index

Throws

TypeDescription
Throwableif an error occurs during the merge operation

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:178

from

1Builder from(InputStream inputStream)

Sets an instance of InputStream typically used when index deserialization is needed.

Parameters

NameDescription
inputStreaman instance of InputStream

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:205

from

1Builder from(CuVSMatrix graph)

Sets a CAGRA graph instance to re-create an index from a previously built graph.

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:211

withDataset

1Builder withDataset(float[][] vectors)

Sets the dataset vectors for building the CagraIndex.

Parameters

NameDescription
vectorsa two-dimensional float array

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:219

withDataset

1Builder withDataset(CuVSMatrix dataset)

Sets the dataset for building the CagraIndex.

Parameters

NameDescription
dataseta CuVSMatrix object containing the vectors

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:227

withIndexParams

1Builder withIndexParams(CagraIndexParams cagraIndexParameters)

Registers an instance of configured CagraIndexParams with this Builder.

Parameters

NameDescription
cagraIndexParametersAn instance of CagraIndexParams.

Returns

An instance of this Builder.

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:236

build

1CagraIndex build() throws Throwable

Builds and returns an instance of CagraIndex.

Returns

an instance of CagraIndex

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:243

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java:25