Skip to content

Commit 9c22d53

Browse files
committed
feature #620 [Demo] Leverage Vectorizer in QueryCommand (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Demo] Leverage `Vectorizer` in `QueryCommand` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | Replaces #619 | License | MIT Replace direct platform usage with `VectorizerInterface` injection using the `#[Autowire]` attribute for cleaner dependency management and better separation of concerns. Commits ------- 981ee06 [Demo] Leverage `Vectorizer` in `QueryCommand`
2 parents 937730c + 981ee06 commit 9c22d53

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)