optimize catalog semantic match sby tags

This commit is contained in:
team2
2026-02-28 18:48:38 +01:00
parent 0d3f6e21d6
commit ff01919b30
2 changed files with 65 additions and 92 deletions

View File

@@ -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;