-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: targetVectorFactory, VectorFactory
- Loading branch information
Showing
3 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.qdrant.client; | ||
|
||
import io.qdrant.client.grpc.Points.PointId; | ||
import io.qdrant.client.grpc.Points.TargetVector; | ||
import io.qdrant.client.grpc.Points.Vector; | ||
import io.qdrant.client.grpc.Points.VectorExample; | ||
|
||
/** | ||
* Convenience methods for constructing {@link TargetVector} | ||
*/ | ||
public class TargetVectorFactory { | ||
private TargetVectorFactory() { | ||
} | ||
|
||
/** | ||
* Creates a TargetVector from a point ID | ||
* @param id The point ID to use | ||
* @return A new instance of {@link TargetVector} | ||
*/ | ||
public static TargetVector targetVector(PointId id) { | ||
return TargetVector.newBuilder().setSingle(VectorExample.newBuilder().setId(id)).build(); | ||
} | ||
|
||
/** | ||
* Creates a TargetVector from a Vector | ||
* @param vector The Vector value to use | ||
* @return A new instance of {@link TargetVector} | ||
*/ | ||
public static TargetVector targetVector(Vector vector) { | ||
return TargetVector.newBuilder().setSingle(VectorExample.newBuilder().setVector(vector)).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.qdrant.client; | ||
|
||
import com.google.common.primitives.Floats; | ||
|
||
import java.util.List; | ||
|
||
import static io.qdrant.client.grpc.Points.SparseIndices; | ||
import static io.qdrant.client.grpc.Points.Vector; | ||
|
||
/** | ||
* Convenience methods for constructing {@link Vector} | ||
*/ | ||
public final class VectorFactory { | ||
private VectorFactory() { | ||
} | ||
|
||
/** | ||
* Creates a vector from a list of floats | ||
* | ||
* @param values A map of vector names to values | ||
* @return A new instance of {@link Vector} | ||
*/ | ||
public static Vector vector(List<Float> values) { | ||
return Vector.newBuilder().addAllData(values).build(); | ||
} | ||
|
||
/** | ||
* Creates a vector from a list of floats | ||
* | ||
* @param values A list of values | ||
* @return A new instance of {@link Vector} | ||
*/ | ||
public static Vector vector(float... values) { | ||
return Vector.newBuilder() | ||
.addAllData(Floats.asList(values)) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Creates a sparse vector from a list of floats and integers as indices | ||
* | ||
* @param vector The list of floats representing the vector. | ||
* @param indices The list of integers representing the indices. | ||
* @return A new instance of {@link Vector} | ||
*/ | ||
public static Vector vector(List<Float> vector, List<Integer> indices) { | ||
return Vector.newBuilder() | ||
.addAllData(vector) | ||
.setIndices(SparseIndices.newBuilder().addAllData(indices).build()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters