Date: Tue, 16 Jul 2024 15:07:30 +0530
Subject: [PATCH 12/45] style: Configure Spotless formatter (#45)
---
README.md | 14 +-
build.gradle | 14 +
gradle.properties | 5 +-
.../io/qdrant/client/ApiKeyCredentials.java | 48 +-
.../io/qdrant/client/ConditionFactory.java | 691 +-
.../java/io/qdrant/client/PointIdFactory.java | 44 +-
.../java/io/qdrant/client/QdrantClient.java | 5801 ++++++++---------
.../io/qdrant/client/QdrantException.java | 19 +-
.../io/qdrant/client/QdrantGrpcClient.java | 431 +-
.../java/io/qdrant/client/QueryFactory.java | 332 +-
.../io/qdrant/client/ShardKeyFactory.java | 43 +-
.../client/ShardKeySelectorFactory.java | 76 +-
.../io/qdrant/client/StartFromFactory.java | 113 +-
.../io/qdrant/client/TargetVectorFactory.java | 43 +-
.../java/io/qdrant/client/ValueFactory.java | 114 +-
.../java/io/qdrant/client/VectorFactory.java | 139 +-
.../io/qdrant/client/VectorInputFactory.java | 212 +-
.../java/io/qdrant/client/VectorsFactory.java | 98 +-
.../client/WithPayloadSelectorFactory.java | 69 +-
.../client/WithVectorsSelectorFactory.java | 48 +-
.../java/io/qdrant/client/package-info.java | 6 +-
.../java/io/qdrant/client/ApiKeyTest.java | 92 +-
.../io/qdrant/client/CollectionsTest.java | 487 +-
.../java/io/qdrant/client/DockerImage.java | 2 +-
.../java/io/qdrant/client/HealthTest.java | 66 +-
.../java/io/qdrant/client/PointsTest.java | 1507 +++--
.../io/qdrant/client/QdrantClientTest.java | 42 +-
.../qdrant/client/QdrantGrpcClientTest.java | 66 +-
.../java/io/qdrant/client/SnapshotsTest.java | 273 +-
.../java/io/qdrant/client/package-info.java | 2 +-
30 files changed, 5409 insertions(+), 5488 deletions(-)
diff --git a/README.md b/README.md
index 73c53b9d..d3f5bbc9 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-
+
@@ -34,22 +34,25 @@ To install the library, add the following lines to your build config file.
io.qdrant
client
- 1.9.0
+ 1.10.0
```
#### SBT
```sbt
-libraryDependencies += "io.qdrant" % "client" % "1.9.0"
+libraryDependencies += "io.qdrant" % "client" % "1.10.0"
```
#### Gradle
```gradle
-implementation 'io.qdrant:client:1.9.0'
+implementation 'io.qdrant:client:1.10.0'
```
+> [!NOTE]
+> Please make sure to include all necessary dependencies listed [here](https://central.sonatype.com/artifact/io.qdrant/client/dependencies) in your project.
+
## 📖 Documentation
- [JavaDoc Reference](https://qdrant.github.io/java-client/)
@@ -65,7 +68,8 @@ A client can be instantiated with
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost").build());
```
-which creates a client that will connect to Qdrant on https://localhost:6334.
+
+which creates a client that will connect to Qdrant on .
Internally, the high level client uses a low level gRPC client to interact with
Qdrant. Additional constructor overloads provide more control over how the gRPC
diff --git a/build.gradle b/build.gradle
index edabb70b..951377ad 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,6 +21,7 @@ plugins {
id 'com.google.protobuf' version '0.9.4'
id 'net.ltgt.errorprone' version '3.1.0'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
+ id 'com.diffplug.spotless' version '6.22.0'
}
group = 'io.qdrant'
@@ -250,3 +251,16 @@ signing {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign publishing.publications.mavenJava
}
+
+spotless {
+ java {
+ target 'src/*/java/**/*.java'
+ importOrder()
+ removeUnusedImports()
+ cleanthat()
+ googleJavaFormat()
+ formatAnnotations()
+ }
+}
+
+compileJava.dependsOn 'spotlessApply'
diff --git a/gradle.properties b/gradle.properties
index 81268729..2abb78d3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -5,4 +5,7 @@ qdrantProtosVersion=v1.10.0
qdrantVersion=v1.10.0
# The version of the client to generate
-packageVersion=1.10.0
\ No newline at end of file
+packageVersion=1.10.0
+
+## Extension of the default memory config for the spotless formatter plugin
+org.gradle.jvmargs= -Xmx2000m "-XX:MaxMetaspaceSize=1000m"
diff --git a/src/main/java/io/qdrant/client/ApiKeyCredentials.java b/src/main/java/io/qdrant/client/ApiKeyCredentials.java
index 8ab6c202..ab3c5d0c 100644
--- a/src/main/java/io/qdrant/client/ApiKeyCredentials.java
+++ b/src/main/java/io/qdrant/client/ApiKeyCredentials.java
@@ -1,35 +1,35 @@
package io.qdrant.client;
-import java.util.concurrent.Executor;
-
import io.grpc.CallCredentials;
import io.grpc.Metadata;
import io.grpc.Status;
+import java.util.concurrent.Executor;
-/**
- * API key authentication credentials
- */
+/** API key authentication credentials */
public class ApiKeyCredentials extends CallCredentials {
- private final String apiKey;
+ private final String apiKey;
- /**
- * Instantiates a new instance of {@link ApiKeyCredentials}
- * @param apiKey The API key to use for authentication
- */
- public ApiKeyCredentials(String apiKey) {
- this.apiKey = apiKey;
- }
+ /**
+ * Instantiates a new instance of {@link ApiKeyCredentials}
+ *
+ * @param apiKey The API key to use for authentication
+ */
+ public ApiKeyCredentials(String apiKey) {
+ this.apiKey = apiKey;
+ }
- @Override
- public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) {
- appExecutor.execute(() -> {
- try {
- Metadata headers = new Metadata();
- headers.put(Metadata.Key.of("api-key", Metadata.ASCII_STRING_MARSHALLER), apiKey);
- applier.apply(headers);
- } catch (Throwable e) {
- applier.fail(Status.UNAUTHENTICATED.withCause(e));
- }
+ @Override
+ public void applyRequestMetadata(
+ RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) {
+ appExecutor.execute(
+ () -> {
+ try {
+ Metadata headers = new Metadata();
+ headers.put(Metadata.Key.of("api-key", Metadata.ASCII_STRING_MARSHALLER), apiKey);
+ applier.apply(headers);
+ } catch (Throwable e) {
+ applier.fail(Status.UNAUTHENTICATED.withCause(e));
+ }
});
- }
+ }
}
diff --git a/src/main/java/io/qdrant/client/ConditionFactory.java b/src/main/java/io/qdrant/client/ConditionFactory.java
index bcc991b4..032bccf8 100644
--- a/src/main/java/io/qdrant/client/ConditionFactory.java
+++ b/src/main/java/io/qdrant/client/ConditionFactory.java
@@ -1,7 +1,5 @@
package io.qdrant.client;
-import java.util.List;
-
import io.qdrant.client.grpc.Points.Condition;
import io.qdrant.client.grpc.Points.DatetimeRange;
import io.qdrant.client.grpc.Points.FieldCondition;
@@ -21,371 +19,376 @@
import io.qdrant.client.grpc.Points.RepeatedIntegers;
import io.qdrant.client.grpc.Points.RepeatedStrings;
import io.qdrant.client.grpc.Points.ValuesCount;
+import java.util.List;
-/**
- * Convenience methods for constructing {@link Condition}
- */
+/** Convenience methods for constructing {@link Condition} */
public final class ConditionFactory {
- private ConditionFactory() {
- }
+ private ConditionFactory() {}
- /**
- * Match all records with the provided id
- * @param id The id to match
- * @return a new instance of {@link Condition}
- */
- public static Condition hasId(PointId id) {
- return Condition.newBuilder()
- .setHasId(HasIdCondition.newBuilder()
- .addHasId(id)
- .build())
- .build();
- }
+ /**
+ * Match all records with the provided id
+ *
+ * @param id The id to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition hasId(PointId id) {
+ return Condition.newBuilder()
+ .setHasId(HasIdCondition.newBuilder().addHasId(id).build())
+ .build();
+ }
- /**
- * Match all records with the provided ids
- * @param ids The ids to match
- * @return a new instance of {@link Condition}
- */
- public static Condition hasId(List ids) {
- return Condition.newBuilder()
- .setHasId(HasIdCondition.newBuilder()
- .addAllHasId(ids)
- .build())
- .build();
- }
+ /**
+ * Match all records with the provided ids
+ *
+ * @param ids The ids to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition hasId(List ids) {
+ return Condition.newBuilder()
+ .setHasId(HasIdCondition.newBuilder().addAllHasId(ids).build())
+ .build();
+ }
- /**
- * Match all records where the given field either does not exist, or has null or empty value.
- * @param field The name of the field
- * @return a new instance of {@link Condition}
- */
- public static Condition isEmpty(String field) {
- return Condition.newBuilder()
- .setIsEmpty(IsEmptyCondition.newBuilder()
- .setKey(field)
- .build())
- .build();
- }
+ /**
+ * Match all records where the given field either does not exist, or has null or empty value.
+ *
+ * @param field The name of the field
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition isEmpty(String field) {
+ return Condition.newBuilder()
+ .setIsEmpty(IsEmptyCondition.newBuilder().setKey(field).build())
+ .build();
+ }
- /**
- * Match all records where the given field is null.
- * @param field The name of the field
- * @return a new instance of {@link Condition}
- */
- public static Condition isNull(String field) {
- return Condition.newBuilder()
- .setIsNull(IsNullCondition.newBuilder()
- .setKey(field)
- .build())
- .build();
- }
+ /**
+ * Match all records where the given field is null.
+ *
+ * @param field The name of the field
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition isNull(String field) {
+ return Condition.newBuilder()
+ .setIsNull(IsNullCondition.newBuilder().setKey(field).build())
+ .build();
+ }
- /**
- * Match records where the given field matches the given keyword
- * @param field The name of the field
- * @param keyword The keyword to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchKeyword(String field, String keyword) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setKeyword(keyword)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches the given keyword
+ *
+ * @param field The name of the field
+ * @param keyword The keyword to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchKeyword(String field, String keyword) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(Match.newBuilder().setKeyword(keyword).build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field matches the given text.
- * @param field The name of the field
- * @param text The text to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchText(String field, String text) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setText(text)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches the given text.
+ *
+ * @param field The name of the field
+ * @param text The text to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchText(String field, String text) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(Match.newBuilder().setText(text).build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field matches the given boolean value.
- * @param field The name of the field
- * @param value The value to match
- * @return a new instance of {@link Condition}
- */
- public static Condition match(String field, boolean value) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setBoolean(value)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches the given boolean value.
+ *
+ * @param field The name of the field
+ * @param value The value to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition match(String field, boolean value) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(Match.newBuilder().setBoolean(value).build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field matches the given long value.
- * @param field The name of the field
- * @param value The value to match
- * @return a new instance of {@link Condition}
- */
- public static Condition match(String field, long value) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setInteger(value)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches the given long value.
+ *
+ * @param field The name of the field
+ * @param value The value to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition match(String field, long value) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(Match.newBuilder().setInteger(value).build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field matches any of the given keywords.
- * @param field The name of the field
- * @param keywords The keywords to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchKeywords(String field, List keywords) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setKeywords(RepeatedStrings.newBuilder().addAllStrings(keywords).build())
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches any of the given keywords.
+ *
+ * @param field The name of the field
+ * @param keywords The keywords to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchKeywords(String field, List keywords) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(
+ Match.newBuilder()
+ .setKeywords(RepeatedStrings.newBuilder().addAllStrings(keywords).build())
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field matches any of the given values.
- * @param field The name of the field
- * @param values The values to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchValues(String field, List values) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setIntegers(RepeatedIntegers.newBuilder().addAllIntegers(values).build())
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches any of the given values.
+ *
+ * @param field The name of the field
+ * @param values The values to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchValues(String field, List values) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(
+ Match.newBuilder()
+ .setIntegers(RepeatedIntegers.newBuilder().addAllIntegers(values).build())
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field does not match any of the given keywords.
- * @param field The name of the field
- * @param keywords The keywords not to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchExceptKeywords(String field, List keywords) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setExceptKeywords(RepeatedStrings.newBuilder().addAllStrings(keywords).build())
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field does not match any of the given keywords.
+ *
+ * @param field The name of the field
+ * @param keywords The keywords not to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchExceptKeywords(String field, List keywords) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(
+ Match.newBuilder()
+ .setExceptKeywords(
+ RepeatedStrings.newBuilder().addAllStrings(keywords).build())
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field does not match any of the given values.
- * @param field The name of the field
- * @param values The values not to match
- * @return a new instance of {@link Condition}
- */
- public static Condition matchExceptValues(String field, List values) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setMatch(Match.newBuilder()
- .setExceptIntegers(RepeatedIntegers.newBuilder().addAllIntegers(values).build())
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field does not match any of the given values.
+ *
+ * @param field The name of the field
+ * @param values The values not to match
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition matchExceptValues(String field, List values) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setMatch(
+ Match.newBuilder()
+ .setExceptIntegers(
+ RepeatedIntegers.newBuilder().addAllIntegers(values).build())
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given nested field matches the given condition.
- * @param field The name of the nested field.
- * @param condition The condition to match.
- * @return a new instance of {@link Condition}
- */
- public static Condition nested(String field, Condition condition) {
- return Condition.newBuilder()
- .setNested(NestedCondition.newBuilder()
- .setKey(field)
- .setFilter(Filter.newBuilder()
- .addMust(condition)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given nested field matches the given condition.
+ *
+ * @param field The name of the nested field.
+ * @param condition The condition to match.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition nested(String field, Condition condition) {
+ return Condition.newBuilder()
+ .setNested(
+ NestedCondition.newBuilder()
+ .setKey(field)
+ .setFilter(Filter.newBuilder().addMust(condition).build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given nested field matches the given filter.
- * @param field The name of the nested field.
- * @param filter The filter to match.
- * @return a new instance of {@link Condition}
- */
- public static Condition nested(String field, Filter filter) {
- return Condition.newBuilder()
- .setNested(NestedCondition.newBuilder()
- .setKey(field)
- .setFilter(filter))
- .build();
- }
+ /**
+ * Match records where the given nested field matches the given filter.
+ *
+ * @param field The name of the nested field.
+ * @param filter The filter to match.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition nested(String field, Filter filter) {
+ return Condition.newBuilder()
+ .setNested(NestedCondition.newBuilder().setKey(field).setFilter(filter))
+ .build();
+ }
- /**
- * Match records where the given field matches the given range.
- * @param field The name of the nested field.
- * @param range The range to match.
- * @return a new instance of {@link Condition}
- */
- public static Condition range(String field, Range range) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setRange(range)
- .build())
- .build();
- }
+ /**
+ * Match records where the given field matches the given range.
+ *
+ * @param field The name of the nested field.
+ * @param range The range to match.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition range(String field, Range range) {
+ return Condition.newBuilder()
+ .setField(FieldCondition.newBuilder().setKey(field).setRange(range).build())
+ .build();
+ }
- /**
- * Match records where the given field has values inside a circle centred at a given latitude and longitude
- * with a given radius.
- * @param field The name of the field.
- * @param latitude The latitude of the center.
- * @param longitude The longitude of the center.
- * @param radius The radius in meters.
- * @return a new instance of {@link Condition}
- */
- public static Condition geoRadius(String field, double latitude, double longitude, float radius) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setGeoRadius(GeoRadius.newBuilder()
- .setCenter(GeoPoint.newBuilder()
- .setLat(latitude)
- .setLon(longitude)
- .build())
- .setRadius(radius)
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field has values inside a circle centred at a given latitude and
+ * longitude with a given radius.
+ *
+ * @param field The name of the field.
+ * @param latitude The latitude of the center.
+ * @param longitude The longitude of the center.
+ * @param radius The radius in meters.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition geoRadius(String field, double latitude, double longitude, float radius) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setGeoRadius(
+ GeoRadius.newBuilder()
+ .setCenter(GeoPoint.newBuilder().setLat(latitude).setLon(longitude).build())
+ .setRadius(radius)
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Match records where the given field has values inside a bounding box specified by the top left and
- * bottom right coordinates.
- * @param field The name of the field.
- * @param topLeftLatitude The latitude of the top left point.
- * @param topLeftLongitude The longitude of the top left point.
- * @param bottomRightLatitude The latitude of the bottom right point.
- * @param bottomRightLongitude The longitude of the bottom right point.
- * @return a new instance of {@link Condition}
- */
- public static Condition geoBoundingBox(
- String field,
- double topLeftLatitude,
- double topLeftLongitude,
- double bottomRightLatitude,
- double bottomRightLongitude) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setGeoBoundingBox(GeoBoundingBox.newBuilder()
- .setTopLeft(GeoPoint.newBuilder()
- .setLat(topLeftLatitude)
- .setLon(topLeftLongitude)
- .build())
- .setBottomRight(GeoPoint.newBuilder()
- .setLat(bottomRightLatitude)
- .setLon(bottomRightLongitude)
- .build())
- .build())
- .build())
- .build();
- }
+ /**
+ * Match records where the given field has values inside a bounding box specified by the top left
+ * and bottom right coordinates.
+ *
+ * @param field The name of the field.
+ * @param topLeftLatitude The latitude of the top left point.
+ * @param topLeftLongitude The longitude of the top left point.
+ * @param bottomRightLatitude The latitude of the bottom right point.
+ * @param bottomRightLongitude The longitude of the bottom right point.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition geoBoundingBox(
+ String field,
+ double topLeftLatitude,
+ double topLeftLongitude,
+ double bottomRightLatitude,
+ double bottomRightLongitude) {
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setGeoBoundingBox(
+ GeoBoundingBox.newBuilder()
+ .setTopLeft(
+ GeoPoint.newBuilder()
+ .setLat(topLeftLatitude)
+ .setLon(topLeftLongitude)
+ .build())
+ .setBottomRight(
+ GeoPoint.newBuilder()
+ .setLat(bottomRightLatitude)
+ .setLon(bottomRightLongitude)
+ .build())
+ .build())
+ .build())
+ .build();
+ }
- /**
- * Matches records where the given field has values inside the provided polygon. A polygon always has an exterior
- * ring and may optionally have interior rings, which represent independent areas or holes.
- * When defining a ring, you must pick either a clockwise or counterclockwise ordering for your points.
- * The first and last point of the polygon must be the same.
- * @param field The name of the field.
- * @param exterior The exterior ring of the polygon.
- * @param interiors The interior rings of the polygon.
- * @return a new instance of {@link Condition}
- */
- public static Condition geoPolygon(String field, GeoLineString exterior, List interiors) {
- GeoPolygon.Builder geoPolygonBuilder = GeoPolygon.newBuilder()
- .setExterior(exterior);
+ /**
+ * Matches records where the given field has values inside the provided polygon. A polygon always
+ * has an exterior ring and may optionally have interior rings, which represent independent areas
+ * or holes. When defining a ring, you must pick either a clockwise or counterclockwise ordering
+ * for your points. The first and last point of the polygon must be the same.
+ *
+ * @param field The name of the field.
+ * @param exterior The exterior ring of the polygon.
+ * @param interiors The interior rings of the polygon.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition geoPolygon(
+ String field, GeoLineString exterior, List interiors) {
+ GeoPolygon.Builder geoPolygonBuilder = GeoPolygon.newBuilder().setExterior(exterior);
- if (!interiors.isEmpty()) {
- geoPolygonBuilder.addAllInteriors(interiors);
- }
+ if (!interiors.isEmpty()) {
+ geoPolygonBuilder.addAllInteriors(interiors);
+ }
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setGeoPolygon(geoPolygonBuilder.build())
- .build())
- .build();
- }
+ return Condition.newBuilder()
+ .setField(
+ FieldCondition.newBuilder()
+ .setKey(field)
+ .setGeoPolygon(geoPolygonBuilder.build())
+ .build())
+ .build();
+ }
- /**
- * Matches records where the given field has a count of values within the specified count range
- * @param field The name of the field.
- * @param valuesCount The count range to match.
- * @return a new instance of {@link Condition}
- */
- public static Condition valuesCount(String field, ValuesCount valuesCount) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setValuesCount(valuesCount)
- .build())
- .build();
- }
+ /**
+ * Matches records where the given field has a count of values within the specified count range
+ *
+ * @param field The name of the field.
+ * @param valuesCount The count range to match.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition valuesCount(String field, ValuesCount valuesCount) {
+ return Condition.newBuilder()
+ .setField(FieldCondition.newBuilder().setKey(field).setValuesCount(valuesCount).build())
+ .build();
+ }
- /**
- * Nests a filter
- * @param filter The filter to nest.
- * @return a new instance of {@link Condition}
- */
- public static Condition filter(Filter filter) {
- return Condition.newBuilder()
- .setFilter(filter)
- .build();
- }
+ /**
+ * Nests a filter
+ *
+ * @param filter The filter to nest.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition filter(Filter filter) {
+ return Condition.newBuilder().setFilter(filter).build();
+ }
- /**
- * Matches records where the given field has a datetime value within the
- * specified range
- *
- * @param field The name of the field.
- * @param datetimeRange The datetime range to match.
- * @return a new instance of {@link Condition}
- */
- public static Condition datetimeRange(String field, DatetimeRange datetimeRange) {
- return Condition.newBuilder()
- .setField(FieldCondition.newBuilder()
- .setKey(field)
- .setDatetimeRange(datetimeRange)
- .build())
- .build();
- }
+ /**
+ * Matches records where the given field has a datetime value within the specified range
+ *
+ * @param field The name of the field.
+ * @param datetimeRange The datetime range to match.
+ * @return a new instance of {@link Condition}
+ */
+ public static Condition datetimeRange(String field, DatetimeRange datetimeRange) {
+ return Condition.newBuilder()
+ .setField(FieldCondition.newBuilder().setKey(field).setDatetimeRange(datetimeRange).build())
+ .build();
+ }
}
diff --git a/src/main/java/io/qdrant/client/PointIdFactory.java b/src/main/java/io/qdrant/client/PointIdFactory.java
index ec1015ca..35844562 100644
--- a/src/main/java/io/qdrant/client/PointIdFactory.java
+++ b/src/main/java/io/qdrant/client/PointIdFactory.java
@@ -1,31 +1,29 @@
package io.qdrant.client;
-import java.util.UUID;
-
import io.qdrant.client.grpc.Points.PointId;
+import java.util.UUID;
-/**
- * Convenience methods for constructing {@link PointId}
- */
+/** Convenience methods for constructing {@link PointId} */
public final class PointIdFactory {
- private PointIdFactory() {
- }
+ private PointIdFactory() {}
- /**
- * Creates a point id from a {@link long}
- * @param id The id
- * @return a new instance of {@link PointId}
- */
- public static PointId id(long id) {
- return PointId.newBuilder().setNum(id).build();
- }
+ /**
+ * Creates a point id from a {@link long}
+ *
+ * @param id The id
+ * @return a new instance of {@link PointId}
+ */
+ public static PointId id(long id) {
+ return PointId.newBuilder().setNum(id).build();
+ }
- /**
- * Creates a point id from a {@link UUID}
- * @param id The id
- * @return a new instance of {@link PointId}
- */
- public static PointId id(UUID id) {
- return PointId.newBuilder().setUuid(id.toString()).build();
- }
+ /**
+ * Creates a point id from a {@link UUID}
+ *
+ * @param id The id
+ * @return a new instance of {@link PointId}
+ */
+ public static PointId id(UUID id) {
+ return PointId.newBuilder().setUuid(id.toString()).build();
+ }
}
diff --git a/src/main/java/io/qdrant/client/QdrantClient.java b/src/main/java/io/qdrant/client/QdrantClient.java
index e71dea09..d03a8f88 100644
--- a/src/main/java/io/qdrant/client/QdrantClient.java
+++ b/src/main/java/io/qdrant/client/QdrantClient.java
@@ -1,16 +1,5 @@
package io.qdrant.client;
-import java.time.Duration;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-import javax.annotation.Nullable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -18,7 +7,6 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-
import io.qdrant.client.grpc.Collections.AliasDescription;
import io.qdrant.client.grpc.Collections.AliasOperations;
import io.qdrant.client.grpc.Collections.ChangeAliases;
@@ -124,2925 +112,2876 @@
import io.qdrant.client.grpc.SnapshotsService.ListSnapshotsRequest;
import io.qdrant.client.grpc.SnapshotsService.ListSnapshotsResponse;
import io.qdrant.client.grpc.SnapshotsService.SnapshotDescription;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-/**
- * Client for the Qdrant vector database.
- */
+/** Client for the Qdrant vector database. */
public class QdrantClient implements AutoCloseable {
- private static final Logger logger = LoggerFactory.getLogger(QdrantClient.class);
- private final QdrantGrpcClient grpcClient;
-
- /**
- * Creates a new instance of {@link QdrantClient}
- *
- * @param grpcClient The low-level gRPC client to use.
- */
- public QdrantClient(QdrantGrpcClient grpcClient) {
- this.grpcClient = grpcClient;
- }
-
- /**
- * Gets the low-level gRPC client. This is exposed to
- *
- * - Allow access to the underlying gRPC channel
- * - Allow access to the gRPC client to make requests using the low-level gRPC client in cases
- * where functionality may not yet be exposed by the higher level client.
- *
- * @return The low-level gRPC client
- */
- public QdrantGrpcClient grpcClient() {
- return grpcClient;
- }
-
- /**
- * Gets detailed information about the qdrant cluster.
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture healthCheckAsync() {
- return healthCheckAsync(null);
- }
-
- /**
- * Gets detailed information about the qdrant cluster.
- *
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture healthCheckAsync(@Nullable Duration timeout) {
- QdrantFutureStub qdrant = timeout != null
- ? this.grpcClient.qdrant().withDeadlineAfter(timeout.toMillis(), TimeUnit.MILLISECONDS)
- : this.grpcClient.qdrant();
- return qdrant.healthCheck(HealthCheckRequest.getDefaultInstance());
- }
-
- //region Collections
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param collectionName The name of the collection.
- * @param vectorParams The vector parameters
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(
- String collectionName,
- VectorParams vectorParams) {
- return createCollectionAsync(collectionName, vectorParams, null);
- }
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param collectionName The name of the collection.
- * @param vectorParams The vector parameters
- * @param timeout The timeout for the call
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(
- String collectionName,
- VectorParams vectorParams,
- @Nullable Duration timeout) {
- return createCollectionAsync(CreateCollection.newBuilder()
- .setCollectionName(collectionName)
- .setVectorsConfig(VectorsConfig.newBuilder()
- .setParams(vectorParams)
- .build())
- .build(),
- timeout);
- }
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param collectionName The name of the collection.
- * @param namedVectorParams The named vector parameters
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(
- String collectionName,
- Map namedVectorParams) {
- return createCollectionAsync(collectionName, namedVectorParams, null);
- }
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param collectionName The name of the collection.
- * @param namedVectorParams The named vector parameters
- * @param timeout The timeout for the call
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(
- String collectionName,
- Map namedVectorParams,
- @Nullable Duration timeout) {
- return createCollectionAsync(CreateCollection.newBuilder()
- .setCollectionName(collectionName)
- .setVectorsConfig(VectorsConfig.newBuilder()
- .setParamsMap(VectorParamsMap.newBuilder().putAllMap(namedVectorParams).build())
- .build())
- .build(),
- timeout);
- }
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param createCollection The collection creation parameters
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(CreateCollection createCollection) {
- return createCollectionAsync(createCollection, null);
- }
-
- /**
- * Creates a new collection with the given parameters
- *
- * @param createCollection The collection creation parameters
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createCollectionAsync(CreateCollection createCollection, @Nullable Duration timeout) {
- String collectionName = createCollection.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Create collection '{}'", collectionName);
- ListenableFuture future = getCollections(timeout).create(createCollection);
- addLogFailureCallback(future, "Create collection");
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Collection '{}' could not be created", collectionName);
- throw new QdrantException("Collection '" + collectionName + "' could not be created");
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param collectionName The name of the collection.
- * @param vectorParams The vector parameters
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture recreateCollectionAsync(
- String collectionName,
- VectorParams vectorParams) {
- return recreateCollectionAsync(collectionName, vectorParams, null);
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param collectionName The name of the collection.
- * @param vectorParams The vector parameters
- * @param timeout The timeout for the call
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture recreateCollectionAsync(
- String collectionName,
- VectorParams vectorParams,
- @Nullable Duration timeout) {
- return recreateCollectionAsync(CreateCollection.newBuilder()
- .setCollectionName(collectionName)
- .setVectorsConfig(VectorsConfig.newBuilder()
- .setParams(vectorParams)
- .build())
- .build(),
- timeout);
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param collectionName The name of the collection.
- * @param namedVectorParams The named vector parameters
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture recreateCollectionAsync(
- String collectionName,
- Map namedVectorParams) {
- return recreateCollectionAsync(collectionName, namedVectorParams, null);
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param collectionName The name of the collection.
- * @param namedVectorParams The named vector parameters
- * @param timeout The timeout for the call
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture recreateCollectionAsync(
- String collectionName,
- Map namedVectorParams,
- @Nullable Duration timeout) {
- return recreateCollectionAsync(CreateCollection.newBuilder()
- .setCollectionName(collectionName)
- .setVectorsConfig(VectorsConfig.newBuilder()
- .setParamsMap(VectorParamsMap.newBuilder().putAllMap(namedVectorParams).build())
- .build())
- .build(),
- timeout);
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param createCollection The collection creation parameters
- * @return a new instance of {@link CollectionOperationResponse}
- */
- public ListenableFuture recreateCollectionAsync(CreateCollection createCollection) {
- return recreateCollectionAsync(createCollection, null);
- }
-
- /**
- * Deletes a collection if one exists, and creates a new collection with the given parameters.
- *
- * @param createCollection The collection creation parameters
- * @param timeout The timeout for the call.
- * @return a new instance of {@link CollectionOperationResponse}
- */
- public ListenableFuture recreateCollectionAsync(CreateCollection createCollection, @Nullable Duration timeout) {
- return Futures.transformAsync(
- deleteCollectionAsync(createCollection.getCollectionName(), timeout),
- input -> createCollectionAsync(createCollection, timeout),
- MoreExecutors.directExecutor());
- }
-
- /**
- * Gets detailed information about an existing collection.
- *
- * @param collectionName The name of the collection.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture getCollectionInfoAsync(String collectionName) {
- return getCollectionInfoAsync(collectionName, null);
- }
-
- /**
- * Gets detailed information about an existing collection.
- *
- * @param collectionName The name of the collection.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture getCollectionInfoAsync(String collectionName, @Nullable Duration timeout) {
- logger.debug("Get collection info for '{}'", collectionName);
- GetCollectionInfoRequest request = GetCollectionInfoRequest.newBuilder()
- .setCollectionName(collectionName)
- .build();
- ListenableFuture future = getCollections(timeout).get(request);
- addLogFailureCallback(future, "Get collection info");
- return Futures.transform(future, GetCollectionInfoResponse::getResult, MoreExecutors.directExecutor());
- }
-
- /**
- * Deletes a collection and all its associated data.
- *
- * @param collectionName The name of the collection
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteCollectionAsync(String collectionName) {
- return deleteCollectionAsync(collectionName, null);
- }
-
- /**
- * Deletes a collection and all its associated data.
- *
- * @param collectionName The name of the collection
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteCollectionAsync(String collectionName, @Nullable Duration timeout) {
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Delete collection '{}'", collectionName);
-
- DeleteCollection deleteCollection = DeleteCollection.newBuilder()
- .setCollectionName(collectionName)
- .build();
- ListenableFuture future = getCollections(timeout).delete(deleteCollection);
- addLogFailureCallback(future, "Delete collection");
-
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Collection '{}' could not be deleted", collectionName);
- throw new QdrantException("Collection '" + collectionName + "' could not be deleted");
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- /**
- * Gets the names of all existing collections
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listCollectionsAsync() {
- return listCollectionsAsync(null);
- }
-
- /**
- * Gets the names of all existing collections
- *
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listCollectionsAsync(@Nullable Duration timeout) {
- logger.debug("List collections");
-
- ListenableFuture future =
- getCollections(timeout).list(ListCollectionsRequest.getDefaultInstance());
-
- addLogFailureCallback(future, "List collection");
- return Futures.transform(future, response ->
- response.getCollectionsList()
- .stream()
- .map(CollectionDescription::getName)
- .collect(Collectors.toList()), MoreExecutors.directExecutor());
- }
-
- /**
- * Update parameters of the collection
- *
- * @param updateCollection The update parameters.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateCollectionAsync(UpdateCollection updateCollection) {
- return updateCollectionAsync(updateCollection, null);
- }
-
- /**
- * Update parameters of the collection
- *
- * @param updateCollection The update parameters.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateCollectionAsync(UpdateCollection updateCollection, @Nullable Duration timeout) {
- String collectionName = updateCollection.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Update collection '{}'", collectionName);
-
- ListenableFuture future = getCollections(timeout).update(updateCollection);
- addLogFailureCallback(future, "Update collection");
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Collection '{}' could not be updated", collectionName);
- throw new QdrantException("Collection '" + collectionName + "' could not be updated");
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- /**
- * Check if a collection exists
- *
- * @param collectionName The name of the collection.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture collectionExistsAsync(String collectionName) {
- return collectionExistsAsync(collectionName, null);
- }
-
- /**
- * Check if a collection exists
- *
- * @param collectionName The name of the collection.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture collectionExistsAsync(String collectionName, @Nullable Duration timeout) {
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Collection exists '{}'", collectionName);
-
- ListenableFuture future = getCollections(timeout)
- .collectionExists(CollectionExistsRequest.newBuilder().setCollectionName(collectionName).build());
- addLogFailureCallback(future, "Collection exists");
- return Futures.transform(future, response -> response.getResult().getExists(), MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Alias Management
-
- /**
- * Creates an alias for a given collection.
- *
- * @param aliasName The alias to be created.
- * @param collectionName The collection for which the alias is to be created.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createAliasAsync(String aliasName, String collectionName) {
- return createAliasAsync(aliasName, collectionName, null);
- }
-
- /**
- * Creates an alias for a given collection.
- *
- * @param aliasName The alias to be created.
- * @param collectionName The collection for which the alias is to be created.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createAliasAsync(String aliasName, String collectionName, @Nullable Duration timeout) {
- return updateAliasesAsync(ImmutableList.of(AliasOperations.newBuilder()
- .setCreateAlias(CreateAlias.newBuilder()
- .setAliasName(aliasName)
- .setCollectionName(collectionName)
- .build())
- .build()),
- timeout);
- }
-
- /**
- * Renames an existing alias.
- *
- * @param oldAliasName The old alias name.
- * @param newAliasName The new alias name.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture renameAliasAsync(String oldAliasName, String newAliasName) {
- return renameAliasAsync(oldAliasName, newAliasName, null);
- }
-
- /**
- * Renames an existing alias.
- *
- * @param oldAliasName The old alias name.
- * @param newAliasName The new alias name.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture renameAliasAsync(String oldAliasName, String newAliasName, @Nullable Duration timeout) {
- return updateAliasesAsync(ImmutableList.of(AliasOperations.newBuilder()
- .setRenameAlias(RenameAlias.newBuilder()
- .setOldAliasName(oldAliasName)
- .setNewAliasName(newAliasName)
- .build())
- .build()),
- timeout);
- }
-
- /**
- * Deletes an alias.
- *
- * @param aliasName The alias to be deleted.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAliasAsync(String aliasName) {
- return deleteAliasAsync(aliasName, null);
- }
-
- /**
- * Deletes an alias.
- *
- * @param aliasName The alias to be deleted.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAliasAsync(String aliasName, @Nullable Duration timeout) {
- return updateAliasesAsync(ImmutableList.of(AliasOperations.newBuilder()
- .setDeleteAlias(DeleteAlias.newBuilder()
- .setAliasName(aliasName)
- .build())
- .build()),
- timeout);
- }
-
- /**
- * Update the aliases of existing collections.
- *
- * @param aliasOperations The list of operations to perform.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateAliasesAsync(List aliasOperations) {
- return updateAliasesAsync(aliasOperations, null);
- }
-
- /**
- * Update the aliases of existing collections.
- *
- * @param aliasOperations The list of operations to perform.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateAliasesAsync(List aliasOperations, @Nullable Duration timeout) {
- ChangeAliases request = ChangeAliases.newBuilder()
- .addAllActions(aliasOperations)
- .build();
-
- if (logger.isDebugEnabled()) {
- for (AliasOperations aliasOperation : aliasOperations) {
- switch (aliasOperation.getActionCase()) {
- case CREATE_ALIAS:
- CreateAlias createAlias = aliasOperation.getCreateAlias();
- logger.debug("Create alias '{}' for collection '{}'",
- createAlias.getAliasName(),
- createAlias.getCollectionName());
- break;
- case RENAME_ALIAS:
- RenameAlias renameAlias = aliasOperation.getRenameAlias();
- logger.debug("Rename alias '{}' to '{}'",
- renameAlias.getOldAliasName(),
- renameAlias.getNewAliasName());
- break;
- case DELETE_ALIAS:
- DeleteAlias deleteAlias = aliasOperation.getDeleteAlias();
- logger.debug("Delete alias '{}'", deleteAlias.getAliasName());
- break;
- case ACTION_NOT_SET:
- break;
- }
- }
- }
-
- ListenableFuture future = getCollections(timeout).updateAliases(request);
- addLogFailureCallback(future, "Update aliases");
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Alias update operation could not be performed");
- throw new QdrantException("Alias update could not be performed");
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- /**
- * Gets a list of all aliases for a collection.
- *
- * @param collectionName The name of the collection.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listCollectionAliasesAsync(String collectionName) {
- return listCollectionAliasesAsync(collectionName, null);
- }
-
- /**
- * Gets a list of all aliases for a collection.
- *
- * @param collectionName The name of the collection.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listCollectionAliasesAsync(String collectionName, @Nullable Duration timeout) {
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("List aliases for collection '{}'", collectionName);
-
- ListCollectionAliasesRequest request = ListCollectionAliasesRequest.newBuilder()
- .setCollectionName(collectionName)
- .build();
-
- ListenableFuture future = getCollections(timeout).listCollectionAliases(request);
- addLogFailureCallback(future, "List collection aliases");
- return Futures.transform(future, response -> response.getAliasesList()
- .stream()
- .map(AliasDescription::getAliasName)
- .collect(Collectors.toList()), MoreExecutors.directExecutor());
- }
-
- /**
- * Gets a list of all aliases for all existing collections.
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listAliasesAsync() {
- return listAliasesAsync(null);
- }
-
- /**
- * Gets a list of all aliases for all existing collections.
- *
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> listAliasesAsync(@Nullable Duration timeout) {
- logger.debug("List all aliases");
- ListenableFuture future = getCollections(timeout).listAliases(ListAliasesRequest.getDefaultInstance());
- addLogFailureCallback(future, "List aliases");
- return Futures.transform(future, ListAliasesResponse::getAliasesList, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region ShardKey Management
-
- /**
- * Creates a shard key for a collection.
- *
- * @param createShardKey The request object for the operation.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createShardKeyAsync(CreateShardKeyRequest createShardKey) {
- return createShardKeyAsync(createShardKey, null);
- }
-
- /**
- * Creates a shard key for a collection.
- *
- * @param createShardKey The request object for the operation.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createShardKeyAsync(CreateShardKeyRequest createShardKey, @Nullable Duration timeout) {
- String collectionName = createShardKey.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- ShardKey shardKey = createShardKey.getRequest().getShardKey();
- logger.debug("Create shard key '{}' for '{}'", shardKey, collectionName);
-
- ListenableFuture future = getCollections(timeout).createShardKey(createShardKey);
- addLogFailureCallback(future, "Create shard key");
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Shard key could not be created for '{}'", collectionName);
- throw new QdrantException("Shard key " + shardKey + " could not be created for " + collectionName);
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- /**
- * Deletes a shard key for a collection.
- *
- * @param deleteShardKey The request object for the operation.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey) {
- return deleteShardKeyAsync(deleteShardKey, null);
- }
-
- /**
- * Deletes a shard key for a collection.
- *
- * @param deleteShardKey The request object for the operation.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey, @Nullable Duration timeout) {
- String collectionName = deleteShardKey.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- ShardKey shardKey = deleteShardKey.getRequest().getShardKey();
- logger.debug("Delete shard key '{}' for '{}'", shardKey, collectionName);
-
- ListenableFuture future = getCollections(timeout).deleteShardKey(deleteShardKey);
- addLogFailureCallback(future, "Delete shard key");
- return Futures.transform(future, response -> {
- if (!response.getResult()) {
- logger.error("Shard key '{}' could not be deleted for '{}'", shardKey, collectionName);
- throw new QdrantException("Shard key " + shardKey + " could not be created for " + collectionName);
- }
- return response;
- }, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Point Management
-
- /**
- * Perform insert and updates on points. If a point with a given ID already exists, it will be overwritten.
- *
- * @param collectionName The name of the collection.
- * @param points The points to be upserted
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture upsertAsync(
- String collectionName,
- List points) {
- return upsertAsync(collectionName, points, null);
- }
-
- /**
- * Perform insert and updates on points. If a point with a given ID already exists, it will be overwritten.
- * The call waits for the changes to be applied.
- *
- * @param collectionName The name of the collection.
- * @param points The points to be upserted
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture upsertAsync(
- String collectionName,
- List points,
- @Nullable Duration timeout) {
- return upsertAsync(
- UpsertPoints.newBuilder()
- .setCollectionName(collectionName)
- .addAllPoints(points)
- .setWait(true)
- .build(),
- timeout);
- }
-
- /**
- * Perform insert and updates on points. If a point with a given ID already exists, it will be overwritten.
- *
- * @param request The upsert points request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture upsertAsync(UpsertPoints request) {
- return upsertAsync(request, null);
- }
-
- /**
- * Perform insert and updates on points. If a point with a given ID already exists, it will be overwritten.
- *
- * @param request The upsert points request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture upsertAsync(
- UpsertPoints request,
- @Nullable Duration timeout) {
- String collectionName = request.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Upsert {} points into '{}'", request.getPointsList().size(), collectionName);
- ListenableFuture future = getPoints(timeout).upsert(request);
- addLogFailureCallback(future, "Upsert");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- /**
- * Deletes points.
- * The call waits for the changes to be applied.
- *
- * @param collectionName The name of the collection.
- * @param ids The ids of points to delete.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(
- String collectionName,
- List ids) {
- return deleteAsync(collectionName, ids, null);
- }
-
- /**
- * Deletes points.
- * The call waits for the changes to be applied.
- *
- * @param collectionName The name of the collection.
- * @param ids The ids of points to delete.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(
- String collectionName,
- List ids,
- @Nullable Duration timeout) {
- return deleteAsync(DeletePoints.newBuilder()
- .setCollectionName(collectionName)
- .setPoints(PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addAllIds(ids).build()).build())
- .setWait(true)
- .build(),
- timeout);
- }
-
- /**
- * Deletes points.
- * The call waits for the changes to be applied.
- *
- * @param collectionName The name of the collection.
- * @param filter A filter selecting the points to be deleted.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(
- String collectionName,
- Filter filter) {
- return deleteAsync(collectionName, filter, null);
- }
-
- /**
- * Deletes points.
- *
- * @param collectionName The name of the collection.
- * @param filter A filter selecting the points to be deleted.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(
- String collectionName,
- Filter filter,
- @Nullable Duration timeout) {
- return deleteAsync(DeletePoints.newBuilder()
- .setCollectionName(collectionName)
- .setPoints(PointsSelector.newBuilder().setFilter(filter).build())
- .setWait(true)
- .build(),
- timeout);
- }
-
- /**
- * Deletes points.
- *
- * @param request The delete points request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(DeletePoints request) {
- return deleteAsync(request, null);
- }
-
- /**
- * Deletes points.
- *
- * @param request The delete points request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteAsync(
- DeletePoints request,
- @Nullable Duration timeout) {
- String collectionName = request.getCollectionName();
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
- logger.debug("Delete from '{}'", collectionName);
- ListenableFuture future = getPoints(timeout).delete(request);
- addLogFailureCallback(future, "Delete");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- /**
- * Retrieves points. Includes all payload, excludes vectors.
- *
- * @param collectionName The name of the collection.
- * @param id The id of a point to retrieve
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- PointId id,
- @Nullable ReadConsistency readConsistency
- ) {
- return retrieveAsync(
- collectionName,
- id,
- true,
- false,
- readConsistency
- );
- }
-
- /**
- * Retrieves points.
- *
- * @param collectionName The name of the collection.
- * @param id The id of a point to retrieve
- * @param withPayload Whether to include the payload or not.
- * @param withVectors Whether to include the vectors or not.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- PointId id,
- boolean withPayload,
- boolean withVectors,
- @Nullable ReadConsistency readConsistency
- ) {
- return retrieveAsync(
- collectionName,
- ImmutableList.of(id),
- WithPayloadSelectorFactory.enable(withPayload),
- WithVectorsSelectorFactory.enable(withVectors),
- readConsistency
- );
- }
-
- /**
- * Retrieves points. Includes all payload, excludes vectors.
- *
- * @param collectionName The name of the collection.
- * @param ids The list of ids of points to retrieve
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- List ids,
- @Nullable ReadConsistency readConsistency
- ) {
- return retrieveAsync(
- collectionName,
- ids,
- true,
- false,
- readConsistency
- );
- }
-
- /**
- * Retrieves points.
- *
- * @param collectionName The name of the collection.
- * @param ids The list of ids of points to retrieve
- * @param withPayload Whether to include the payload or not.
- * @param withVectors Whether to include the vectors or not.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- List ids,
- boolean withPayload,
- boolean withVectors,
- @Nullable ReadConsistency readConsistency
- ) {
- return retrieveAsync(
- collectionName,
- ids,
- WithPayloadSelectorFactory.enable(withPayload),
- WithVectorsSelectorFactory.enable(withVectors),
- readConsistency
- );
- }
-
- /**
- * Retrieves points.
- *
- * @param collectionName The name of the collection.
- * @param ids The list of ids of points to retrieve
- * @param payloadSelector Options for specifying which payload to include or not.
- * @param vectorsSelector Options for specifying which vectors to include into response.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- List ids,
- WithPayloadSelector payloadSelector,
- WithVectorsSelector vectorsSelector,
- @Nullable ReadConsistency readConsistency
- ) {
- return retrieveAsync(collectionName, ids, payloadSelector, vectorsSelector, readConsistency, null);
- }
-
- /**
- * Retrieves points.
- *
- * @param collectionName The name of the collection.
- * @param ids The list of ids of points to retrieve
- * @param payloadSelector Options for specifying which payload to include or not.
- * @param vectorsSelector Options for specifying which vectors to include into response.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- String collectionName,
- List ids,
- WithPayloadSelector payloadSelector,
- WithVectorsSelector vectorsSelector,
- @Nullable ReadConsistency readConsistency,
- @Nullable Duration timeout
- ) {
- logger.debug("Retrieve points from '{}'", collectionName);
- GetPoints.Builder requestBuilder = GetPoints.newBuilder()
- .setCollectionName(collectionName)
- .addAllIds(ids)
- .setWithPayload(payloadSelector)
- .setWithVectors(vectorsSelector);
-
- if (readConsistency != null) {
- requestBuilder.setReadConsistency(readConsistency);
- }
-
- return retrieveAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Retrieves points.
- *
- * @param request The get points request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> retrieveAsync(
- GetPoints request, @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(), "Collection name must not be empty");
-
- logger.debug("Retrieve points from '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).get(request);
- addLogFailureCallback(future, "Retrieve");
- return Futures.transform(future, GetResponse::getResultList, MoreExecutors.directExecutor());
- }
-
- //region Update Vectors
-
- /**
- * Update named vectors for point.
- *
- * @param collectionName The name of the collection.
- * @param points The list of points and vectors to update.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateVectorsAsync(
- String collectionName,
- List points
- ) {
- return updateVectorsAsync(collectionName, points, null, null, null);
- }
-
- /**
- * Update named vectors for point.
- *
- * @param collectionName The name of the collection.
- * @param points The list of points and vectors to update.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateVectorsAsync(
- String collectionName,
- List points,
- @Nullable Duration timeout
- ) {
- return updateVectorsAsync(collectionName, points, null, null, timeout);
- }
-
- /**
- * Update named vectors for point.
- *
- * @param collectionName The name of the collection.
- * @param points The list of points and vectors to update.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateVectorsAsync(
- String collectionName,
- List points,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- logger.debug("Update vectors in '{}'", collectionName);
- UpdatePointVectors.Builder requestBuilder = UpdatePointVectors.newBuilder()
- .setCollectionName(collectionName)
- .addAllPoints(points)
- .setWait(wait == null || wait);
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- return updateVectorsAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Update named vectors for point.
- *
- * @param request The update point vectors request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture updateVectorsAsync(
- UpdatePointVectors request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(!request.getCollectionName().isEmpty(), "Collection name must not be empty");
- logger.debug("Update vectors in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).updateVectors(request);
- addLogFailureCallback(future, "Update vectors");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Delete Vectors
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param filter A filter selecting the points to be deleted.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- Filter filter
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder().setFilter(filter).build(),
- null,
- null,
- null
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param filter A filter selecting the points to be deleted.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- Filter filter,
- @Nullable Duration timeout
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder().setFilter(filter).build(),
- null,
- null,
- timeout
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param filter A filter selecting the points to be deleted.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- Filter filter,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder().setFilter(filter).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param ids The list of ids to delete.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- List ids
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder()
- .setPoints(PointsIdsList.newBuilder().addAllIds(ids).build())
- .build(),
- null,
- null,
- null
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param ids The list of ids to delete.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- List ids,
- @Nullable Duration timeout
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder()
- .setPoints(PointsIdsList.newBuilder().addAllIds(ids).build())
- .build(),
- null,
- null,
- timeout
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param ids The list of ids to delete.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- List ids,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deleteVectorsAsync(
- collectionName,
- vectors,
- PointsSelector.newBuilder()
- .setPoints(PointsIdsList.newBuilder().addAllIds(ids).build())
- .build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param collectionName The name of the collection.
- * @param vectors The list of vector names to delete.
- * @param pointsSelector A selector for the points to be deleted.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- String collectionName,
- List vectors,
- PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- logger.debug("Delete vectors in '{}'", collectionName);
- DeletePointVectors.Builder requestBuilder = DeletePointVectors.newBuilder()
- .setCollectionName(collectionName)
- .setVectors(VectorsSelector.newBuilder()
- .addAllNames(vectors)
- .build())
- .setPointsSelector(pointsSelector)
- .setWait(wait == null || wait);
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- return deleteVectorsAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Delete named vectors for points.
- *
- * @param request The delete point vectors request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deleteVectorsAsync(
- DeletePointVectors request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Delete vectors in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).deleteVectors(request);
- addLogFailureCallback(future, "Delete vectors");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //endregion
-
- //region Set Payload
-
- /**
- * Sets the payload for all points in the collection.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return setPayloadAsync(
- collectionName,
- payload,
- (PointsSelector) null,
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Sets the payload for the given id.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param id The id for which to set the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- PointId id,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return setPayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addIds(id).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Sets the payload for the given ids.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param ids The ids for which to set the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- List ids,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return setPayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addAllIds(ids).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Sets the payload for the given ids.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param filter A filter selecting the points to be set.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- Filter filter,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return setPayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setFilter(filter).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Sets the payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param pointsSelector selector for the points whose payloads are to be set.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return setPayloadAsync(
- collectionName,
- payload,
- pointsSelector,
- wait,
- null,
- ordering,
- timeout
- );
- }
-
- /**
- * Sets the payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param pointsSelector Selector for the points whose payloads are to be set.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param key The key for which to set the payload if nested
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- String collectionName,
- Map payload,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable String key,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- SetPayloadPoints.Builder requestBuilder = SetPayloadPoints.newBuilder()
- .setCollectionName(collectionName)
- .setWait(wait == null || wait)
- .putAllPayload(payload);
-
- if (pointsSelector != null) {
- requestBuilder.setPointsSelector(pointsSelector);
- }
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- if (key != null) {
- requestBuilder.setKey(key);
- }
-
- return setPayloadAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Sets the payload for the points.
- *
- * @param request The set payload request.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture setPayloadAsync(
- SetPayloadPoints request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Set payload in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).setPayload(request);
- addLogFailureCallback(future, "Set payload");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Overwrite payload
-
- /**
- * Overwrites the payload for all points in the collection.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return overwritePayloadAsync(
- collectionName,
- payload,
- (PointsSelector) null,
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Overwrites the payload for the given id.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param id The id for which to overwrite the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- PointId id,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return overwritePayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addIds(id).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Overwrites the payload for the given ids.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param ids The ids for which to overwrite the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- List ids,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return overwritePayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addAllIds(ids).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Overwrites the payload for the filtered points.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param filter A filter selecting the points for which to overwrite the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- Filter filter,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return overwritePayloadAsync(
- collectionName,
- payload,
- PointsSelector.newBuilder().setFilter(filter).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Overwrites the payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param pointsSelector A selector for the points whose payloads are to be overwritten.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return overwritePayloadAsync(
- collectionName,
- payload,
- pointsSelector,
- wait,
- null,
- ordering,
- timeout
- );
- }
-
- /**
- * Overwrites the payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param payload New payload values
- * @param pointsSelector Selector for the points whose payloads are to be overwritten.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param key The key for which to overwrite the payload if nested
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- String collectionName,
- Map payload,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable String key,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- SetPayloadPoints.Builder requestBuilder = SetPayloadPoints.newBuilder()
- .setCollectionName(collectionName)
- .setWait(wait == null || wait)
- .putAllPayload(payload);
-
- if (pointsSelector != null) {
- requestBuilder.setPointsSelector(pointsSelector);
- }
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- if (key != null)
- requestBuilder.setKey(key);
-
- return overwritePayloadAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Overwrites the payload for the points.
- *
- * @param request The overwrite payload request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture overwritePayloadAsync(
- SetPayloadPoints request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Set payload in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).overwritePayload(request);
- addLogFailureCallback(future, "Overwrite payload");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Delete Payload
-
- /**
- * Delete specified key payload for all points.
- *
- * @param collectionName The name of the collection.
- * @param keys List of keys to delete.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- String collectionName,
- List keys,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deletePayloadAsync(
- collectionName,
- keys,
- (PointsSelector) null,
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete specified key payload for the given id.
- *
- * @param collectionName The name of the collection.
- * @param keys List of keys to delete.
- * @param id The id for which to delete the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- String collectionName,
- List keys,
- PointId id,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deletePayloadAsync(
- collectionName,
- keys,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addIds(id).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete specified key payload for the given ids.
- *
- * @param collectionName The name of the collection.
- * @param keys List of keys to delete.
- * @param ids The ids for which to delete the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- String collectionName,
- List keys,
- List ids,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deletePayloadAsync(
- collectionName,
- keys,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addAllIds(ids).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete specified key payload for the filtered points.
- *
- * @param collectionName The name of the collection.
- * @param keys List of keys to delete.
- * @param filter A filter selecting the points to for which to delete the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- String collectionName,
- List keys,
- Filter filter,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return deletePayloadAsync(
- collectionName,
- keys,
- PointsSelector.newBuilder().setFilter(filter).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Delete specified key payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param keys List of keys to delete.
- * @param pointsSelector selector for the points whose payloads are to be deleted.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- String collectionName,
- List keys,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- DeletePayloadPoints.Builder requestBuilder = DeletePayloadPoints.newBuilder()
- .setCollectionName(collectionName)
- .setWait(wait == null || wait)
- .addAllKeys(keys);
-
- if (pointsSelector != null) {
- requestBuilder.setPointsSelector(pointsSelector);
- }
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- return deletePayloadAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Delete specified key payload for the points.
- *
- * @param request The delete payload request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadAsync(
- DeletePayloadPoints request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Delete payload in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).deletePayload(request);
- addLogFailureCallback(future, "Delete payload");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- //region Clear Payload
-
- /**
- * Remove all payload for all points.
- *
- * @param collectionName The name of the collection.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- String collectionName,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return clearPayloadAsync(
- collectionName,
- (PointsSelector) null,
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Removes all payload for the given id.
- *
- * @param collectionName The name of the collection.
- * @param id The id for which to remove the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- String collectionName,
- PointId id,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return clearPayloadAsync(
- collectionName,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addIds(id).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Removes all payload for the given ids.
- *
- * @param collectionName The name of the collection.
- * @param ids The ids for which to remove the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- String collectionName,
- List ids,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return clearPayloadAsync(
- collectionName,
- PointsSelector.newBuilder().setPoints(PointsIdsList.newBuilder().addAllIds(ids).build()).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Removes all payload for the filtered points.
- *
- * @param collectionName The name of the collection.
- * @param filter A filter selecting the points for which to remove the payload.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- String collectionName,
- Filter filter,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- return clearPayloadAsync(
- collectionName,
- PointsSelector.newBuilder().setFilter(filter).build(),
- wait,
- ordering,
- timeout
- );
- }
-
- /**
- * Removes all payload for the points.
- *
- * @param collectionName The name of the collection.
- * @param pointsSelector A selector for the points whose payloads are to be removed.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- String collectionName,
- @Nullable PointsSelector pointsSelector,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- ClearPayloadPoints.Builder requestBuilder = ClearPayloadPoints.newBuilder()
- .setCollectionName(collectionName)
- .setWait(wait == null || wait);
-
- if (pointsSelector != null) {
- requestBuilder.setPoints(pointsSelector);
- }
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- return clearPayloadAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Removes all payload for the points.
- *
- * @param request The clear payload request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture clearPayloadAsync(
- ClearPayloadPoints request,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Clear payload in '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).clearPayload(request);
- addLogFailureCallback(future, "Clear payload");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- //endregion
-
- /**
- * Creates a payload field index in a collection.
- *
- * @param collectionName The name of the collection.
- * @param field The field name to index.
- * @param schemaType The schema type of the field.
- * @param indexParams Payload index parameters.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createPayloadIndexAsync(
- String collectionName,
- String field,
- PayloadSchemaType schemaType,
- @Nullable PayloadIndexParams indexParams,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- CreateFieldIndexCollection.Builder requestBuilder = CreateFieldIndexCollection.newBuilder()
- .setCollectionName(collectionName)
- .setFieldName(field)
- .setWait(wait == null || wait);
-
- switch (schemaType) {
- case Keyword:
- requestBuilder.setFieldType(FieldType.FieldTypeKeyword);
- break;
- case Integer:
- requestBuilder.setFieldType(FieldType.FieldTypeInteger);
- break;
- case Float:
- requestBuilder.setFieldType(FieldType.FieldTypeFloat);
- break;
- case Geo:
- requestBuilder.setFieldType(FieldType.FieldTypeGeo);
- break;
- case Text:
- requestBuilder.setFieldType(FieldType.FieldTypeText);
- break;
- case Bool:
- requestBuilder.setFieldType(FieldType.FieldTypeBool);
- break;
- case Datetime:
- requestBuilder.setFieldType(FieldType.FieldTypeDatetime);
- break;
- default:
- throw new IllegalArgumentException("Invalid schemaType: '" + schemaType + "'");
- }
-
- if (indexParams != null) {
- requestBuilder.setFieldIndexParams(indexParams);
- }
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- return createPayloadIndexAsync(requestBuilder.build(), timeout);
- }
-
- /**
- * Creates a payload field index in a collection.
- *
- * @param request The create field index request.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture createPayloadIndexAsync(
- CreateFieldIndexCollection request,
- @Nullable Duration timeout
- ) {
- logger.debug("Create payload field index for '{}' in '{}'", request.getFieldName(), request.getCollectionName());
- ListenableFuture future = getPoints(timeout).createFieldIndex(request);
- addLogFailureCallback(future, "Create payload field index");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- /**
- * Deletes a payload field index in a collection.
- *
- * @param collectionName The name of the collection.
- * @param field The field name to index.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture deletePayloadIndexAsync(
- String collectionName,
- String field,
- @Nullable Boolean wait,
- @Nullable WriteOrderingType ordering,
- @Nullable Duration timeout
- ) {
- DeleteFieldIndexCollection.Builder requestBuilder = DeleteFieldIndexCollection.newBuilder()
- .setCollectionName(collectionName)
- .setFieldName(field)
- .setWait(wait == null || wait);
-
- if (ordering != null) {
- requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
- }
-
- logger.debug("Delete payload field index for '{}' in '{}'", field, collectionName);
- ListenableFuture future = getPoints(timeout).deleteFieldIndex(requestBuilder.build());
- addLogFailureCallback(future, "Delete payload field index");
- return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions.
- *
- * @param request the search request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchAsync(SearchPoints request) {
- return searchAsync(request, null);
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions.
- *
- * @param request the search request
- * @param timeout the timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchAsync(SearchPoints request, @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- Preconditions.checkArgument(
- !request.getVectorList().isEmpty(),
- "Vector must not be empty");
-
- logger.debug("Search on '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).search(request);
- addLogFailureCallback(future, "Search");
- return Futures.transform(future, SearchResponse::getResultList, MoreExecutors.directExecutor());
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions.
- *
- * @param collectionName The name of the collection
- * @param searches The searches to be performed in the batch.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchBatchAsync(
- String collectionName,
- List searches,
- @Nullable ReadConsistency readConsistency
- ) {
- return searchBatchAsync(collectionName, searches, readConsistency, null);
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions.
- *
- * @param collectionName The name of the collection
- * @param searches The searches to be performed in the batch.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchBatchAsync(
- String collectionName,
- List searches,
- @Nullable ReadConsistency readConsistency,
- @Nullable Duration timeout
- ) {
- // TODO: Workaround for https://github.com/qdrant/qdrant/issues/2880
- searches = Lists.transform(
- searches,
- searchPoints -> searchPoints.toBuilder().setCollectionName(collectionName).build());
-
- SearchBatchPoints.Builder requestBuilder = SearchBatchPoints.newBuilder()
- .setCollectionName(collectionName)
- .addAllSearchPoints(searches);
-
- if (readConsistency != null) {
- requestBuilder.setReadConsistency(readConsistency);
- }
-
- logger.debug("Search batch on '{}'", collectionName);
- ListenableFuture future = getPoints(timeout).searchBatch(requestBuilder.build());
- addLogFailureCallback(future, "Search batch");
- return Futures.transform(future, SearchBatchResponse::getResultList, MoreExecutors.directExecutor());
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions, grouped by a given field.
- *
- * @param request The search group request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchGroupsAsync(SearchPointGroups request) {
- return searchGroupsAsync(request, null);
- }
-
- /**
- * Retrieves closest points based on vector similarity and the given filtering conditions, grouped by a given field.
- *
- * @param request The search group request
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> searchGroupsAsync(SearchPointGroups request, @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Search groups on '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).searchGroups(request);
- addLogFailureCallback(future, "Search groups");
- return Futures.transform(
- future,
- response -> response.getResult().getGroupsList(),
- MoreExecutors.directExecutor());
- }
-
- /**
- * Iterates over all or filtered points.
- *
- * @param request The scroll request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture scrollAsync(ScrollPoints request) {
- return scrollAsync(request, null);
- }
-
- /**
- * Iterates over all or filtered points.
- *
- * @param request The scroll request.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture scrollAsync(ScrollPoints request, @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Scroll on '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).scroll(request);
- addLogFailureCallback(future, "Scroll");
- return future;
- }
-
- /**
- * Look for the points which are closer to stored positive examples and at the same time further to negative
- * examples.
- *
- * @param request The recommend request
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> recommendAsync(RecommendPoints request) {
- return recommendAsync(request, null);
- }
-
- /**
- * Look for the points which are closer to stored positive examples and at the same time further to negative
- * examples.
- *
- * @param request The recommend request.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> recommendAsync(RecommendPoints request, @Nullable Duration timeout) {
- Preconditions.checkArgument(
- !request.getCollectionName().isEmpty(),
- "Collection name must not be empty");
- logger.debug("Recommend on '{}'", request.getCollectionName());
- ListenableFuture future = getPoints(timeout).recommend(request);
- addLogFailureCallback(future, "Recommend");
- return Futures.transform(
- future,
- RecommendResponse::getResultList,
- MoreExecutors.directExecutor());
- }
-
- /**
- * Look for the points which are closer to stored positive examples and at the same time further to negative
- * examples.
- *
- * @param collectionName The name of the collection.
- * @param recommendSearches The list of recommendation searches.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> recommendBatchAsync(
- String collectionName,
- List recommendSearches,
- @Nullable ReadConsistency readConsistency) {
- return recommendBatchAsync(collectionName, recommendSearches, readConsistency, null);
- }
-
- /**
- * Look for the points which are closer to stored positive examples and at the same time further to negative
- * examples.
- *
- * @param collectionName The name of the collection.
- * @param recommendSearches The list of recommendation searches.
- * @param readConsistency Options for specifying read consistency guarantees.
- * @param timeout The timeout for the call.
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> recommendBatchAsync(
- String collectionName,
- List recommendSearches,
- @Nullable ReadConsistency readConsistency,
- @Nullable Duration timeout) {
- Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
-
- // TODO: Workaround for https://github.com/qdrant/qdrant/issues/2880
- recommendSearches = Lists.transform(
- recommendSearches,
- recommendPoints -> recommendPoints.toBuilder().setCollectionName(collectionName).build());
-
- RecommendBatchPoints.Builder requestBuilder = RecommendBatchPoints.newBuilder()
- .setCollectionName(collectionName)
- .addAllRecommendPoints(recommendSearches);
-
- if (readConsistency != null) {
- requestBuilder.setReadConsistency(readConsistency);
- }
-
- logger.debug("Recommend batch on '{}'", collectionName);
- ListenableFuture future = getPoints(timeout).recommendBatch(requestBuilder.build());
- addLogFailureCallback(future, "Recommend batch");
- return Futures.transform(
- future,
- RecommendBatchResponse::getResultList,
- MoreExecutors.directExecutor());
- }
-
- /**
- * Performs a batch update of points.
- *
- * @param collectionName The name of the collection.
- * @param operations The list of point update operations.
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> batchUpdateAsync(String collectionName, List operations) {
- return batchUpdateAsync(collectionName, operations, null, null, null);
- }
-
- /**
- * Performs a batch update of points.
- *
- * @param collectionName The name of the collection.
- * @param operations The list of point update operations.
- * @param wait Whether to wait until the changes have been applied. Defaults to true.
- * @param ordering Write ordering guarantees.
- * @param timeout The timeout for the call.
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture> batchUpdateAsync(
- String collectionName,
- List operations,
- @Nullable Boolean wait,
- @Nullable WriteOrdering ordering,
- @Nullable Duration timeout) {
-
- UpdateBatchPoints.Builder requestBuilder = UpdateBatchPoints.newBuilder()
- .setCollectionName(collectionName)
- .addAllOperations(operations)
- .setWait(wait == null || wait);
-
- if (ordering != null) {
- requestBuilder.setOrdering(ordering);
- }
- return batchUpdateAsync(requestBuilder.build(), timeout);
- }
-
-
- /**
- * Performs a batch update of points.
- *
- * @param request The update batch request.
- * @param timeout The timeout for the call.
- *
- * @return a new instance of {@link ListenableFuture}
- */
- public ListenableFuture