Skip to content

Commit

Permalink
Support Java 8 πŸŽ‰ (#2)
Browse files Browse the repository at this point in the history
* Support Java 8 πŸŽ‰

* ci: Distribution to temurin

* docs: README example update

* ci: build for other Java versions

* ci: multiple java versions cd.yml

* ci: Add Java 21 to matrix
  • Loading branch information
Anush008 authored Dec 5, 2023
1 parent 07c2a6c commit 5c18145
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 59 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
shell: bash
45 changes: 16 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<dependency>
Expand Down Expand Up @@ -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;
Expand All @@ -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<PointStruct> points = List.of(point);
List<PointStruct> 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;

Expand All @@ -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}
```

</details>
Expand Down
12 changes: 2 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,12 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.2</version>
</plugin>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<goals>
<goal>format</goal>
</goals>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/qdrant/client/TokenInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class TokenInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<>(next.newCall(method, callOptions)) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(API_KEY, apiKey);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/qdrant/client/utils/PointUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/qdrant/client/utils/SelectorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -74,7 +76,7 @@ public static PointsSelector idsSelector(List<PointId> 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();
}

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/io/qdrant/client/QdrantClientPointsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,7 +59,7 @@ void testPointsWithPayloadFilters() {
Points.GetResponse response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);
Expand All @@ -79,12 +80,12 @@ void testPointsWithPayloadFilters() {
PointUtil.point(
pointID, VectorUtil.dummyVector(EMBEDDINGS_SIZE), PayloadUtil.toPayload(data));

List<PointStruct> points = List.of(point);
List<PointStruct> points = Arrays.asList(point);
qdrantClient.upsertPointsBlocking(collectionName, points, null);
response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);
Expand All @@ -101,7 +102,7 @@ void testPointsWithPayloadFilters() {
response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);
Expand All @@ -122,20 +123,20 @@ void testUpsertPoints() {
Points.GetResponse response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);

assertEquals(0, response.getResultCount());

PointStruct point = PointUtil.point(pointID, VectorUtil.dummyVector(EMBEDDINGS_SIZE), null);
List<PointStruct> points = List.of(point);
List<PointStruct> points = Arrays.asList(point);
qdrantClient.upsertPointsBlocking(collectionName, points, null);
response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);
Expand All @@ -146,7 +147,7 @@ void testUpsertPoints() {
response =
qdrantClient.getPoints(
collectionName,
List.of(pointIds),
Arrays.asList(pointIds),
SelectorUtil.withVectors(),
SelectorUtil.withPayload(),
null);
Expand Down

0 comments on commit 5c18145

Please sign in to comment.