Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
52.50% |
21 / 40 |
|
30.77% |
8 / 26 |
CRAP | |
0.00% |
0 / 1 |
| Pinecone | |
52.50% |
21 / 40 |
|
30.77% |
8 / 26 |
98.45 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| inference | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| assistant | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| listIndexes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createForModel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| describeIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| deleteIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| configureIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createCollection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| listCollections | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describeCollection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteCollection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createBackup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| listBackups | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describeBackup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteBackup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| listRestoreJobs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describeRestoreJob | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createAssistant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| listAssistants | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describeAssistant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| updateAssistant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteAssistant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildIndexHost | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Mbvb1223\Pinecone; |
| 6 | |
| 7 | use GuzzleHttp\Client; |
| 8 | use Mbvb1223\Pinecone\Control\ControlPlane; |
| 9 | use Mbvb1223\Pinecone\Data\Index; |
| 10 | use Mbvb1223\Pinecone\Inference\InferenceClient; |
| 11 | use Mbvb1223\Pinecone\Assistant\AssistantClient; |
| 12 | use Mbvb1223\Pinecone\Utils\Configuration; |
| 13 | |
| 14 | class Pinecone |
| 15 | { |
| 16 | private Configuration $config; |
| 17 | private ControlPlane $controlPlane; |
| 18 | |
| 19 | public function __construct(?string $apiKey = null, ?array $config = null) |
| 20 | { |
| 21 | $this->config = new Configuration($apiKey, $config); |
| 22 | $client = new Client([ |
| 23 | 'base_uri' => $this->config->getControllerHost(), |
| 24 | 'timeout' => $this->config->getTimeout(), |
| 25 | 'headers' => $this->config->getDefaultHeaders(), |
| 26 | ]); |
| 27 | $this->controlPlane = new ControlPlane($client); |
| 28 | } |
| 29 | |
| 30 | // ===== Factory methods to get sub-components ===== |
| 31 | public function index(string $name): Index |
| 32 | { |
| 33 | $indexInfo = $this->describeIndex($name); |
| 34 | $host = $indexInfo['host'] ?? $this->buildIndexHost($indexInfo['name']); |
| 35 | $client = new Client([ |
| 36 | 'base_uri' => "https://{$host}", |
| 37 | 'timeout' => $this->config->getTimeout(), |
| 38 | 'headers' => $this->config->getDefaultHeaders(), |
| 39 | ]); |
| 40 | |
| 41 | return new Index($client); |
| 42 | } |
| 43 | |
| 44 | public function inference(): InferenceClient |
| 45 | { |
| 46 | return new InferenceClient($this->config); |
| 47 | } |
| 48 | |
| 49 | public function assistant(string $name): AssistantClient |
| 50 | { |
| 51 | $assistantInfo = $this->describeAssistant($name); |
| 52 | |
| 53 | return new AssistantClient($this->config, $assistantInfo); |
| 54 | } |
| 55 | |
| 56 | // ===== Index control plane methods ===== |
| 57 | public function listIndexes(): array |
| 58 | { |
| 59 | return $this->controlPlane->listIndexes(); |
| 60 | } |
| 61 | |
| 62 | public function createIndex(string $name, array $requestData): array |
| 63 | { |
| 64 | return $this->controlPlane->createIndex($name, $requestData); |
| 65 | } |
| 66 | |
| 67 | public function createForModel(string $name, array $requestData): array |
| 68 | { |
| 69 | return $this->controlPlane->createForModel($name, $requestData); |
| 70 | } |
| 71 | |
| 72 | public function describeIndex(string $name): array |
| 73 | { |
| 74 | return $this->controlPlane->describeIndex($name); |
| 75 | } |
| 76 | |
| 77 | public function deleteIndex(string $name): void |
| 78 | { |
| 79 | $this->controlPlane->deleteIndex($name); |
| 80 | } |
| 81 | |
| 82 | public function configureIndex(string $name, array $requestData): array |
| 83 | { |
| 84 | return $this->controlPlane->configureIndex($name, $requestData); |
| 85 | } |
| 86 | |
| 87 | // ===== Collection control plane methods ===== |
| 88 | public function createCollection(array $config): array |
| 89 | { |
| 90 | return $this->controlPlane->createCollection($config); |
| 91 | } |
| 92 | |
| 93 | public function listCollections(): array |
| 94 | { |
| 95 | return $this->controlPlane->listCollections(); |
| 96 | } |
| 97 | |
| 98 | public function describeCollection(string $name): array |
| 99 | { |
| 100 | return $this->controlPlane->describeCollection($name); |
| 101 | } |
| 102 | |
| 103 | public function deleteCollection(string $name): void |
| 104 | { |
| 105 | $this->controlPlane->deleteCollection($name); |
| 106 | } |
| 107 | |
| 108 | // ===== Backup control plane methods ===== |
| 109 | public function createBackup(array $config): array |
| 110 | { |
| 111 | return $this->controlPlane->createBackup($config); |
| 112 | } |
| 113 | |
| 114 | public function listBackups(): array |
| 115 | { |
| 116 | return $this->controlPlane->listBackups(); |
| 117 | } |
| 118 | |
| 119 | public function describeBackup(string $id): array |
| 120 | { |
| 121 | return $this->controlPlane->describeBackup($id); |
| 122 | } |
| 123 | |
| 124 | public function deleteBackup(string $id): void |
| 125 | { |
| 126 | $this->controlPlane->deleteBackup($id); |
| 127 | } |
| 128 | |
| 129 | // ===== Restore control plane methods ===== |
| 130 | public function listRestoreJobs(array $params = []): array |
| 131 | { |
| 132 | return $this->controlPlane->listRestoreJobs($params); |
| 133 | } |
| 134 | |
| 135 | public function describeRestoreJob(string $id): array |
| 136 | { |
| 137 | return $this->controlPlane->describeRestoreJob($id); |
| 138 | } |
| 139 | |
| 140 | // ===== Assistant control plane methods ===== |
| 141 | public function createAssistant(array $config): array |
| 142 | { |
| 143 | return $this->controlPlane->createAssistant($config); |
| 144 | } |
| 145 | |
| 146 | public function listAssistants(): array |
| 147 | { |
| 148 | return $this->controlPlane->listAssistants(); |
| 149 | } |
| 150 | |
| 151 | public function describeAssistant(string $name): array |
| 152 | { |
| 153 | return $this->controlPlane->describeAssistant($name); |
| 154 | } |
| 155 | |
| 156 | public function updateAssistant(string $name, array $config): array |
| 157 | { |
| 158 | return $this->controlPlane->updateAssistant($name, $config); |
| 159 | } |
| 160 | |
| 161 | public function deleteAssistant(string $name): void |
| 162 | { |
| 163 | $this->controlPlane->deleteAssistant($name); |
| 164 | } |
| 165 | |
| 166 | private function buildIndexHost(string $indexName): string |
| 167 | { |
| 168 | return "{$indexName}-{$this->config->getEnvironment()}.svc.{$this->config->getEnvironment()}.pinecone.io"; |
| 169 | } |
| 170 | } |