|
18 | 18 | use Symfony\AI\Platform\Vector\Vector; |
19 | 19 | use Symfony\AI\Store\Exception\RuntimeException; |
20 | 20 |
|
21 | | -final readonly class Vectorizer implements VectorizerInterface |
| 21 | +final class Vectorizer implements VectorizerInterface |
22 | 22 | { |
23 | 23 | public function __construct( |
24 | | - private PlatformInterface $platform, |
25 | | - private string $model, |
26 | | - private LoggerInterface $logger = new NullLogger(), |
| 24 | + private readonly PlatformInterface $platform, |
| 25 | + private readonly string $model, |
| 26 | + private readonly LoggerInterface $logger = new NullLogger(), |
27 | 27 | ) { |
28 | 28 | } |
29 | 29 |
|
@@ -97,10 +97,13 @@ private function vectorizeString(string|\Stringable $string, array $options = [] |
97 | 97 | private function vectorizeEmbeddableDocument(EmbeddableDocumentInterface $document, array $options = []): VectorDocument |
98 | 98 | { |
99 | 99 | $this->logger->debug('Vectorizing embeddable document', ['document_id' => $document->getId()]); |
| 100 | + $vectors = $this->platform->invoke($this->model, $document->getContent(), $options); |
100 | 101 |
|
101 | | - $vector = $this->vectorizeString($document->getContent(), $options); |
| 102 | + if (!isset($vectors[0])) { |
| 103 | + throw new RuntimeException('No vector returned for vectorization.'); |
| 104 | + } |
102 | 105 |
|
103 | | - return new VectorDocument($document->getId(), $vector, $document->getMetadata()); |
| 106 | + return new VectorDocument($document->getId(), $vectors[0], $document->getMetadata()); |
104 | 107 | } |
105 | 108 |
|
106 | 109 | /** |
|
0 commit comments