Skip to content

Commit 3206ead

Browse files
committed
Support mixed 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.
1 parent 2ddd2b3 commit 3206ead

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/store/src/Document/EmbeddableDocumentInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface EmbeddableDocumentInterface
1515
{
1616
public function getId(): mixed;
1717

18-
public function getContent(): string;
18+
public function getContent(): mixed;
1919

2020
public function getMetadata(): Metadata;
2121
}

src/store/src/Document/Vectorizer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ private function vectorizeString(string|\Stringable $string, array $options = []
9797
private function vectorizeEmbeddableDocument(EmbeddableDocumentInterface $document, array $options = []): VectorDocument
9898
{
9999
$this->logger->debug('Vectorizing embeddable document', ['document_id' => $document->getId()]);
100+
$vectors = $this->platform->invoke($this->model, $document->getContent(), $options);
100101

101-
$vector = $this->vectorizeString($document->getContent(), $options);
102+
if (!isset($vectors[0])) {
103+
throw new RuntimeException('No vector returned for vectorization.');
104+
}
102105

103-
return new VectorDocument($document->getId(), $vector, $document->getMetadata());
106+
return new VectorDocument($document->getId(), $vectors[0], $document->getMetadata());
104107
}
105108

106109
/**

0 commit comments

Comments
 (0)