1212namespace App \Blog \Command ;
1313
1414use Codewithkyrian \ChromaDB \Client ;
15- use Symfony \AI \Platform \Bridge \OpenAi \Embeddings ;
16- use Symfony \AI \Platform \PlatformInterface ;
15+ use Symfony \AI \Store \Document \VectorizerInterface ;
1716use Symfony \Component \Console \Attribute \AsCommand ;
1817use Symfony \Component \Console \Command \Command ;
1918use Symfony \Component \Console \Style \SymfonyStyle ;
19+ use Symfony \Component \DependencyInjection \Attribute \Autowire ;
2020
2121#[AsCommand('app:blog:query ' , description: 'Test command for querying the blog collection in Chroma DB. ' )]
22- final class QueryCommand
22+ final readonly class QueryCommand
2323{
2424 public function __construct (
25- private readonly Client $ chromaClient ,
26- private readonly PlatformInterface $ platform ,
25+ private Client $ chromaClient ,
26+ #[Autowire(service: 'ai.vectorizer.openai ' )]
27+ private VectorizerInterface $ vectorizer ,
2728 ) {
2829 }
2930
@@ -44,9 +45,9 @@ public function __invoke(SymfonyStyle $io): int
4445 $ io ->comment (\sprintf ('Converting "%s" to vector & searching in Chroma DB ... ' , $ search ));
4546 $ io ->comment ('Results are limited to 4 most similar documents. ' );
4647
47- $ platformResponse = $ this ->platform -> invoke ( new Embeddings (Embeddings:: TEXT_3_SMALL ), $ search );
48+ $ vector = $ this ->vectorizer -> vectorize ( $ search );
4849 $ queryResponse = $ collection ->query (
49- queryEmbeddings: [$ platformResponse -> asVectors ()[ 0 ] ->getData ()],
50+ queryEmbeddings: [$ vector ->getData ()],
5051 nResults: 4 ,
5152 );
5253
0 commit comments