11package io .weaviate .client6 .v1 .api .collections ;
22
33import java .io .IOException ;
4+ import java .util .Arrays ;
45import java .util .Collections ;
56import java .util .HashMap ;
67import java .util .Map ;
1516import com .google .gson .stream .JsonReader ;
1617import com .google .gson .stream .JsonWriter ;
1718
18- import io .weaviate .client6 .v1 .internal .ObjectBuilder ;
19- import lombok .ToString ;
20-
2119/**
2220 * Vectors is an abstraction over named vectors, which can store
2321 * both 1-dimensional and 2-dimensional vectors.
2422 */
25- @ ToString
2623public class Vectors {
2724 /** Elements of this map must only be {@code float[]} or {@code float[][]}. */
28- private final Map <String , Object > namedVectors ;
25+ private final Map <String , Object > vectorsMap ;
2926
3027 /** Create a 1-dimensional vector. */
3128 public static Vectors of (float [] vector ) {
@@ -58,7 +55,7 @@ public static Vectors of(String name, float[][] vector) {
5855 * @param vector {@code float[]} or {@code float[][]} vector.
5956 */
6057 private Vectors (String name , Object vector ) {
61- this .namedVectors = Collections .singletonMap (name , vector );
58+ this .vectorsMap = Collections .singletonMap (name , vector );
6259 }
6360
6461 /**
@@ -72,7 +69,7 @@ private Vectors(String name, Object vector) {
7269 * @param vector Map of named vectors.
7370 */
7471 private Vectors (Map <String , Object > namedVectors ) {
75- this .namedVectors = namedVectors ;
72+ this .vectorsMap = namedVectors ;
7673 }
7774
7875 /** Merge all vectors in a single vector map. */
@@ -81,7 +78,7 @@ public Vectors(Vectors... vectors) {
8178 for (var vec : vectors ) {
8279 namedVectors .putAll (vec .asMap ());
8380 }
84- this .namedVectors = namedVectors ;
81+ this .vectorsMap = namedVectors ;
8582 }
8683
8784 /**
@@ -91,7 +88,7 @@ public Vectors(Vectors... vectors) {
9188 * @throws ClassCastException The underlying vector is not a {@code float[]}.
9289 */
9390 public float [] getSingle (String name ) {
94- return (float []) namedVectors .get (name );
91+ return (float []) vectorsMap .get (name );
9592 }
9693
9794 /**
@@ -112,7 +109,7 @@ public float[] getDefaultSingle() {
112109 * {@code float[][]}.
113110 */
114111 public float [][] getMulti (String name ) {
115- return (float [][]) namedVectors .get (name );
112+ return (float [][]) vectorsMap .get (name );
116113 }
117114
118115 /**
@@ -134,7 +131,22 @@ public float[][] getDefaultMulti() {
134131 * @return Map of name-vector pairs. The returned map is immutable.
135132 */
136133 public Map <String , Object > asMap () {
137- return Map .copyOf (namedVectors );
134+ return Map .copyOf (vectorsMap );
135+ }
136+
137+ @ Override
138+ public String toString () {
139+ var vectorStrings = vectorsMap .entrySet ().stream ()
140+ .map (v -> {
141+ var name = v .getKey ();
142+ var value = v .getValue ();
143+ var array = (value instanceof float [] f )
144+ ? Arrays .toString ((float []) value )
145+ : Arrays .deepToString ((float [][]) value );
146+ return "%s=%s" .formatted (name , array );
147+ })
148+ .toList ();
149+ return "Vectors(%s)" .formatted (String .join (", " , vectorStrings ));
138150 }
139151
140152 public static enum CustomTypeAdapterFactory implements TypeAdapterFactory {
@@ -154,7 +166,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
154166
155167 @ Override
156168 public void write (JsonWriter out , Vectors value ) throws IOException {
157- mapAdapter .write (out , value .namedVectors );
169+ mapAdapter .write (out , value .vectorsMap );
158170 }
159171
160172 @ Override
0 commit comments