optimize catalog semantic match sby tags
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Intent;
|
||||
|
||||
use App\Tag\TagVectorSearchClient;
|
||||
use App\Tag\TagTypes;
|
||||
|
||||
final class CatalogIntentLite
|
||||
{
|
||||
@@ -22,8 +23,11 @@ final class CatalogIntentLite
|
||||
'alle',
|
||||
];
|
||||
|
||||
private const MIN_SCORE = 0.60;
|
||||
private const AMBIGUITY_DELTA = 0.05;
|
||||
// Realistischer Gate-Wert
|
||||
private const MIN_SCORE = 0.50;
|
||||
|
||||
// Ambiguity darf nicht zu aggressiv sein
|
||||
private const AMBIGUITY_DELTA = 0.01;
|
||||
|
||||
public function __construct(
|
||||
private readonly SalesIntentLite $salesIntentLite,
|
||||
@@ -34,12 +38,12 @@ final class CatalogIntentLite
|
||||
{
|
||||
$normalizedPrompt = mb_strtolower($prompt);
|
||||
|
||||
// 1) Muss Listen-Signal enthalten
|
||||
// 1) Listen-Signal prüfen
|
||||
if (!$this->containsAny($normalizedPrompt, self::LIST_SIGNALS)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2) Guardrail: Nur DISCOVERY
|
||||
// 2) Nur DISCOVERY zulassen
|
||||
$sales = $this->salesIntentLite->detect($prompt);
|
||||
$intent = (string)($sales['intent'] ?? SalesIntentLite::DISCOVERY);
|
||||
|
||||
@@ -47,7 +51,7 @@ final class CatalogIntentLite
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3) Vector-basierte Tag-Suche (Top 3 für Ambiguity-Check)
|
||||
// 3) Vector-Search
|
||||
$hits = $this->tagVectorClient->search($prompt, 3);
|
||||
|
||||
if ($hits === []) {
|
||||
@@ -61,7 +65,7 @@ final class CatalogIntentLite
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ambiguity-Check
|
||||
// Ambiguity-Prüfung
|
||||
if (isset($hits[1])) {
|
||||
$secondScore = (float)($hits[1]['score'] ?? 0.0);
|
||||
if (abs($bestScore - $secondScore) < self::AMBIGUITY_DELTA) {
|
||||
@@ -69,13 +73,12 @@ final class CatalogIntentLite
|
||||
}
|
||||
}
|
||||
|
||||
// 4) Nur catalog_entity zulassen
|
||||
if (($best['tag_type'] ?? null) !== 'catalog_entity') {
|
||||
// Nur catalog_entity zulassen
|
||||
if (($best['tag_type'] ?? null) !== TagTypes::CATALOG_ENTITY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 5) Canonical Label zurückgeben
|
||||
$label = (string)($best['label'] ?? '');
|
||||
$label = trim((string)($best['label'] ?? ''));
|
||||
|
||||
if ($label === '') {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user