optimize as sales rag

This commit is contained in:
team2
2026-02-27 21:03:59 +01:00
parent efa9b17c2f
commit 3a5804e44c
6 changed files with 541 additions and 213 deletions

View File

@@ -9,7 +9,16 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
final readonly class TagVectorSearchClient
{
private const MIN_SCORE = 0.4; // 🔥 Tag Confidence Gate
/**
* Minimum similarity score required for a tag to be considered.
* Acts as a confidence gate to avoid noisy routing.
*/
private const MIN_SCORE = 0.4;
/**
* Hard limit to prevent excessive requests.
*/
private const MAX_LIMIT = 50;
public function __construct(
private HttpClientInterface $http,
@@ -18,11 +27,18 @@ final readonly class TagVectorSearchClient
) {}
/**
* Executes a vector search against the Python tag index.
*
* @return array<int, array{tag_id:string, score:float}>
*/
public function search(string $query, int $limit = 8): array
{
$limit = max(1, min($limit, 50));
$query = trim($query);
if ($query === '') {
return [];
}
$limit = max(1, min($limit, self::MAX_LIMIT));
try {
$response = $this->http->request(
@@ -38,7 +54,10 @@ final readonly class TagVectorSearchClient
);
if ($response->getStatusCode() !== 200) {
$this->agentLogger->warning('Tag vector service returned non-200');
$this->agentLogger->warning(
'Tag vector service returned non-200',
['status' => $response->getStatusCode()]
);
return [];
}
@@ -46,12 +65,14 @@ final readonly class TagVectorSearchClient
} catch (\Throwable $e) {
$this->agentLogger->warning(
'Tag vector service unreachable: ' . $e->getMessage()
'Tag vector service unreachable',
['error' => $e->getMessage()]
);
return [];
}
if (!is_array($data)) {
$this->agentLogger->warning('Tag vector service returned invalid payload');
return [];
}