Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/store/src/Document/EmbeddableDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface EmbeddableDocumentInterface
{
public function getId(): mixed;

public function getContent(): string;
public function getContent(): string|object;

public function getMetadata(): Metadata;
}
13 changes: 11 additions & 2 deletions src/store/src/Document/Vectorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +76,8 @@ private function validateArray(array $values, string $expectedType): void

/**
* @param array<string, mixed> $options
*
* @throws ExceptionInterface
*/
private function vectorizeString(string|\Stringable $string, array $options = []): Vector
{
Expand All @@ -93,14 +96,20 @@ private function vectorizeString(string|\Stringable $string, array $options = []

/**
* @param array<string, mixed> $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());
}

/**
Expand Down