Java library for the Qdrant vector search engine.
Java client library with handy utility methods and overloads for interfacing with Qdrant.
Not yet published.
To install the library, add the following lines to your build config file. Requires JDK 17 or above.
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.0</version>
</dependency>libraryDependencies += "io.qdrant" % "client" % "1.0"implementation 'io.qdrant:client:1.0'Note
The library uses Qdrant's GRPC interface. The default port being 6334.
Uses TLS if the URL protocol is https, plaintext otherwise.
import io.qdrant.client.QdrantClient;
QdrantClient client = new QdrantClient("http://localhost:6334");import io.qdrant.client.QdrantClient;
QdrantClient client = new QdrantClient("https://xyz-eg.eu-central.aws.cloud.qdrant.io:6334", "<your-api-key>");Click to expand example
You can connect to Qdrant by instantiating a QdrantClient instance.
import io.qdrant.client.QdrantClient;
QdrantClient client = new QdrantClient("http://localhost:6334");
System.out.println(client.listCollections());Output:
collections {
name: "Documents"
}
collections {
name: "some_collection"
}
time: 7.04541E-4
The library offers handy utility methods for constructing GRPC structures.
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.qdrant.client.utils.*;
String collectionName = "Documents";
client.recreateCollection(collectionName, 6, Distance.Cosine);
Map<String, Object> map = new HashMap<>();
map.put("name", "John Doe");
map.put("age", 42);
map.put("married", true);
PointStruct point =
PointUtil.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);
client.upsertPoints(collectionName, points, null);import io.qdrant.client.grpc.Points.SearchPoints;
import io.qdrant.client.grpc.Points.SearchResponse;
import io.qdrant.client.utils.*;
Filter filter = FilterUtil.must(FilterUtil.fieldCondition("age", FilterUtil.match(42)));
SearchPoints request = SearchPoints.newBuilder()
.setCollectionName(collectionName)
.addAllVector(List.of(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);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
Apache 2.0 © 2023
