Skip to content

Commit 981ee06

Browse files
committed
[Demo] Leverage Vectorizer in QueryCommand
1 parent 937730c commit 981ee06

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

demo/src/Blog/Command/QueryCommand.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
namespace App\Blog\Command;
1313

1414
use Codewithkyrian\ChromaDB\Client;
15-
use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
16-
use Symfony\AI\Platform\PlatformInterface;
15+
use Symfony\AI\Store\Document\VectorizerInterface;
1716
use Symfony\Component\Console\Attribute\AsCommand;
1817
use Symfony\Component\Console\Command\Command;
1918
use 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

Comments
 (0)