@@ -15,12 +15,11 @@ class PointStruct
1515{
1616 use ProtectedPropertyAccessor;
1717
18- // TODO: we need a solution for point with uuid
1918 protected int |string $ id ;
2019 protected ?array $ payload = null ;
21- protected VectorStruct $ vector ;
20+ protected VectorStructInterface $ vector ;
2221
23- public function __construct (int |string $ id , VectorStruct $ vector , array $ payload = null )
22+ public function __construct (int |string $ id , VectorStructInterface $ vector , array $ payload = null )
2423 {
2524 $ this ->id = $ id ;
2625 $ this ->vector = $ vector ;
@@ -33,9 +32,17 @@ public static function createFromArray(array $pointArray): PointStruct
3332 if (count (array_intersect_key (array_flip ($ required ), $ pointArray )) !== count ($ required )) {
3433 throw new InvalidArgumentException ('Missing point keys ' );
3534 }
35+
3636 $ vector = $ pointArray ['vector ' ];
37- if (is_array ($ pointArray ['vector ' ])) {
38- $ vector = new VectorStruct ($ pointArray ['vector ' ], $ pointArray ['name ' ] ?? null );
37+
38+ // Check if it's an array and convert it to a VectorStruct
39+ if (is_array ($ vector )) {
40+ $ vector = new VectorStruct ($ vector , $ pointArray ['name ' ] ?? null );
41+ }
42+
43+ // Check if it's already a VectorStruct or MultiVectorStruct
44+ if (!($ vector instanceof VectorStructInterface)) {
45+ throw new InvalidArgumentException ('Invalid vector type ' );
3946 }
4047
4148 return new PointStruct ($ pointArray ['id ' ], $ vector , $ pointArray ['payload ' ] ?? null );
@@ -55,26 +62,17 @@ public function toArray(): array
5562 return $ point ;
5663 }
5764
58- /**
59- * @return int
60- */
6165 public function getId (): int |string
6266 {
6367 return $ this ->id ;
6468 }
6569
66- /**
67- * @return array|null
68- */
6970 public function getPayload (): ?array
7071 {
7172 return $ this ->payload ;
7273 }
7374
74- /**
75- * @return VectorStruct
76- */
77- public function getVector (): VectorStruct
75+ public function getVector (): VectorStructInterface
7876 {
7977 return $ this ->vector ;
8078 }
0 commit comments