From 981ee06162e403d4fd7c8a4bb37f9a9e88b23687 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 17 Sep 2025 13:19:32 +0200 Subject: [PATCH] [Demo] Leverage `Vectorizer` in `QueryCommand` --- demo/src/Blog/Command/QueryCommand.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/demo/src/Blog/Command/QueryCommand.php b/demo/src/Blog/Command/QueryCommand.php index 82c2ad67d..e6472c107 100644 --- a/demo/src/Blog/Command/QueryCommand.php +++ b/demo/src/Blog/Command/QueryCommand.php @@ -12,18 +12,19 @@ namespace App\Blog\Command; use Codewithkyrian\ChromaDB\Client; -use Symfony\AI\Platform\Bridge\OpenAi\Embeddings; -use Symfony\AI\Platform\PlatformInterface; +use Symfony\AI\Store\Document\VectorizerInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\Attribute\Autowire; #[AsCommand('app:blog:query', description: 'Test command for querying the blog collection in Chroma DB.')] -final class QueryCommand +final readonly class QueryCommand { public function __construct( - private readonly Client $chromaClient, - private readonly PlatformInterface $platform, + private Client $chromaClient, + #[Autowire(service: 'ai.vectorizer.openai')] + private VectorizerInterface $vectorizer, ) { } @@ -44,9 +45,9 @@ public function __invoke(SymfonyStyle $io): int $io->comment(\sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search)); $io->comment('Results are limited to 4 most similar documents.'); - $platformResponse = $this->platform->invoke(new Embeddings(Embeddings::TEXT_3_SMALL), $search); + $vector = $this->vectorizer->vectorize($search); $queryResponse = $collection->query( - queryEmbeddings: [$platformResponse->asVectors()[0]->getData()], + queryEmbeddings: [$vector->getData()], nResults: 4, );