Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
acae395
initial work
narangvivek10 May 16, 2025
3116819
fix for cagra search
narangvivek10 May 19, 2025
29362e5
bruteforce implementation
narangvivek10 May 20, 2025
4ffec00
hnsw implementation
narangvivek10 May 20, 2025
f6bb090
gpuInfo implementation
narangvivek10 May 21, 2025
f150914
CAGRA index dims and size implementation
narangvivek10 May 21, 2025
228a02f
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 21, 2025
d8c8769
remove panama class and additional refactoring
narangvivek10 May 22, 2025
184f12b
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 22, 2025
d7ce786
update CagraBuildAndSearchIT - remove getIndexSize call
narangvivek10 May 22, 2025
1dabaf8
additional refactoring changes
narangvivek10 May 22, 2025
ac9f98d
API update - move CagraCompressionParams from CagraIndex to CagraInde…
narangvivek10 May 22, 2025
de65604
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 23, 2025
9481325
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 26, 2025
cd8b859
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 27, 2025
66dca00
Find the libcuvs_c.so during runtime, using LD_LIBRARY_PATH
May 27, 2025
442a67e
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
chatman May 27, 2025
14bee25
Build fix: jextract couldn't find cudaMemcpy, so adding cuda_runtime_…
May 27, 2025
bcf87f1
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
chatman May 27, 2025
e043c8c
Fixing Panama Bindings generation for CUDA 12.8: removing named heade…
May 28, 2025
b36d005
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
chatman May 28, 2025
3e7ca02
Removing the C layer's .so file completely
May 28, 2025
71ca015
Minor cleanups
May 28, 2025
e9a8b6d
style-check fix
narangvivek10 May 28, 2025
6675419
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
narangvivek10 May 28, 2025
ff0c7a3
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
chatman Jun 2, 2025
d69d12a
Merge branch 'branch-25.06' into vivek/replace-c-layer-with-panama-impl
chatman Jun 3, 2025
410de12
Merge branch 'branch-25.08' into vivek/replace-c-layer-with-panama-impl
narangvivek10 Jun 4, 2025
39f92d7
style-check fixes
narangvivek10 Jun 4, 2025
2b56f59
Merge branch 'branch-25.08' into vivek/replace-c-layer-with-panama-impl
chatman Jun 4, 2025
b104f19
review fixes
narangvivek10 Jun 4, 2025
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
12 changes: 8 additions & 4 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# CuVS Java API
# cuVS Java API
Comment thread
narangvivek10 marked this conversation as resolved.


CuVS Java API provides a Java based simple, efficient, and a robust vector search API.
cuVS Java API provides a Java based simple, efficient, and a robust vector search API.

> [!CAUTION]
> CuVS 25.06 contains an experimental version and updates to this API are expected in the coming release.
> This contains an experimental APIs and may change in upcoming releases.

## Prerequisites

Expand All @@ -21,7 +21,11 @@ The libcuvs C and C++ libraries are needed for this API. If libcuvs libraries ha
Alternatively, if libcuvs libraries are already built and you just want to build this API, please
do `./build.sh java` in the top level directory or just do `./build.sh` in this directory.

## Testing

Run `./build.sh --run-java-tests` from this directory.

Comment on lines +24 to +27
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏


## Examples

A few starter examples of CAGRA, HNSW, and Bruteforce index are provided in the `examples` directory.
A few starter examples of CAGRA, HNSW, and Bruteforce indexing and searching are provided in the `examples` directory.
13 changes: 9 additions & 4 deletions java/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -e -u -o pipefail
ARGS="$*"
NUMARGS=$#

CURDIR=$(cd "$(dirname $0)"; pwd)
VERSION="25.08.0" # Note: The version is updated automatically when ci/release/update-version.sh is invoked
GROUP_ID="com.nvidia.cuvs"
SO_FILE_PATH="./internal/build"

if [ -z "${CMAKE_PREFIX_PATH:=}" ]; then
CMAKE_PREFIX_PATH="$(pwd)/../cpp/build"
Expand All @@ -30,7 +30,12 @@ if ! hasArg --run-java-tests; then
fi

# Build the java layer
mvn install:install-file -DgroupId=$GROUP_ID -DartifactId=cuvs-java-internal -Dversion=$VERSION -Dpackaging=so -Dfile=$SO_FILE_PATH/libcuvs_java.so \
&& cd cuvs-java \
&& mvn verify "${MAVEN_VERIFY_ARGS[@]}" \
if [ -z ${LD_LIBRARY_PATH+x} ]
then export LD_LIBRARY_PATH=${CURDIR}/../cpp/build
else export LD_LIBRARY_PATH=${CURDIR}/../cpp/build:${LD_LIBRARY_PATH}
fi

export LD_LIBRARY_PATH=${CURDIR}/../cpp/build:${LD_LIBRARY_PATH}
cd cuvs-java
mvn verify "${MAVEN_VERIFY_ARGS[@]}" \
&& mvn install:install-file -Dfile=./target/cuvs-java-$VERSION-jar-with-dependencies.jar -DgroupId=$GROUP_ID -DartifactId=cuvs-java -Dversion=$VERSION -Dpackaging=jar
29 changes: 0 additions & 29 deletions java/cuvs-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Comment thread
narangvivek10 marked this conversation as resolved.
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.nvidia.cuvs</groupId>
<artifactId>cuvs-java-internal</artifactId>
<!-- NOTE: The version automatically gets updated when ci/release/update-version.sh is invoked. -->
<!--CUVS_JAVA#VERSION_UPDATE_MARKER_START--><version>25.08.0</version><!--CUVS_JAVA#VERSION_UPDATE_MARKER_END-->
<type>so</type>
<overWrite>false</overWrite>
<outputDirectory>
${project.build.directory}/classes/META-INF/native/linux_x64</outputDirectory>
<destFileName>libcuvs_java.so</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
public class CagraCompressionParams {

private CuVSResources resources;
private final int pqBits;
private final int pqDim;
private final int vqNCenters;
Expand All @@ -35,7 +34,6 @@ public class CagraCompressionParams {
* Constructs an instance of CagraCompressionParams with passed search
* parameters.
*
* @param resources the resources instance to use
* @param pqBits the bit length of the vector element after
* compression by PQ
* @param pqDim the dimensionality of the vector after
Expand All @@ -49,9 +47,8 @@ public class CagraCompressionParams {
* @param pqKmeansTrainsetFraction the fraction of data to use during iterative
* kmeans building (PQ phase)
*/
private CagraCompressionParams(CuVSResources resources, int pqBits, int pqDim, int vqNCenters, int kmeansNIters,
private CagraCompressionParams(int pqBits, int pqDim, int vqNCenters, int kmeansNIters,
double vqKmeansTrainsetFraction, double pqKmeansTrainsetFraction) {
this.resources = resources;
this.pqBits = pqBits;
this.pqDim = pqDim;
this.vqNCenters = vqNCenters;
Expand Down Expand Up @@ -132,16 +129,14 @@ public String toString() {
*/
public static class Builder {

private CuVSResources resources;
private int pqBits = 8;
private int pqDim = 0;
private int vqNCenters = 0;
private int kmeansNIters = 25;
private double vqKmeansTrainsetFraction = 0;
private double pqKmeansTrainsetFraction = 0;

public Builder(CuVSResources resources) {
this.resources = resources;
public Builder() {
}

/**
Expand Down Expand Up @@ -230,7 +225,7 @@ public Builder withPqKmeansTrainsetFraction(double pqKmeansTrainsetFraction) {
* @return an instance of {@link CagraCompressionParams}
*/
public CagraCompressionParams build() {
return new CagraCompressionParams(resources, pqBits, pqDim, vqNCenters, kmeansNIters, vqKmeansTrainsetFraction,
return new CagraCompressionParams(pqBits, pqDim, vqNCenters, kmeansNIters, vqKmeansTrainsetFraction,
pqKmeansTrainsetFraction);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,6 @@ interface Builder {
*/
Builder withIndexParams(CagraIndexParams cagraIndexParameters);

/**
* Registers an instance of configured {@link CagraCompressionParams} with this
* Builder.
*
* @param cagraCompressionParams An instance of CagraCompressionParams.
* @return An instance of this Builder.
*/
public Builder withCompressionParams(CagraCompressionParams cagraCompressionParams);

/**
* Builds and returns an instance of CagraIndex.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class CagraIndexParams {
private final int nnDescentNiter;
private final int numWriterThreads;
private final CuVSIvfPqParams cuVSIvfPqParams;
private final CagraCompressionParams cagraCompressionParams;

/**
* Enum that denotes which ANN algorithm is used to build CAGRA graph.
Expand Down Expand Up @@ -251,14 +252,16 @@ private CudaDataType(int value) {
}

private CagraIndexParams(int intermediateGraphDegree, int graphDegree, CagraGraphBuildAlgo CuvsCagraGraphBuildAlgo,
int nnDescentNiter, int writerThreads, CuvsDistanceType cuvsDistanceType, CuVSIvfPqParams cuVSIvfPqParams) {
int nnDescentNiter, int writerThreads, CuvsDistanceType cuvsDistanceType, CuVSIvfPqParams cuVSIvfPqParams,
Comment thread
narangvivek10 marked this conversation as resolved.
CagraCompressionParams cagraCompressionParams) {
this.intermediateGraphDegree = intermediateGraphDegree;
this.graphDegree = graphDegree;
this.cuvsCagraGraphBuildAlgo = CuvsCagraGraphBuildAlgo;
this.nnDescentNiter = nnDescentNiter;
this.numWriterThreads = writerThreads;
this.cuvsDistanceType = cuvsDistanceType;
this.cuVSIvfPqParams = cuVSIvfPqParams;
this.cagraCompressionParams = cagraCompressionParams;
}

/**
Expand Down Expand Up @@ -315,12 +318,33 @@ public CuVSIvfPqParams getCuVSIvfPqParams() {
return cuVSIvfPqParams;
}

/**
* Gets the CAGRA build algorithm.
*/
public CagraGraphBuildAlgo getCuvsCagraGraphBuildAlgo() {
return cuvsCagraGraphBuildAlgo;
}

/**
* Gets the number of Iterations to run.
*/
public int getNnDescentNiter() {
return nnDescentNiter;
}

/**
* Gets the CAGRA compression parameters.
*/
public CagraCompressionParams getCagraCompressionParams() {
return cagraCompressionParams;
}

@Override
public String toString() {
return "CagraIndexParams [cuvsCagraGraphBuildAlgo=" + cuvsCagraGraphBuildAlgo + ", cuvsDistanceType="
+ cuvsDistanceType + ", intermediateGraphDegree=" + intermediateGraphDegree + ", graphDegree=" + graphDegree
+ ", nnDescentNiter=" + nnDescentNiter + ", numWriterThreads=" + numWriterThreads + ", cuVSIvfPqParams="
+ cuVSIvfPqParams + "]";
+ cuVSIvfPqParams + ", cagraCompressionParams=" + cagraCompressionParams + "]";
}

/**
Expand All @@ -335,6 +359,7 @@ public static class Builder {
private int nnDescentNumIterations = 20;
private int numWriterThreads = 2;
private CuVSIvfPqParams cuVSIvfPqParams = new CuVSIvfPqParams.Builder().build();
private CagraCompressionParams cagraCompressionParams;

public Builder() {
}
Expand Down Expand Up @@ -418,14 +443,26 @@ public Builder withCuVSIvfPqParams(CuVSIvfPqParams cuVSIvfPqParams) {
return this;
}

/**
* Registers an instance of configured {@link CagraCompressionParams} with this
* Builder.
*
* @param cagraCompressionParams An instance of CagraCompressionParams.
* @return An instance of this Builder.
*/
public Builder withCompressionParams(CagraCompressionParams cagraCompressionParams) {
this.cagraCompressionParams = cagraCompressionParams;
return this;
}

/**
* Builds an instance of {@link CagraIndexParams}.
*
* @return an instance of {@link CagraIndexParams}
*/
public CagraIndexParams build() {
return new CagraIndexParams(intermediateGraphDegree, graphDegree, cuvsCagraGraphBuildAlgo, nnDescentNumIterations,
numWriterThreads, cuvsDistanceType, cuVSIvfPqParams);
numWriterThreads, cuvsDistanceType, cuVSIvfPqParams, cagraCompressionParams);
}
}
}
Loading