diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 075c5125..4b345eba 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,12 +11,15 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + java-version: ["8", "11", "16", "17", "21"] steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: - java-version: "17" - distribution: "oracle" + java-version: ${{ matrix.java-version }} + distribution: "temurin" - name: Set execute permission run: | chmod +x ./tools/mvn_test.sh @@ -33,7 +36,7 @@ jobs: uses: dev-vince/actions-publish-javadoc@v1.0.1 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - java-version: "17" + java-version: "8" java-distribution: "adopt" # The distributor of the target JDK. See https://github.com/actions/setup-java for more information. project: maven # The project type. branch: "gh-pages" # The branch for the javadoc contents. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46204bee..cd540363 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,16 +11,19 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + java-version: ["8", "11", "16", "17", "21"] steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: - java-version: "17" - distribution: "oracle" + java-version: ${{ matrix.java-version }} + distribution: "temurin" - name: Set execute permission run: | chmod +x ./tools/mvn_test.sh - name: Maven tests run: | ./tools/mvn_test.sh - shell: bash \ No newline at end of file + shell: bash diff --git a/README.md b/README.md index 9d33a89d..5dd61df5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,11 @@ Java client library with handy utility methods and overloads for interfacing wit > Not yet published. -To install the library, add the following lines to your build config file. Requires JDK 17 or above. +> [!IMPORTANT] +> Requires Java 8 or above. + +To install the library, add the following lines to your build config file. + #### Maven ```xml @@ -98,6 +102,7 @@ time: 7.04541E-4 The library offers handy utility methods for constructing GRPC structures. ```java +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -118,12 +123,13 @@ PointStruct point = 0, VectorUtil.toVector(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f), PayloadUtil.toPayload(map)); -List points = List.of(point); +List points = Arrays.asList; client.upsertPoints(collectionName, points, null); ``` #### Performing a search on the vectors with filtering ```java +import io.qdrant.client.grpc.Points.Filter; import io.qdrant.client.grpc.Points.SearchPoints; import io.qdrant.client.grpc.Points.SearchResponse; @@ -133,41 +139,22 @@ Filter filter = FilterUtil.must(FilterUtil.fieldCondition("age", FilterUtil.matc SearchPoints request = SearchPoints.newBuilder() .setCollectionName(collectionName) - .addAllVector(List.of(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f)) + .addAllVector(Arrays.asList(0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f)) .setFilter(filter) .setWithPayload(SelectorUtil.withPayload()) .setLimit(10) .build(); SearchResponse result = client.searchPoints(request); -System.out.println(result); + +ScoredPoint result = results.getResult(0); + +System.out.println("Similarity: " + result.getScore()); +System.out.println("Payload: " + PayloadUtil.toMap(result.getPayload())); ``` *Output*: ``` -result { -id { -num: 0 -} -payload { -key: "age" -value { -integer_value: 42 -} -} -payload { -key: "married" -value { -bool_value: true -} -} -payload { -key: "name" -value { -string_value: "John Doe" -} -} -score: 0.9999999 -} -time: 4.63542E-4 +Similarity: 0.9999999 +Payload: {name=John Doe, married=true, age=42} ``` diff --git a/pom.xml b/pom.xml index d6361cb9..98aea8bf 100644 --- a/pom.xml +++ b/pom.xml @@ -88,20 +88,12 @@ maven-javadoc-plugin 3.6.2 - - com.spotify.fmt - fmt-maven-plugin - 2.21.1 - - format - - maven-compiler-plugin 3.11.0 - 17 - 17 + 1.8 + 1.8 diff --git a/src/main/java/io/qdrant/client/TokenInterceptor.java b/src/main/java/io/qdrant/client/TokenInterceptor.java index e04a3e68..f735ed42 100644 --- a/src/main/java/io/qdrant/client/TokenInterceptor.java +++ b/src/main/java/io/qdrant/client/TokenInterceptor.java @@ -26,7 +26,7 @@ final class TokenInterceptor implements ClientInterceptor { @Override public ClientCall interceptCall( MethodDescriptor method, CallOptions callOptions, Channel next) { - return new SimpleForwardingClientCall<>(next.newCall(method, callOptions)) { + return new SimpleForwardingClientCall(next.newCall(method, callOptions)) { @Override public void start(Listener responseListener, Metadata headers) { headers.put(API_KEY, apiKey); diff --git a/src/main/java/io/qdrant/client/utils/PointUtil.java b/src/main/java/io/qdrant/client/utils/PointUtil.java index 6e4ac758..30db977d 100644 --- a/src/main/java/io/qdrant/client/utils/PointUtil.java +++ b/src/main/java/io/qdrant/client/utils/PointUtil.java @@ -16,6 +16,8 @@ import java.util.Arrays; import java.util.Map; import java.util.UUID; +import java.util.stream.Collector; +import java.util.stream.Collectors; /** Utility class for working with Points. */ public class PointUtil { @@ -30,7 +32,7 @@ public static PointsSelector createPointsSelector(long... pointIds) { PointsIdsList pointsIdsList = PointsIdsList.newBuilder() - .addAllIds(Arrays.stream(pointIds).mapToObj(PointUtil::pointId).toList()) + .addAllIds(Arrays.stream(pointIds).mapToObj(PointUtil::pointId).collect(Collectors.toList())) .build(); return PointsSelector.newBuilder().setPoints(pointsIdsList).build(); @@ -51,7 +53,7 @@ public static PointsSelector createPointsSelector(String... pointIds) { // Using map() instead PointsIdsList pointsIdsList = PointsIdsList.newBuilder() - .addAllIds(Arrays.stream(pointIds).map((String id) -> PointUtil.pointId(id)).toList()) + .addAllIds(Arrays.stream(pointIds).map((String id) -> PointUtil.pointId(id)).collect(Collectors.toList())) .build(); return PointsSelector.newBuilder().setPoints(pointsIdsList).build(); diff --git a/src/main/java/io/qdrant/client/utils/SelectorUtil.java b/src/main/java/io/qdrant/client/utils/SelectorUtil.java index bc8ad1f3..e2c6c0b1 100644 --- a/src/main/java/io/qdrant/client/utils/SelectorUtil.java +++ b/src/main/java/io/qdrant/client/utils/SelectorUtil.java @@ -8,6 +8,8 @@ import io.qdrant.client.grpc.Points.VectorsSelector; import io.qdrant.client.grpc.Points.WithPayloadSelector; import io.qdrant.client.grpc.Points.WithVectorsSelector; + +import java.util.Arrays; import java.util.List; /** Utility class for working with Selectors. */ @@ -39,7 +41,7 @@ public static WithVectorsSelector withVectors() { */ public static WithPayloadSelector withPayload(String... fields) { PayloadIncludeSelector include = - PayloadIncludeSelector.newBuilder().addAllFields(List.of(fields)).build(); + PayloadIncludeSelector.newBuilder().addAllFields(Arrays.asList(fields)).build(); return WithPayloadSelector.newBuilder().setInclude(include).build(); } @@ -50,7 +52,7 @@ public static WithPayloadSelector withPayload(String... fields) { * @return The created {@link WithVectorsSelector} object. */ public static WithVectorsSelector withVectors(String... vectors) { - VectorsSelector include = VectorsSelector.newBuilder().addAllNames(List.of(vectors)).build(); + VectorsSelector include = VectorsSelector.newBuilder().addAllNames(Arrays.asList(vectors)).build(); return WithVectorsSelector.newBuilder().setInclude(include).build(); } @@ -74,7 +76,7 @@ public static PointsSelector idsSelector(List ids) { */ public static PointsSelector idsSelector(PointId... ids) { return PointsSelector.newBuilder() - .setPoints(PointsIdsList.newBuilder().addAllIds(List.of(ids)).build()) + .setPoints(PointsIdsList.newBuilder().addAllIds(Arrays.asList(ids)).build()) .build(); } diff --git a/src/test/java/io/qdrant/client/QdrantClientPointsTest.java b/src/test/java/io/qdrant/client/QdrantClientPointsTest.java index c8cd5639..410b21db 100644 --- a/src/test/java/io/qdrant/client/QdrantClientPointsTest.java +++ b/src/test/java/io/qdrant/client/QdrantClientPointsTest.java @@ -17,6 +17,7 @@ import io.qdrant.client.utils.SelectorUtil; import io.qdrant.client.utils.VectorUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +59,7 @@ void testPointsWithPayloadFilters() { Points.GetResponse response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null); @@ -79,12 +80,12 @@ void testPointsWithPayloadFilters() { PointUtil.point( pointID, VectorUtil.dummyVector(EMBEDDINGS_SIZE), PayloadUtil.toPayload(data)); - List points = List.of(point); + List points = Arrays.asList(point); qdrantClient.upsertPointsBlocking(collectionName, points, null); response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null); @@ -101,7 +102,7 @@ void testPointsWithPayloadFilters() { response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null); @@ -122,7 +123,7 @@ void testUpsertPoints() { Points.GetResponse response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null); @@ -130,12 +131,12 @@ void testUpsertPoints() { assertEquals(0, response.getResultCount()); PointStruct point = PointUtil.point(pointID, VectorUtil.dummyVector(EMBEDDINGS_SIZE), null); - List points = List.of(point); + List points = Arrays.asList(point); qdrantClient.upsertPointsBlocking(collectionName, points, null); response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null); @@ -146,7 +147,7 @@ void testUpsertPoints() { response = qdrantClient.getPoints( collectionName, - List.of(pointIds), + Arrays.asList(pointIds), SelectorUtil.withVectors(), SelectorUtil.withPayload(), null);