Files
MtoRagSystem/src/Command/TestVectorCommand.php
2026-02-22 08:35:13 +01:00

79 lines
2.6 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Command;
use App\Vector\VectorSearchClient;
use App\Tag\TagVectorSearchClient;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'mto:agent:test-vector')]
final class TestVectorCommand extends Command
{
public function __construct(
private readonly VectorSearchClient $vectorSearchClient,
private readonly TagVectorSearchClient $tagVectorSearchClient,
) {
parent::__construct();
}
protected function configure(): void
{
$this->addArgument(
'prompt',
InputArgument::REQUIRED,
'User prompt (realistic retrieval test)'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$prompt = (string) $input->getArgument('prompt');
$limit = 8;
$output->writeln('');
$output->writeln('<info>Prompt:</info> ' . $prompt);
$output->writeln('');
$totalStart = microtime(true);
// ----------------------------
// 1⃣ Tag Routing Phase
// ----------------------------
$tagStart = microtime(true);
$tagResults = $this->tagVectorSearchClient->search($prompt, $limit);
$tagDuration = (microtime(true) - $tagStart) * 1000;
// ----------------------------
// 2⃣ Chunk Retrieval Phase
// ----------------------------
$chunkStart = microtime(true);
$chunkResults = $this->vectorSearchClient->search($prompt, $limit);
$chunkDuration = (microtime(true) - $chunkStart) * 1000;
$totalDuration = (microtime(true) - $totalStart) * 1000;
// ----------------------------
// Output
// ----------------------------
$output->writeln('<comment>Tag Routing Time:</comment> ' . round($tagDuration, 2) . ' ms');
$output->writeln('<comment>Chunk Retrieval Time:</comment> ' . round($chunkDuration, 2) . ' ms');
$output->writeln('<comment>Total Retrieval Time:</comment> ' . round($totalDuration, 2) . ' ms');
$output->writeln('');
$output->writeln('--- Tag Results ---');
$output->writeln(json_encode($tagResults, JSON_PRETTY_PRINT));
$output->writeln('');
$output->writeln('--- Chunk Results ---');
$output->writeln(json_encode($chunkResults, JSON_PRETTY_PRINT));
$output->writeln('');
return Command::SUCCESS;
}
}