optimize as sales rag
This commit is contained in:
@@ -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 [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user