Skip to content

Commit acde2bd

Browse files
authored
chore: Cloud inference helpers (#72)
Signed-off-by: Anush008 <anushshetty90@gmail.com>
1 parent 38fd5de commit acde2bd

File tree

5 files changed

+132
-31
lines changed

5 files changed

+132
-31
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
qdrantProtosVersion=v1.14.0
33

44
# The version of qdrant docker image to run integration tests against
5-
qdrantVersion=v1.14.0
5+
qdrantVersion=v1.14.1
66

77
# The version of the client to generate
8-
packageVersion=1.14.0
8+
packageVersion=1.14.1

src/main/java/io/qdrant/client/QueryFactory.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import io.qdrant.client.grpc.Points.ContextInput;
77
import io.qdrant.client.grpc.Points.DiscoverInput;
8+
import io.qdrant.client.grpc.Points.Document;
89
import io.qdrant.client.grpc.Points.Formula;
910
import io.qdrant.client.grpc.Points.Fusion;
11+
import io.qdrant.client.grpc.Points.InferenceObject;
1012
import io.qdrant.client.grpc.Points.OrderBy;
1113
import io.qdrant.client.grpc.Points.PointId;
1214
import io.qdrant.client.grpc.Points.Query;
@@ -157,7 +159,7 @@ public static Query nearest(long id) {
157159
/**
158160
* Creates a {@link Query} from a {@link UUID}
159161
*
160-
* @param id The pint id
162+
* @param id The point id
161163
* @return a new instance of {@link Query}
162164
*/
163165
public static Query nearest(UUID id) {
@@ -167,13 +169,43 @@ public static Query nearest(UUID id) {
167169
/**
168170
* Creates a {@link Query} from a {@link PointId}
169171
*
170-
* @param id The pint id
172+
* @param id The point id
171173
* @return a new instance of {@link Query}
172174
*/
173175
public static Query nearest(PointId id) {
174176
return Query.newBuilder().setNearest(vectorInput(id)).build();
175177
}
176178

179+
/**
180+
* Creates a {@link Query} from a {@link Document}
181+
*
182+
* @param document The document to vectorize and query against.
183+
* @return a new instance of {@link Query}
184+
*/
185+
public static Query nearest(Document document) {
186+
return Query.newBuilder().setNearest(vectorInput(document)).build();
187+
}
188+
189+
/**
190+
* Creates a {@link Query} from an image for cloud inference.
191+
*
192+
* @param image The image to vectorize and query against.
193+
* @return a new instance of {@link Query}
194+
*/
195+
public static Query nearest(io.qdrant.client.grpc.Points.Image image) {
196+
return Query.newBuilder().setNearest(vectorInput(image)).build();
197+
}
198+
199+
/**
200+
* Creates a {@link Query} from an {@link InferenceObject}
201+
*
202+
* @param object The inference object to vectorize and query against.
203+
* @return a new instance of {@link Query}
204+
*/
205+
public static Query nearest(InferenceObject object) {
206+
return Query.newBuilder().setNearest(vectorInput(object)).build();
207+
}
208+
177209
/**
178210
* Creates a {@link Query} from a nested list of floats representing a multi vector
179211
*

src/main/java/io/qdrant/client/VectorFactory.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.qdrant.client;
22

33
import com.google.common.primitives.Floats;
4+
import io.qdrant.client.grpc.Points.Document;
5+
import io.qdrant.client.grpc.Points.Image;
6+
import io.qdrant.client.grpc.Points.InferenceObject;
47
import io.qdrant.client.grpc.Points.SparseIndices;
58
import io.qdrant.client.grpc.Points.Vector;
69
import java.util.ArrayList;
@@ -45,6 +48,36 @@ public static Vector vector(List<Float> vector, List<Integer> indices) {
4548
.build();
4649
}
4750

51+
/**
52+
* Creates a vector from a document for cloud inference.
53+
*
54+
* @param document The document to vectorize.
55+
* @return A new instance of {@link Vector}
56+
*/
57+
public static Vector vector(Document document) {
58+
return Vector.newBuilder().setDocument(document).build();
59+
}
60+
61+
/**
62+
* Creates a vector from an image for cloud inference.
63+
*
64+
* @param image The image to vectorize.
65+
* @return A new instance of {@link Vector}
66+
*/
67+
public static Vector vector(Image image) {
68+
return Vector.newBuilder().setImage(image).build();
69+
}
70+
71+
/**
72+
* Creates a vector from an inference object.
73+
*
74+
* @param object The inference object to vectorize.
75+
* @return A new instance of {@link Vector}
76+
*/
77+
public static Vector vector(InferenceObject object) {
78+
return Vector.newBuilder().setObject(object).build();
79+
}
80+
4881
/**
4982
* Creates a multi vector from a nested list of floats
5083
*

src/main/java/io/qdrant/client/VectorInputFactory.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import com.google.common.primitives.Floats;
66
import io.qdrant.client.grpc.Points.DenseVector;
7+
import io.qdrant.client.grpc.Points.Document;
8+
import io.qdrant.client.grpc.Points.Image;
9+
import io.qdrant.client.grpc.Points.InferenceObject;
710
import io.qdrant.client.grpc.Points.MultiDenseVector;
811
import io.qdrant.client.grpc.Points.PointId;
912
import io.qdrant.client.grpc.Points.SparseVector;
@@ -114,33 +117,33 @@ public static VectorInput vectorInput(PointId id) {
114117
return VectorInput.newBuilder().setId(id).build();
115118
}
116119

117-
// /**
118-
// * Creates a {@link VectorInput} from a {@link Document}
119-
// *
120-
// * @param document An instance of {@link Document}
121-
// * @return a new instance of {@link VectorInput}
122-
// */
123-
// public static VectorInput vectorInput(Document document) {
124-
// return VectorInput.newBuilder().setDocument(document).build();
125-
// }
120+
/**
121+
* Creates a {@link VectorInput} from a {@link Document}
122+
*
123+
* @param document An instance of {@link Document}
124+
* @return a new instance of {@link VectorInput}
125+
*/
126+
public static VectorInput vectorInput(Document document) {
127+
return VectorInput.newBuilder().setDocument(document).build();
128+
}
126129

127-
// /**
128-
// * Creates a {@link VectorInput} from a an {@link Image}
129-
// *
130-
// * @param image An instance of {@link Image}
131-
// * @return a new instance of {@link VectorInput}
132-
// */
133-
// public static VectorInput vectorInput(Image image) {
134-
// return VectorInput.newBuilder().setImage(image).build();
135-
// }
130+
/**
131+
* Creates a {@link VectorInput} from a an {@link Image}
132+
*
133+
* @param image An instance of {@link Image}
134+
* @return a new instance of {@link VectorInput}
135+
*/
136+
public static VectorInput vectorInput(Image image) {
137+
return VectorInput.newBuilder().setImage(image).build();
138+
}
136139

137-
// /**
138-
// * Creates a {@link VectorInput} from a {@link InferenceObject}
139-
// *
140-
// * @param object An instance of {@link InferenceObject}
141-
// * @return a new instance of {@link VectorInput}
142-
// */
143-
// public static VectorInput vectorInput(InferenceObject object) {
144-
// return VectorInput.newBuilder().setObject(object).build();
145-
// }
140+
/**
141+
* Creates a {@link VectorInput} from a {@link InferenceObject}
142+
*
143+
* @param object An instance of {@link InferenceObject}
144+
* @return a new instance of {@link VectorInput}
145+
*/
146+
public static VectorInput vectorInput(InferenceObject object) {
147+
return VectorInput.newBuilder().setObject(object).build();
148+
}
146149
}

src/main/java/io/qdrant/client/VectorsFactory.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import static io.qdrant.client.VectorFactory.vector;
44

5+
import io.qdrant.client.grpc.Points.Document;
6+
import io.qdrant.client.grpc.Points.Image;
7+
import io.qdrant.client.grpc.Points.InferenceObject;
58
import io.qdrant.client.grpc.Points.NamedVectors;
69
import io.qdrant.client.grpc.Points.Vector;
710
import io.qdrant.client.grpc.Points.Vectors;
@@ -51,4 +54,34 @@ public static Vectors vectors(float... values) {
5154
public static Vectors vectors(Vector vector) {
5255
return Vectors.newBuilder().setVector(vector).build();
5356
}
57+
58+
/**
59+
* Creates an instance of {@link Vectors} from a document for cloud inference.
60+
*
61+
* @param document An instance of {@link Document}
62+
* @return a new instance of {@link Vectors}
63+
*/
64+
public static Vectors vectors(Document document) {
65+
return Vectors.newBuilder().setVector(vector(document)).build();
66+
}
67+
68+
/**
69+
* Creates an instance of {@link Vectors} from an image for cloud inference.
70+
*
71+
* @param image An instance of {@link Image}
72+
* @return a new instance of {@link Vectors}
73+
*/
74+
public static Vectors vectors(Image image) {
75+
return Vectors.newBuilder().setVector(vector(image)).build();
76+
}
77+
78+
/**
79+
* Creates an instance of {@link Vectors} from an inference object.
80+
*
81+
* @param object The inference object to vectorize.
82+
* @return A new instance of {@link Vectors}
83+
*/
84+
public static Vectors vectors(InferenceObject object) {
85+
return Vectors.newBuilder().setVector(vector(object)).build();
86+
}
5487
}

0 commit comments

Comments
 (0)