From 2d5909ccf2e2bd4dbe23a77e45fa21c246455925 Mon Sep 17 00:00:00 2001 From: Pauline Vos Date: Mon, 27 Oct 2025 17:00:55 +0100 Subject: [PATCH] Support `string|object` for `getContent` method As the Vectorizer currently makes assumptions about having to pass string data to `PlatformInterface::invoke`, when that method can actually take about any sort of input. `Platform` implementations decide what data types they can handle through their normalizers. Therefore, it should be up to `platform` to handle types and not up to `store` to decide that it should only pass strings. --- .../src/Document/EmbeddableDocumentInterface.php | 2 +- src/store/src/Document/Vectorizer.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/store/src/Document/EmbeddableDocumentInterface.php b/src/store/src/Document/EmbeddableDocumentInterface.php index 672ae4a30..6397bc5a3 100644 --- a/src/store/src/Document/EmbeddableDocumentInterface.php +++ b/src/store/src/Document/EmbeddableDocumentInterface.php @@ -15,7 +15,7 @@ interface EmbeddableDocumentInterface { public function getId(): mixed; - public function getContent(): string; + public function getContent(): string|object; public function getMetadata(): Metadata; } diff --git a/src/store/src/Document/Vectorizer.php b/src/store/src/Document/Vectorizer.php index f6b6490c7..678724c1e 100644 --- a/src/store/src/Document/Vectorizer.php +++ b/src/store/src/Document/Vectorizer.php @@ -14,6 +14,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\AI\Platform\Capability; +use Symfony\AI\Platform\Exception\ExceptionInterface; use Symfony\AI\Platform\PlatformInterface; use Symfony\AI\Platform\Vector\Vector; use Symfony\AI\Store\Exception\RuntimeException; @@ -75,6 +76,8 @@ private function validateArray(array $values, string $expectedType): void /** * @param array $options + * + * @throws ExceptionInterface */ private function vectorizeString(string|\Stringable $string, array $options = []): Vector { @@ -93,14 +96,20 @@ private function vectorizeString(string|\Stringable $string, array $options = [] /** * @param array $options + * + * @throws ExceptionInterface */ private function vectorizeEmbeddableDocument(EmbeddableDocumentInterface $document, array $options = []): VectorDocument { $this->logger->debug('Vectorizing embeddable document', ['document_id' => $document->getId()]); + $result = $this->platform->invoke($this->model, $document->getContent(), $options); + $vectors = $result->asVectors(); - $vector = $this->vectorizeString($document->getContent(), $options); + if (!isset($vectors[0])) { + throw new RuntimeException('No vector returned for vectorization.'); + } - return new VectorDocument($document->getId(), $vector, $document->getMetadata()); + return new VectorDocument($document->getId(), $vectors[0], $document->getMetadata()); } /**