patch 20j
This commit is contained in:
@@ -1469,6 +1469,15 @@ final readonly class AgentRunner
|
||||
return $optimizedShopQuery;
|
||||
}
|
||||
|
||||
if ($this->standaloneOptimizedShopQueryIntroducesUnsupportedContext($prompt, $optimizedShopQuery)) {
|
||||
$this->agentLogger->info('Ignored optimized shop query because it introduced unsupported standalone context', [
|
||||
'prompt' => $prompt,
|
||||
'optimizedShopQuery' => $optimizedShopQuery,
|
||||
]);
|
||||
|
||||
return $prompt;
|
||||
}
|
||||
|
||||
if ($this->extractFirstTestomatModelAnchor($prompt) === '') {
|
||||
return $optimizedShopQuery;
|
||||
}
|
||||
@@ -1489,6 +1498,39 @@ final readonly class AgentRunner
|
||||
return $prompt;
|
||||
}
|
||||
|
||||
private function standaloneOptimizedShopQueryIntroducesUnsupportedContext(
|
||||
string $prompt,
|
||||
string $optimizedShopQuery
|
||||
): bool {
|
||||
$promptTokens = array_fill_keys($this->tokenizeShopQueryCandidate($prompt), true);
|
||||
$optimizedTokens = $this->tokenizeShopQueryCandidate($optimizedShopQuery);
|
||||
|
||||
if ($optimizedTokens === [] || $promptTokens === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$overlap = 0;
|
||||
|
||||
foreach ($optimizedTokens as $token) {
|
||||
if (isset($promptTokens[$token])) {
|
||||
$overlap++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// A standalone query optimizer may remove words, but it must not add
|
||||
// model numbers or article-like numbers that are absent from the
|
||||
// current user input. Otherwise old context can leak into new shop
|
||||
// searches, for example "Anschlusskabel pH/Redox" -> "testomat 808".
|
||||
if (preg_match('/\d/u', $token) === 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the optimized query has no token overlap with the current standalone
|
||||
// input, it is not a safe optimization but a context substitution.
|
||||
return $overlap === 0 && !$this->isMetaOnlyShopQuery($prompt);
|
||||
}
|
||||
|
||||
private function resolveShopSearchQuery(
|
||||
string $prompt,
|
||||
string $optimizedShopQuery,
|
||||
|
||||
Reference in New Issue
Block a user