|
3 | 3 | namespace Upstash\Vector\Operations; |
4 | 4 |
|
5 | 5 | use Upstash\Vector\Contracts\TransporterInterface; |
| 6 | +use Upstash\Vector\DenseIndexInfo; |
| 7 | +use Upstash\Vector\Enums\IndexType; |
6 | 8 | use Upstash\Vector\IndexInfo; |
7 | 9 | use Upstash\Vector\NamespaceInfo; |
8 | 10 | use Upstash\Vector\Operations\Concerns\AssertsApiResponseErrors; |
| 11 | +use Upstash\Vector\SparseIndexInfo; |
9 | 12 | use Upstash\Vector\Transporter\ContentType; |
10 | 13 | use Upstash\Vector\Transporter\Method; |
11 | 14 | use Upstash\Vector\Transporter\TransporterRequest; |
@@ -55,6 +58,31 @@ private function transformResponse(TransporterResponse $response): IndexInfo |
55 | 58 | dimension: $result['dimension'], |
56 | 59 | similarityFunction: $result['similarityFunction'], |
57 | 60 | namespaces: $namespaces, |
| 61 | + indexType: IndexType::tryFrom($result['indexType'] ?? '') ?? IndexType::UNKNOWN, |
| 62 | + denseIndex: isset($result['denseIndex']) ? $this->transformDenseIndex($result['denseIndex']) : null, |
| 63 | + sparseIndex: isset($result['sparseIndex']) ? $this->transformSparseIndex($result['sparseIndex']) : null, |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @param array<string, mixed> $data |
| 69 | + */ |
| 70 | + private function transformDenseIndex(array $data): DenseIndexInfo |
| 71 | + { |
| 72 | + return new DenseIndexInfo( |
| 73 | + dimension: $data['dimension'] ?? 0, |
| 74 | + similarityFunction: $data['similarityFunction'] ?? '', |
| 75 | + embeddingModel: $data['embeddingModel'] ?? '', |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @param array<string, mixed> $data |
| 81 | + */ |
| 82 | + private function transformSparseIndex(array $data): SparseIndexInfo |
| 83 | + { |
| 84 | + return new SparseIndexInfo( |
| 85 | + embeddingModel: $data['embeddingModel'] ?? '', |
58 | 86 | ); |
59 | 87 | } |
60 | 88 | } |
0 commit comments