optimize weigths by rag and shop

This commit is contained in:
team 1
2026-04-19 17:17:50 +02:00
parent 39849d22cb
commit a0e0ec67d1
6 changed files with 315 additions and 302 deletions

View File

@@ -14,9 +14,7 @@ final class CommerceIntentLite
public function __construct(
private readonly CommerceIntentConfig $config
)
{
) {
}
/**
@@ -34,19 +32,32 @@ final class CommerceIntentLite
];
}
// Block support / diagnostic questions from entering the commerce flow
// unless the prompt also contains very explicit purchase / shop intent.
if ($this->isSupportOrDiagnosticQuery($p) && !$this->hasExplicitCommerceIntent($p)) {
return [
'intent' => self::NONE,
'score' => 0,
'signals' => ['support_or_diagnostic'],
];
}
$score = 0;
$signals = [];
$strongSignals = $this->config->getStrongSignalsList();
foreach ($strongSignals as $signal) {
if (str_contains($p, strtolower($signal))) {
if (str_contains($p, mb_strtolower($signal))) {
$score += 3;
$signals[] = $signal;
}
}
if (preg_match('#\d{3,10}#', $p)) {
// Treat long numeric identifiers as stronger product-number-like signals.
// This avoids over-triggering commerce purely because a model name contains
// a short number such as "808" in support questions.
if (preg_match('/\b\d{4,10}\b/u', $p) === 1) {
$score += 2;
$signals[] = 'sku';
}
@@ -78,7 +89,7 @@ final class CommerceIntentLite
$advisorySignals = $this->config->getAdvisorySignals();
foreach ($advisorySignals as $signal) {
if (str_contains($p, $signal)) {
if (str_contains($p, mb_strtolower($signal))) {
$score += 1;
$signals[] = 'advisory:' . $signal;
}
@@ -109,4 +120,65 @@ final class CommerceIntentLite
];
}
private function isSupportOrDiagnosticQuery(string $prompt): bool
{
$patterns = [
'/\bfehler\b/u',
'/\bfehlercode\b/u',
'/\berror\b/u',
'/\bstörung\b/u',
'/\bstoerung\b/u',
'/\balarm\b/u',
'/\bstörungsmeldung\b/u',
'/\bstoerungsmeldung\b/u',
'/\bmeldung\b/u',
'/\bwarnung\b/u',
'/\bwarncode\b/u',
'/\bcode\b/u',
'/\bwas bedeutet\b/u',
'/\bwarum\b/u',
'/\bblinkt\b/u',
'/\bzeigt\b/u',
'/\bzeigt an\b/u',
'/\bursache\b/u',
'/\bdiagnose\b/u',
'/\bservicefall\b/u',
'/\bproblem\b/u',
'/\bstörung beheben\b/u',
'/\bstoerung beheben\b/u',
'/\be\d{1,3}\b/u',
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $prompt) === 1) {
return true;
}
}
return false;
}
private function hasExplicitCommerceIntent(string $prompt): bool
{
$patterns = [
'/\bshop\b/u',
'/\bpreis\b/u',
'/\bkosten\b/u',
'/\bkostet\b/u',
'/\bkaufen\b/u',
'/\bbestellen\b/u',
'/\bprodukt\b/u',
'/\bartikel\b/u',
'/\bsku\b/u',
'/\bonline\b/u',
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $prompt) === 1) {
return true;
}
}
return false;
}
}