Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4367f36
Refactor merge to call CAGRA's merge(), implement CAGRA prefiltering
chatman Aug 11, 2025
f136334
Handle CAGRA merge with deletions and code cleanup
narangvivek10 Aug 13, 2025
283e2cf
Code refactoring
narangvivek10 Aug 13, 2025
e19b628
Adding tests for BF and CAG+BF merge
chatman Aug 14, 2025
2d96c71
Slight fix to IntStream usage
chatman Aug 14, 2025
53d326c
Merge branch 'branch-25.10' into searchscale/merge-and-prefiltering
chatman Aug 14, 2025
3f0a03b
Move createFloatMatrix to Utils
narangvivek10 Aug 14, 2025
433c485
Merge branch 'branch-25.10' into searchscale/merge-and-prefiltering
chatman Aug 28, 2025
84eae2f
Fail tests if cuVS libraries not found
Sep 4, 2025
9498678
Debugging on CI to see where to find libcuvs_c.so
Sep 4, 2025
40e21f1
Merge branch 'branch-25.10' into searchscale/merge-and-prefiltering
chatman Sep 4, 2025
31f1dab
Revert "Debugging on CI to see where to find libcuvs_c.so"
Sep 4, 2025
6f8bebd
Upgrade to latest cuvs-java & pulling libcuvs from nightly if not fou…
Sep 11, 2025
5692496
Merge branch 'branch-25.10' into searchscale/merge-and-prefiltering
chatman Sep 11, 2025
41a0124
CI Style check fix
Sep 11, 2025
221de3d
CI shellcheck fixes
Sep 11, 2025
5de9cc9
Disabling shellcheck SC1091
Sep 11, 2025
00947ef
Error finding .so file in CI, adding debug logging
Sep 11, 2025
3d9de2d
find command was failing for non-existent paths that were present in …
Sep 11, 2025
5b1313b
Removing CUDA 12.9 build and debug-printing libcudart.so location
Sep 11, 2025
5b90792
Debug-printing libcudart.so location
Sep 11, 2025
6c0fb70
Adding the conda's lib dir to LD_LIBRARY_PATH
Sep 11, 2025
1b9ce64
Removing the loading of cudart to see if tests still pass
Sep 11, 2025
f0efa86
Revert "Removing the loading of cudart to see if tests still pass"
Sep 11, 2025
4b09035
Update build.sh - to build cuvs from source instead, revert pr.yaml
narangvivek10 Sep 21, 2025
8c8e009
Add --build-cuvs-from-source argument
narangvivek10 Sep 21, 2025
c4f1abb
Update ci/build_java.sh - to handle additional argument
narangvivek10 Sep 21, 2025
fa7cdb1
Update build.sh - change cuvs repo
narangvivek10 Sep 21, 2025
f4bc2e6
Update build.sh - get cmake if not available
narangvivek10 Sep 21, 2025
06e39dd
Revert build from source changes.
narangvivek10 Sep 22, 2025
76010c0
Merge branch 'branch-25.10' into searchscale/merge-and-prefiltering
narangvivek10 Sep 22, 2025
d8bb38d
Use libcuvs from conda environment instead
narangvivek10 Sep 22, 2025
f27f907
Update log message in ci/build_java.sh
narangvivek10 Sep 24, 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
41 changes: 41 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,47 @@ function hasArg {
(( NUMARGS != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
}

if hasArg --build-cuvs-from-source; then

CUR_DIR=$(pwd)
# Get cmake locally if not found
if ! cmake; then
echo "==> cmake not found. Downloading..."
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v4.1.1/cmake-4.1.1-linux-x86_64.tar.gz"
wget $CMAKE_URL
tar -xvf cmake-4.1.1-linux-x86_64.tar.gz
CMAKE_HOME="cmake-4.1.1-linux-x86_64"
export PATH="$CUR_DIR/$CMAKE_HOME/bin:$PATH"
echo "PATH: $PATH"
fi

unset LD_LIBRARY_PATH
CUVS_REPO="https://github.com/rapidsai/cuvs.git"
CUVS_DIR="cuvs"
BUILD_DIR=$CUVS_DIR/cpp/build

# checkout cuvs
if [ ! -d "$CUVS_DIR" ]; then
echo "==> Current working directory is: $CUR_DIR, checking out cuvs repository into $CUR_DIR..."
RV=$(git clone $CUVS_REPO $CUVS_DIR)
if [ "$RV" -ne 0 ]; then
echo "==> cuvs checkout failed."
exit "$RV"
fi
fi

# build cuvs
echo "==> Building cuvs"
if ! ./$CUVS_DIR/build.sh libcuvs; then
echo "==> cuvs build.sh returned non-zero."
exit "$RV"
fi
Comment thread
narangvivek10 marked this conversation as resolved.
Outdated

# set LD_LIBRARY_PATH variable
export LD_LIBRARY_PATH="$CUR_DIR/$BUILD_DIR"
echo "==> LD_LIBRARY_PATH is set to: $LD_LIBRARY_PATH"
fi

MAVEN_VERIFY_ARGS=()
if ! hasArg --run-java-tests; then
MAVEN_VERIFY_ARGS=("-DskipTests")
Expand Down
11 changes: 8 additions & 3 deletions ci/build_java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ set -euo pipefail
# and test_java.sh no longer calls build_java.sh
# ref: https://github.com/rapidsai/cuvs/issues/868
EXTRA_BUILD_ARGS=()
if [[ "${1:-}" == "--run-java-tests" ]]; then
EXTRA_BUILD_ARGS+=("--run-java-tests")
fi
for arg in "$@"; do
if [[ "$arg" == "--run-java-tests" ]]; then
EXTRA_BUILD_ARGS+=("--run-java-tests")
fi
if [[ "$arg" == "--build-cuvs-from-source" ]]; then
EXTRA_BUILD_ARGS+=("--build-cuvs-from-source")
fi
done

# shellcheck disable=SC1091
. /opt/conda/etc/profile.d/conda.sh
Expand Down
2 changes: 1 addition & 1 deletion ci/test_java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ rapids-logger "Run Java build and tests"

# TODO: switch to installing pre-built artifacts instead of rebuilding in test jobs
# ref: https://github.com/rapidsai/cuvs/issues/868
ci/build_java.sh --run-java-tests
ci/build_java.sh --run-java-tests --build-cuvs-from-source
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<groupId>com.nvidia.cuvs</groupId>
<artifactId>cuvs-java</artifactId>
<!-- Note: This is temporary measure (artifact coming from https://maven.searchscale.com/snapshots, for now) and will get updated in subsequent PRs. -->
<version>25.8.0-4f53f-SNAPSHOT</version>
<version>25.10.0-2c0e1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/nvidia/cuvs/lucene/CuVSIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.nvidia.cuvs.lucene;

import static com.nvidia.cuvs.lucene.CuVSVectorsReader.handleThrowable;

import com.nvidia.cuvs.BruteForceIndex;
import com.nvidia.cuvs.CagraIndex;
import com.nvidia.cuvs.HnswIndex;
Expand Down Expand Up @@ -103,16 +101,16 @@ public void close() throws IOException {
private void destroyIndices() throws IOException {
try {
if (cagraIndex != null) {
cagraIndex.destroyIndex();
cagraIndex.close();
}
if (bruteforceIndex != null) {
bruteforceIndex.destroyIndex();
bruteforceIndex.close();
}
if (hnswIndex != null) {
hnswIndex.destroyIndex();
hnswIndex.close();
}
} catch (Throwable t) {
handleThrowable(t);
Utils.handleThrowable(t);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.KnnFloatVectorQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.knn.KnnCollectorManager;
import org.apache.lucene.util.Bits;
Expand All @@ -29,8 +30,9 @@ public class CuVSKnnFloatVectorQuery extends KnnFloatVectorQuery {
private final int iTopK;
private final int searchWidth;

public CuVSKnnFloatVectorQuery(String field, float[] target, int k, int iTopK, int searchWidth) {
super(field, target, k);
public CuVSKnnFloatVectorQuery(
String field, float[] target, int k, Query filter, int iTopK, int searchWidth) {
super(field, target, k, filter);
this.iTopK = iTopK;
this.searchWidth = searchWidth;
}
Expand All @@ -46,7 +48,7 @@ protected TopDocs approximateSearch(
PerLeafCuVSKnnCollector results = new PerLeafCuVSKnnCollector(k, iTopK, searchWidth);

LeafReader reader = context.reader();
reader.searchNearestVectors(field, this.getTargetCopy(), results, null);
reader.searchNearestVectors(field, this.getTargetCopy(), results, acceptDocs);
return results.topDocs();
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/nvidia/cuvs/lucene/CuVSVectorsFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public CuVSVectorsFormat(
}

private static CuVSResources cuVSResourcesOrNull() {
try {
System.loadLibrary(

@msarahan msarahan Sep 24, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you can pass arguments to loadLibrary in your Java code and not rely on LD_LIBRARY_PATH, things will probably be more robust. The hard part is that it must be recursive. Loading a conda library should load all conda dependencies, or else you get weird runtime errors. This is especially problematic with libstdc++.

One way to ensure that libstdc++ does not accidentally come from the system is to explicitly load it from the conda environment before loading any other (conda-based) libraries.

I don't know much at all about Java, but this site seemed to have some helpful alternatives to LD_LIBRARY_PATH. The more you can change just your process and not the environment, the fewer strange issues you'll have. LD_LIBRARY_PATH is a foot gun. Use it if you must, but only after exhausting other options.

"cudart"); // nocommit: this is here so as to pass CI, should goto cuvs-java
} catch (UnsatisfiedLinkError e) {
LOG.warning("Could not load CUDA runtime library: " + e.getMessage());
}
try {
resources = CuVSResources.create();
return resources;
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/nvidia/cuvs/lucene/CuVSVectorsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private CuVSIndex loadCuVSIndex(FieldEntry fieldEntry) throws IOException {
}
}
} catch (Throwable t) {
handleThrowable(t);
Utils.handleThrowable(t);
}
return new CuVSIndex(cagraIndex, bruteForceIndex, hnswIndex);
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public void search(String field, float[] target, KnnCollector knnCollector, Bits
try {
searchResult = cagraIndex.search(query).getResults();
} catch (Throwable t) {
handleThrowable(t);
Utils.handleThrowable(t);
}
// List expected to have only one entry because of single query "target".
assert searchResult.size() == 1;
Expand All @@ -385,7 +385,7 @@ public void search(String field, float[] target, KnnCollector knnCollector, Bits
try {
searchResult = bruteforceIndex.search(query).getResults();
} catch (Throwable t) {
handleThrowable(t);
Utils.handleThrowable(t);
}
assert searchResult.size() == 1;
result = searchResult.getFirst();
Expand Down Expand Up @@ -472,12 +472,15 @@ static void checkVersion(int versionMeta, int versionVectorData, IndexInput in)
}
}

static void handleThrowable(Throwable t) throws IOException {
switch (t) {
case IOException ioe -> throw ioe;
case Error error -> throw error;
case RuntimeException re -> throw re;
case null, default -> throw new RuntimeException("UNEXPECTED: exception type", t);
}
public FieldInfos getFieldInfos() {
return fieldInfos;
}

public IntObjectHashMap<CuVSIndex> getCuvsIndexes() {
return cuvsIndices;
}

public IntObjectHashMap<FieldEntry> getFieldEntries() {
return fields;
}
}
Loading
Loading