|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\AI\Store\Bridge\Pinecone; |
| 13 | + |
| 14 | +use Probots\Pinecone\Client; |
| 15 | +use Symfony\AI\Store\Exception\RuntimeException; |
| 16 | +use Symfony\AI\Store\ManagedStoreInterface; |
| 17 | + |
| 18 | +final class ManagedStore implements ManagedStoreInterface |
| 19 | +{ |
| 20 | + public function __construct( |
| 21 | + private readonly Client $pinecone, |
| 22 | + private readonly string $indexName, |
| 23 | + private readonly int $dimension, |
| 24 | + private readonly string $metric, |
| 25 | + private readonly string $cloud, |
| 26 | + private readonly string $region, |
| 27 | + ) { |
| 28 | + if (!class_exists(Client::class)) { |
| 29 | + throw new RuntimeException('For using the Pinecone as retrieval vector store, the probots-io/pinecone-php package is required. Try running "composer require probots-io/pinecone-php".'); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + public function setup(array $options = []): void |
| 34 | + { |
| 35 | + $this->pinecone |
| 36 | + ->control() |
| 37 | + ->index($this->indexName) |
| 38 | + ->createServerless($this->dimension, $this->metric, $this->cloud, $this->region); |
| 39 | + } |
| 40 | + |
| 41 | + public function drop(): void |
| 42 | + { |
| 43 | + $this->pinecone |
| 44 | + ->control() |
| 45 | + ->index($this->indexName) |
| 46 | + ->delete(); |
| 47 | + } |
| 48 | +} |
0 commit comments