Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Vector | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Mbvb1223\Pinecone\Data\Vectors; |
| 6 | |
| 7 | class Vector |
| 8 | { |
| 9 | /** |
| 10 | * @param array<float> $values |
| 11 | * @param array<string, mixed>|null $metadata |
| 12 | * @param array{indices: array<int>, values: array<float>}|null $sparseValues |
| 13 | */ |
| 14 | public function __construct( |
| 15 | public readonly string $id, |
| 16 | public readonly array $values, |
| 17 | public readonly ?array $metadata = null, |
| 18 | public readonly ?array $sparseValues = null, |
| 19 | ) { |
| 20 | } |
| 21 | |
| 22 | /** @return array<string, mixed> */ |
| 23 | public function toArray(): array |
| 24 | { |
| 25 | $data = ['id' => $this->id, 'values' => $this->values]; |
| 26 | if ($this->metadata !== null) { |
| 27 | $data['metadata'] = $this->metadata; |
| 28 | } |
| 29 | if ($this->sparseValues !== null) { |
| 30 | $data['sparseValues'] = $this->sparseValues; |
| 31 | } |
| 32 | |
| 33 | return $data; |
| 34 | } |
| 35 | } |