Skip to content
Open
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;
}
21 changes: 15 additions & 6 deletions src/store/src/Document/Vectorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
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;

final readonly class Vectorizer implements VectorizerInterface
final class Vectorizer implements VectorizerInterface
{
public function __construct(
private PlatformInterface $platform,
private string $model,
private LoggerInterface $logger = new NullLogger(),
private readonly PlatformInterface $platform,
private readonly string $model,
private readonly LoggerInterface $logger = new NullLogger(),
) {
}
Comment on lines -21 to 29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit confused about this diff, since it is already fixed on main with #829

final class Vectorizer implements VectorizerInterface
{
public function __construct(
private readonly PlatformInterface $platform,
private readonly string $model,
private readonly LoggerInterface $logger = new NullLogger(),
) {
}


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