CagraQuery

View as Markdown

Java package: com.nvidia.cuvs

1public class CagraQuery

CagraQuery holds the CagraSearchParams and the query vectors to be used while invoking search.

Thread Safety: Each CagraQuery instance should use its own CuVSResources object that is not shared with other threads. Sharing CuVSResources between threads can lead to memory allocation errors or JVM crashes.

Public Members

CagraQuery

1private CagraQuery( CagraSearchParams cagraSearchParameters, CuVSMatrix queryVectors, LongToIntFunction mapping, int topK, BitSet prefilter, int numDocs, CuVSResources resources)

Constructs an instance of CagraQuery using cagraSearchParameters, preFilter, queryVectors, mapping, and topK.

Parameters

NameDescription
cagraSearchParametersan instance of CagraSearchParams holding the search parameters
queryVectors2D float query vector array
mappinga function mapping ordinals (neighbor IDs) to custom user IDs
topKthe top k results to return
prefilterA single BitSet to use as filter while searching the CAGRA index
numDocsTotal number of dataset vectors; used to align the prefilter correctly
resourcesCuVSResources instance to use for this query

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:43

getCagraSearchParameters

1public CagraSearchParams getCagraSearchParameters()

Gets the instance of CagraSearchParams initially set.

Returns

an instance CagraSearchParams

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:66

getQueryVectors

1public CuVSMatrix getQueryVectors()

Gets the query vector matrix.

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:73

getMapping

1public LongToIntFunction getMapping()

Gets the function mapping ordinals (neighbor IDs) to custom user IDs

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:80

getTopK

1public int getTopK()

Gets the topK value.

Returns

the topK value

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:89

getPrefilter

1public BitSet getPrefilter()

Gets the prefilter BitSet.

Returns

a BitSet object representing the prefilter

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:98

getNumDocs

1public int getNumDocs()

Gets the number of documents in this index, as used for prefilter

Returns

number of documents as an integer

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:107

getResources

1public CuVSResources getResources()

Gets the CuVSResources instance for this query.

Returns

the CuVSResources instance

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:116

Builder

1public Builder(CuVSResources resources)

Constructor that requires CuVSResources.

Important: The provided CuVSResources instance should not be shared with other threads. Each thread performing searches should create its own CuVSResources instance to avoid memory allocation conflicts and potential JVM crashes.

Parameters

NameDescription
resourcesthe CuVSResources instance to use for this query (must not be shared between threads)

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:155

withSearchParams

1public Builder withSearchParams(CagraSearchParams cagraSearchParams)

Sets the instance of configured CagraSearchParams to be passed for search.

Parameters

NameDescription
cagraSearchParamsan instance of the configured CagraSearchParams to be used for this query

Returns

an instance of this Builder

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

withQueryVectors

1public Builder withQueryVectors(CuVSMatrix queryVectors)

Registers the query vectors to be passed in the search call.

Parameters

NameDescription
queryVectors2D query vector array

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:177

withMapping

1public Builder withMapping(LongToIntFunction mapping)

Sets the function used to map ordinals (neighbor IDs) to custom user IDs

Parameters

NameDescription
mappinga function mapping ordinals (neighbor IDs) to custom user IDs

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:188

withTopK

1public Builder withTopK(int topK)

Registers the topK value.

Parameters

NameDescription
topKthe topK value used to retrieve the topK results

Returns

an instance of this Builder

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:199

withPrefilter

1public Builder withPrefilter(BitSet prefilter, int numDocs)

Sets a global prefilter for all queries in this CagraQuery. The prefilter array must contain exactly one BitSet, which is applied to all queries. A bit value of 1 includes the corresponding dataset vector; 0 excludes it.

Parameters

NameDescription
prefilteran array with the global filter BitSet
numDocstotal number of vectors in the dataset (for alignment)

Returns

this Builder instance

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:214

build

1public CagraQuery build()

Builds an instance of CuVSQuery.

Returns

an instance of CuVSQuery

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:225

Source: java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java:21