Skip to content

Latest commit

History

85 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Qdrant Java Client

This project contains a java client for the Qdrant vector database. The client supports HTTP and gRPC transport in either blocking or non-blocking fashion. For async operation a Future or RxJava3 based API can be used.


testingSonarCloud VulnerabilitiesCode CoverageLicenseLatest releaseQuality Gate Status

Maven

<dependency>
<groupId>io.metaloom.qdrant</groupId>
<artifactId>qdrant-java-grpc-client</artifactId>
<version>0.13.0</version>
</dependency>

or for the HTTP client

<dependency>
<groupId>io.metaloom.qdrant</groupId>
<artifactId>qdrant-java-http-client</artifactId>
<version>0.13.0</version>
</dependency>

NOTE: The http client currently (as of v1.2.0 of Qdrant) supports more methods compared to the gRPC client.

Notes / Status

This client was build and tested for Qdrant server version v1.2.0. Minimum required JRE is current LTS version 17.

Usage - gRPC

intport = qdrant.grpcPort(); // Default: 6334Stringhost = qdrant.getHost();
try (QDrantGRPCClientclient = QDrantGRPCClient.builder()
.setHostname(host)
.setPort(port)
.build()) {
// Define the collection to store vectorsVectorParamsparams = VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Euclid)
.build();
// Add the params to a mapVectorParamsMapparamsMap = VectorParamsMap.newBuilder()
.putMap("firstVector", params)
.putMap("secondVector", params)
.build();
// Create new collections - blockingclient.createCollection("test1", paramsMap).sync();
// .. or via Future APIclient.createCollection("test2", params).async().get();
// .. or via RxJava APIclient.createCollection("test3", params).rx().blockingGet();
// Insert a new vectorsfor (inti = 0; i < 10; i++) {
// Vector of the pointfloat[] vector = newfloat[] { 0.43f + i, 0.1f, 0.61f, 1.45f - i };
// Payload of the pointMap<String, Value> payload = newHashMap<>();
payload.put("color", ModelHelper.value("blue"));
// Now construct the pointPointStructpoint = ModelHelper.namedPoint(42L + i, "firstVector", vector, payload);
// .. and insert itclient.upsertPoint("test1", point, true).sync();
}
// Count pointslongnPoints = client.countPoints("test1", null, true).sync().getResult().getCount();
// Now run KNN searchfloat[] searchVector = newfloat[] { 0.43f, 0.09f, 0.41f, 1.35f };
List<ScoredPoint> searchResults = client.searchPoints("test1", "firstVector", searchVector, 2, null).sync().getResultList();
for (ScoredPointresult : searchResults) {
System.out.println("Found: [" + result.getId().getNum() + "] " + result.getScore());
}
// Invoke backup via Snapshot APIclient.createSnapshot("test1").sync();
}

Usage - HTTP

intport = qdrant.httpPort();
Stringhost = qdrant.getHost();
try (QDrantHttpClientclient = QDrantHttpClient.builder()
.setHostname(host)
.setPort(port)
.build()) {
// Create a collectionCollectionCreateRequestreq = newCollectionCreateRequest();
req.setVectors("colors", 4, Distance.EUCLID);
client.createCollection("the-collection-name", req).sync();
// Now add some pointsPointStructp1 = PointStruct.of("colors", 0.42f, 0.33f, 42.15f, 68.72f)
.setPayload("{\"name\": \"first\"}")
.setId(1);
PointStructp2 = PointStruct.of("colors", 0.76f, 0.43f, 63.45f, 22.10f)
.setPayload("{ \"color\": \"red\"}")
.setId(2);
PointStructp3 = PointStruct.of("colors", 0.41f, 0.32f, 42.11f, 68.71f).setId(3);
PointStructp4 = PointStruct.of("colors", 0.12f, 0.23f, 12.46f, 47.17f).setId(4);
PointsListUpsertRequestpointsRequest = newPointsListUpsertRequest();
pointsRequest.setPoints(p1, p2, p3, p4);
client.upsertPoints("the-collection-name", pointsRequest, false).async().blockingGet();
// List the collectionsclient.listCollections().async().blockingGet();
// Count the points in the collectionclient.countPoints("the-collection-name", newPointCountRequest().setExact(true)).sync();
}

Release Process

# Bump qdrant.version in pom.xml and QDrantContainer#DEFAULT_VERSION# Update maven version to next release
mvn versions:set -DgenerateBackupPoms=false
# Now run tests locally or via GitHub actions
mvn clean package
# Deploy to maven central and auto-close staging repo. # Adding the property will trigger the profiles in the parent pom to include gpg,javadoc...
mvn clean deploy -Drelease

About

HTTP and gRPC Java Client for qdrant vector database

Resources

Stars

53 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages